def test_set_off(self): xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, 'TestOutlet', group_address='1/2/3') outlet.set_off() self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(Address('1/2/3'), payload=DPTBinary(0)))
def test_sync_state(self): xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, "TestOutlet", group_address='1/2/3') outlet.sync_state() self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(Address('1/2/3'), TelegramType.GROUP_READ))
def test_process_callback(self): # pylint: disable=no-self-use xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, 'TestOutlet', group_address='1/2/3') after_update_callback = Mock() outlet.after_update_callback = after_update_callback telegram = Telegram() telegram.payload = DPTBinary(1) outlet.process(telegram) after_update_callback.assert_called_with(outlet)
def test_do(self): xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, 'TestOutlet', group_address='1/2/3') outlet.do("on") self.assertTrue(outlet.state) outlet.do("off") self.assertFalse(outlet.state)
def test_get_item(self): xknx = XKNX(self.loop, start=False) devices = Devices() light1 = Light(xknx, 'Living-Room.Light_1', group_address_switch='1/6/7') devices.add(light1) outlet1 = Outlet(xknx, "TestOutlet_1", group_address='1/2/3') devices.add(outlet1) light2 = Light(xknx, 'Living-Room.Light_2', group_address_switch='1/6/8') devices.add(light2) outlet2 = Outlet(xknx, "TestOutlet_2", group_address='1/2/4') devices.add(outlet2) self.assertEqual(devices["Living-Room.Light_1"], light1) self.assertEqual(devices["Living-Room.Light_2"], light2) self.assertEqual(devices["TestOutlet_1"], outlet1) self.assertEqual(devices["TestOutlet_2"], outlet2)
def test_process(self): xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, 'TestOutlet', group_address='1/2/3') xknx.devices.add(outlet) switch = Switch(xknx, 'TestInput', group_address='1/2/3') action_on = Action( xknx, hook='on', target='TestOutlet', method='on') switch.actions.append(action_on) action_off = Action( xknx, hook='off', target='TestOutlet', method='off') switch.actions.append(action_off) xknx.devices.add(switch) self.assertEqual( xknx.devices['TestInput'].state, BinaryInputState.OFF) self.assertEqual( xknx.devices['TestOutlet'].state, False) telegram_on = Telegram() telegram_on.payload = DPTBinary(1) switch.process(telegram_on) self.assertEqual( xknx.devices['TestInput'].state, BinaryInputState.ON) self.assertEqual( xknx.devices['TestOutlet'].state, True) telegram_off = Telegram() telegram_off.payload = DPTBinary(0) switch.process(telegram_off) self.assertEqual( xknx.devices['TestInput'].state, BinaryInputState.OFF) self.assertEqual( xknx.devices['TestOutlet'].state, False)
def test_process(self): xknx = XKNX(self.loop, start=False) outlet = Outlet(xknx, 'TestOutlet', group_address='1/2/3') self.assertEqual(outlet.state, False) telegram_on = Telegram() telegram_on.payload = DPTBinary(1) outlet.process(telegram_on) self.assertEqual(outlet.state, True) telegram_off = Telegram() telegram_off.payload = DPTBinary(0) outlet.process(telegram_off) self.assertEqual(outlet.state, False)
def test_config_outlet(self): xknx = XKNX(self.loop, start=False) Config(xknx).read('../xknx.yaml') self.assertEqual( xknx.devices['Livingroom.Outlet_2'], Outlet(xknx, 'Livingroom.Outlet_2', group_address='1/3/2'))