def on_message(self, message): from plugins import gateway_led, yeelight message = json.loads(message) device = message.get('device') command = message.get('command') if device == gateway_led.DEVICE: if command == 'color': value = message['value'].replace('#', '') gateway_led.set_color(value) elif command == 'brightness': value = message['value'] gateway_led.set_brightness(value) elif command == 'rgb': value = message['value'].replace('#', '') gateway_led.set_rgb(value) elif command == 'toggle': gateway_led.toggle() self.write_message({'device': gateway_led.DEVICE, 'return': 'ok'}) elif device == yeelight.DEVICE: return_result = 'ok' if command == 'set_power': yeelight.set_power(message['power'], device_id=message['id']) elif command == 'set_name': yeelight.set_name(message['name'], device_id=message['id']) elif command == 'set_bright': yeelight.set_bright(message['bright'], device_id=message['id']) else: return_result = 'error' data = { 'device': yeelight.DEVICE, 'return': return_result } self.write_message(data) if message.get('kind') == 'notification': if message.get('command') == 'read': Notifications.remove(message.get('uuid'))
def test_remove_method_when_no_such_notification_in_list_should_do_nothing( self): Notifications.remove('0de8916f-7595-41b0-8e46-c9eea962b0b8') self.assertEqual(Notifications.list(), self.notifications)
def test_remove_method_should_remove_notification_from_list(self): Notifications.remove('second') expected_list = self.notifications[:1] self.assertEqual(Notifications.list(), expected_list)