Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DeviceController(object):
- # Setup stuff
- # ....
- def subscribe(self, obj, handler):
- """Subscribes to status updates of the requested object."""
- self._subscribers[obj] = handler
- def _recv(self, obj, args):
- # First let the object update itself
- handled = obj.handle_update(args) #<-- Internally, args are passed.
- # Now notify anyone who cares that device may have changed
- if handled and obj in self._subscribers:
- # Current code. To subscriber, library doesn't pass args:
- self._subscribers[obj](obj)
- # Ideal state -- pass args to subscribers. Will error for existing subscribers.
- self._subscribers[obj](obj, args)
- class TestDeviceController(object):
- # Setup stuff
- # ....
- def handler(self, obj):
- """Existing device handler signature
- Don't get the most useful part (e.g., what actually changed)
- However, if we update self._subscribers[obj](obj) above to send args,
- any existing subscribers will break (i think...?)
- """
- _LOGGER.info("Handler Executed for: {}".format(obj))
- def register(self):
- controller = DeviceController('IP Address', 'Username', 'Password')
- for integration_id, keypad in controller._ids['DEVICE'].items():
- controller.subscribe(keypad, self.handler)
- controller.connect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement