From 94ae9a3608602225206256d4011c18778c274d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Wed, 27 Dec 2017 19:20:35 +0100 Subject: [PATCH] added basic event handling support to units (not verified) --- gex/Unit.py | 9 +++++++++ gex/units/Pin.py | 3 +++ 2 files changed, 12 insertions(+) diff --git a/gex/Unit.py b/gex/Unit.py index 8b1379b..7264416 100644 --- a/gex/Unit.py +++ b/gex/Unit.py @@ -8,6 +8,11 @@ class Unit: self.unit_type = self._type() self.callsign = client.get_callsign(name, self.unit_type) + def evt_hdl(event: int, payload): + self.on_event(event, payload) + + self.client.bind_report_listener(self.callsign, evt_hdl) + def _type(self) -> str: raise NotImplementedError("Missing _type() in Unit class \"%s\"" % self.__class__.__name__) @@ -33,3 +38,7 @@ class Unit: bulk is the data to write. """ self.client.bulk_write(cs=self.callsign, cmd=cmd, id=id, pld=pld, bulk=bulk) + + def on_event(self, event:int, payload): + """ Stub for an event handler """ + raise NotImplementedError("Missing on_event() in Unit class \"%s\"" % self.__class__.__name__) diff --git a/gex/units/Pin.py b/gex/units/Pin.py index 6c372a6..690567b 100644 --- a/gex/units/Pin.py +++ b/gex/units/Pin.py @@ -4,6 +4,9 @@ class Pin(gex.Unit): def _type(self): return 'PIN' + def on_event(self, event:int, payload): + pass + def off(self): self.send(0x00)