From e0b39b114464b86f43c2e7f7dcf70e6a4148b8b7 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Thu, 26 Jan 2017 07:14:43 +0100 Subject: [PATCH] mqtt: change 'On' method function signature to match expected interface Signed-off-by: deadprogram --- examples/mqtt_driver_ping.go | 4 ++-- platforms/mqtt/mqtt_driver.go | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/examples/mqtt_driver_ping.go b/examples/mqtt_driver_ping.go index c005b430..632a03d2 100644 --- a/examples/mqtt_driver_ping.go +++ b/examples/mqtt_driver_ping.go @@ -14,11 +14,11 @@ func main() { helloDriver := mqtt.NewDriver(mqttAdaptor, "hello") work := func() { - helloDriver.OnData(func(data []byte) { + helloDriver.On(mqtt.Data, func(data []byte) { fmt.Println("hello") }) - holaDriver.OnData(func(data []byte) { + holaDriver.On(mqtt.Data, func(data []byte) { fmt.Println("hola") }) diff --git a/platforms/mqtt/mqtt_driver.go b/platforms/mqtt/mqtt_driver.go index d0a19b67..edc51833 100644 --- a/platforms/mqtt/mqtt_driver.go +++ b/platforms/mqtt/mqtt_driver.go @@ -2,6 +2,14 @@ package mqtt import "gobot.io/x/gobot" +const ( + // Data event when data is available for Driver + Data = "data" + + // Error event when error occurs in Driver + Error = "error" +) + // Driver for mqtt type Driver struct { name string @@ -60,7 +68,9 @@ func (m *Driver) Publish(message []byte) bool { return m.adaptor().Publish(m.topic, message) } -// OnData subscribes to the current device topic, and then calls the message handler function when data is received -func (m *Driver) OnData(f func(s []byte)) bool { +// On subscribes to data updates for the current device topic, +// and then calls the message handler function when data is received +func (m *Driver) On(n string, f func(s []byte)) bool { + // TODO: subscribe to Error updates return m.adaptor().On(m.topic, f) }