def test_has_group_address(self): """Test has_group_address.""" xknx = XKNX() scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) assert scene.has_group_address(GroupAddress("1/2/1")) assert not scene.has_group_address(GroupAddress("2/2/2"))
def test_has_group_address(self): """Test has_group_address.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.assertTrue(scene.has_group_address(GroupAddress('1/2/1'))) self.assertFalse(scene.has_group_address(GroupAddress('2/2/2')))
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.loop.run_until_complete(asyncio.Task(scene.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 0)
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) self.loop.run_until_complete(scene.sync()) self.assertEqual(xknx.telegrams.qsize(), 0)
def test_has_group_address(self): """Test has_group_address.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) self.assertTrue(scene.has_group_address(GroupAddress("1/2/1"))) self.assertFalse(scene.has_group_address(GroupAddress("2/2/2")))
def test_has_group_address(self): """Test has_group_address.""" xknx = XKNX(loop=self.loop) scene = Scene( xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.assertTrue(scene.has_group_address(GroupAddress('1/2/1'))) self.assertFalse(scene.has_group_address(GroupAddress('2/2/2')))
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) scene = Scene( xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.loop.run_until_complete(asyncio.Task(scene.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 0)
def test_wrong_do(self): """Test wrong do command.""" xknx = XKNX(loop=self.loop) scene = Scene( xknx, 'TestScene', group_address='1/2/1', scene_number=23) with patch('logging.Logger.warning') as mockWarn: self.loop.run_until_complete(asyncio.Task(scene.do("execute"))) mockWarn.assert_called_with('Could not understand action %s for device %s', 'execute', 'TestScene') self.assertEqual(xknx.telegrams.qsize(), 0)
def test_run(self): """Test running scene.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.loop.run_until_complete(asyncio.Task(scene.run())) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram(GroupAddress('1/2/1'), payload=DPTArray(0x16)))
def test_do(self): """Test running scene with do command.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) self.loop.run_until_complete(scene.do("run")) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram(GroupAddress("1/2/1"), payload=DPTArray(0x16)))
def test_do(self): """Test running scene with do command.""" xknx = XKNX(loop=self.loop) scene = Scene( xknx, 'TestScene', group_address='1/2/1', scene_number=23) self.loop.run_until_complete(asyncio.Task(scene.do("run"))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/1'), payload=DPTArray(0x16)))
def test_wrong_do(self): """Test wrong do command.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) with patch("logging.Logger.warning") as mockWarn: self.loop.run_until_complete(scene.do("execute")) mockWarn.assert_called_with( "Could not understand action %s for device %s", "execute", "TestScene") self.assertEqual(xknx.telegrams.qsize(), 0)
async def main(): """Connect to KNX/IP bus and run scene.""" xknx = XKNX() await xknx.start() scene = Scene(xknx, name="Romantic", group_address="7/0/9", scene_number=23) await scene.run() await xknx.stop()
def parse_group_scene(self, entries): """Parse a scene section of xknx.yaml.""" for entry in entries: scene = Scene.from_config( self.xknx, entry, entries[entry]) self.xknx.devices.add(scene)
def test_unique_id(self): """Test unique id functionality.""" xknx = XKNX() scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) assert scene.unique_id == "1/2/1_23"
def test_run(self): """Test running scene.""" xknx = XKNX() scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) self.loop.run_until_complete(scene.run()) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram( destination_address=GroupAddress("1/2/1"), payload=GroupValueWrite(DPTArray(0x16)), ), )
def test_scene(self): """Test string representation of scene object.""" xknx = XKNX() scene = Scene(xknx, name="Romantic", group_address="1/2/3", scene_number=23) assert ( str(scene) == '<Scene name="Romantic" scene_value=<1/2/3, None, [], None /> scene_number="23" />' )
def test_config_scene(self): """Test reading Scene from config file.""" self.assertEqual( TestConfig.xknx.devices["Romantic"], Scene(TestConfig.xknx, "Romantic", group_address='7/0/1', scene_number=23, device_updated_cb=TestConfig.xknx.devices.device_updated))
async def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX() scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) await scene.sync() assert xknx.telegrams.qsize() == 0
def test_config_scene(self): """Test reading Scene from config file.""" self.assertEqual( TestConfig.xknx.devices["Romantic"], Scene(TestConfig.xknx, "Romantic", group_address="7/0/1", scene_number=23), )
def test_config_scene(self): """Test reading Scene from config file.""" xknx = XKNX(config='xknx.yaml', loop=self.loop) self.assertEqual( xknx.devices["Romantic"], Scene(xknx, "Romantic", group_address='7/0/1', scene_number=23, device_updated_cb=xknx.devices.device_updated))
def test_scene(self): """Test string representation of scene object.""" xknx = XKNX(loop=self.loop) scene = Scene(xknx, name='Romantic', group_address='1/2/3', scene_number=23) self.assertEqual( str(scene), '<Scene name="Romantic" scene_value="GroupAddress("1/2/3")/None/None/None" scene_number="23" />' )
async def test_run(self): """Test running scene.""" xknx = XKNX() scene = Scene(xknx, "TestScene", group_address="1/2/1", scene_number=23) await scene.run() assert xknx.telegrams.qsize() == 1 telegram = xknx.telegrams.get_nowait() assert telegram == Telegram( destination_address=GroupAddress("1/2/1"), payload=GroupValueWrite(DPTArray(0x16)), )
def parse_group_scene(self, entries): """Parse a scene section of xknx.yaml.""" for entry in entries: scene = Scene.from_config(self.xknx, entry, entries[entry]) self.xknx.devices.add(scene)