def test_process_switch(self): """Test process / reading telegrams from telegram queue. Test if switch position is processed correctly.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_brightness='1/2/5') self.assertEqual(light.state, False) telegram = Telegram(Address('1/2/3'), payload=DPTBinary(1)) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.state, True) telegram = Telegram(Address('1/2/3'), payload=DPTBinary(0)) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.state, False)
def test_process_color_temperature_wrong_payload(self): """Test process wrong telegrams. (wrong payload type).""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_color_temperature='1/2/5') telegram = Telegram(GroupAddress('1/2/5'), payload=DPTBinary(1)) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
def test_process_color_temperature_payload_invalid_length(self): """Test process wrong telegrams. (wrong payload length).""" # pylint: disable=invalid-name xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_color_temperature='1/2/5') telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23))) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
def test_process_color(self): """Test process / reading telegrams from telegram queue. Test if color is processed.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_color='1/2/5') self.assertEqual(light.current_color, (None, None)) telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23, 24, 25))) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.current_color, ((23, 24, 25), None))
def test_process_tunable_white_wrong_payload(self): """Test process wrong telegrams. (wrong payload type).""" xknx = XKNX() light = Light( xknx, name="TestLight", group_address_switch="1/2/3", group_address_tunable_white="1/2/5", ) telegram = Telegram(GroupAddress("1/2/5"), payload=DPTBinary(1)) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete(light.process(telegram))
def test_process_dimm(self): """Test process / reading telegrams from telegram queue. Test if brightness is processed.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_brightness='1/2/5') self.assertEqual(light.brightness, 0) telegram = Telegram(Address('1/2/5'), payload=DPTArray(23)) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.brightness, 23)
def test_process_tunable_white(self): """Test process / reading telegrams from telegram queue. Test if tunable white is processed.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_tunable_white='1/2/5') self.assertEqual(light.current_tunable_white, None) telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray(23)) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.current_tunable_white, 23)
def test_process_color_temperature(self): """Test process / reading telegrams from telegram queue. Test if color temperature is processed.""" xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_color_temperature='1/2/5') self.assertEqual(light.current_color_temperature, None) telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((0x0F, 0xA0, ))) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) self.assertEqual(light.current_color_temperature, 4000)
def test_process_tunable_white_payload_invalid_length(self): """Test process wrong telegrams. (wrong payload length).""" # pylint: disable=invalid-name xknx = XKNX() light = Light( xknx, name="TestLight", group_address_switch="1/2/3", group_address_tunable_white="1/2/5", ) telegram = Telegram(GroupAddress("1/2/5"), payload=DPTArray((23, 24))) with self.assertRaises(CouldNotParseTelegram): self.loop.run_until_complete(light.process(telegram))
def test_process_dimm(self): """Test process / reading telegrams from telegram queue. Test if brightness is processed.""" xknx = XKNX() light = Light( xknx, name="TestLight", group_address_switch="1/2/3", group_address_brightness="1/2/5", ) self.assertEqual(light.current_brightness, None) telegram = Telegram(GroupAddress("1/2/5"), payload=DPTArray(23)) self.loop.run_until_complete(light.process(telegram)) self.assertEqual(light.current_brightness, 23)
def test_process_color_rgbw(self): """Test process / reading telegrams from telegram queue. Test if RGBW is processed.""" xknx = XKNX() light = Light( xknx, name="TestLight", group_address_switch="1/2/3", group_address_color="1/2/4", group_address_rgbw="1/2/5", ) self.assertEqual(light.current_color, (None, None)) telegram = Telegram(GroupAddress("1/2/5"), payload=DPTArray((23, 24, 25, 26, 0, 15))) self.loop.run_until_complete(light.process(telegram)) self.assertEqual(light.current_color, ([23, 24, 25], 26))
def test_process_switch_callback(self): """Test process / reading telegrams from telegram queue. Test if callback is called.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) light = Light(xknx, name="TestLight", group_address_switch='1/2/3', group_address_brightness='1/2/5') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) light.register_device_updated_cb(async_after_update_callback) telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1)) self.loop.run_until_complete(asyncio.Task(light.process(telegram))) after_update_callback.assert_called_with(light)