def test_process_position(self): """Test process / reading telegrams from telegram queue. Test if position is processed correctly.""" xknx = XKNX() cover = Cover( xknx, "TestCover", group_address_long="1/2/1", group_address_short="1/2/2", group_address_position="1/2/3", group_address_position_state="1/2/4", ) # initial position process - position is unknown so this is the new state - not moving telegram = Telegram(GroupAddress("1/2/3"), payload=DPTArray(213)) self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.current_position(), 84) self.assertFalse(cover.is_traveling()) # state telegram updates current position - we are not moving so this is new state - not moving telegram = Telegram(GroupAddress("1/2/4"), payload=DPTArray(42)) self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.current_position(), 16) self.assertFalse(cover.is_traveling()) self.assertEqual(cover.travelcalculator.travel_to_position, 16) # new position - movement starts telegram = Telegram(GroupAddress("1/2/3"), payload=DPTArray(255)) self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.current_position(), 16) self.assertTrue(cover.is_closing()) self.assertEqual(cover.travelcalculator.travel_to_position, 100) # new state while moving - movement goes on; travelcalculator updated telegram = Telegram(GroupAddress("1/2/4"), payload=DPTArray(213)) self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.current_position(), 84) self.assertTrue(cover.is_closing()) self.assertEqual(cover.travelcalculator.travel_to_position, 100)
def test_process_callback(self): """Test process / reading telegrams from telegram queue. Test if callback is executed.""" # pylint: disable=no-self-use xknx = XKNX() cover = Cover( xknx, "TestCover", group_address_long="1/2/1", group_address_short="1/2/2", group_address_stop="1/2/3", group_address_position="1/2/4", group_address_position_state="1/2/5", group_address_angle="1/2/6", group_address_angle_state="1/2/7", ) after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) cover.register_device_updated_cb(async_after_update_callback) for address, payload, feature in [ ("1/2/1", DPTBinary(1), "long"), ("1/2/2", DPTBinary(1), "short"), ("1/2/4", DPTArray(42), "position"), ("1/2/5", DPTArray(42), "position state"), ("1/2/6", DPTArray(42), "angle"), ("1/2/7", DPTArray(51), "angle state"), ]: with self.subTest(address=address, feature=feature): telegram = Telegram( destination_address=GroupAddress(address), payload=GroupValueWrite(payload), ) self.loop.run_until_complete(cover.process(telegram)) after_update_callback.assert_called_with(cover) after_update_callback.reset_mock() # Stop only when cover is travelling telegram = Telegram( GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(1)) ) self.loop.run_until_complete(cover.process(telegram)) after_update_callback.assert_not_called() self.loop.run_until_complete(cover.set_down()) self.loop.run_until_complete(cover.process(telegram)) after_update_callback.assert_called_with(cover)
def test_position_without_position_address_down(self): """Test moving cover down - with no absolute positioning supported.""" xknx = XKNX() cover = Cover( xknx, "TestCover", group_address_long="1/2/1", group_address_short="1/2/2", group_address_position_state="1/2/4", ) cover.travelcalculator.set_position(70) self.loop.run_until_complete(cover.set_position(80)) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram( destination_address=GroupAddress("1/2/1"), payload=GroupValueWrite(DPTBinary(1)), ), ) self.assertEqual(cover.travelcalculator.travel_to_position, 80) self.assertTrue(cover.is_closing()) # process the outgoing telegram to make sure it doesn't overwrite the target position self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.travelcalculator.travel_to_position, 80)
def test_process_callback(self): """Test process / reading telegrams from telegram queue. Test if callback is executed.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2', group_address_stop='1/2/3', group_address_position='1/2/4', group_address_position_state='1/2/5', group_address_angle='1/2/6', group_address_angle_state='1/2/7') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) cover.register_device_updated_cb(async_after_update_callback) for address, payload, feature in [ ('1/2/1', DPTBinary(1), "long"), ('1/2/2', DPTBinary(1), "short"), ('1/2/4', DPTArray(42), "position"), ('1/2/5', DPTArray(42), "position state"), ('1/2/6', DPTArray(42), "angle"), ('1/2/7', DPTArray(51), "angle state") ]: with self.subTest(address=address, feature=feature): telegram = Telegram(GroupAddress(address), payload=payload) self.loop.run_until_complete( asyncio.Task(cover.process(telegram))) after_update_callback.assert_called_with(cover) after_update_callback.reset_mock() # Stop only when cover is travelling telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) after_update_callback.assert_not_called() self.loop.run_until_complete(asyncio.Task(cover.set_down())) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) after_update_callback.assert_called_with(cover)
def test_process_angle(self): """Test process / reading telegrams from telegram queue. Test if position is processed correctly.""" xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2', group_address_angle='1/2/3', group_address_angle_state='1/2/4') telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) self.assertEqual(cover.current_angle(), 84)
def test_process_down(self): """Test process / reading telegrams from telegram queue. Test if up/down is processed correctly.""" xknx = XKNX() cover = Cover(xknx, "TestCover", group_address_long="1/2/1", group_address_short="1/2/2") cover.travelcalculator.set_position(50) self.assertFalse(cover.is_traveling()) telegram = Telegram(GroupAddress("1/2/1"), payload=DPTBinary(1)) self.loop.run_until_complete(cover.process(telegram)) self.assertTrue(cover.is_closing())
def test_process_up(self): """Test process / reading telegrams from telegram queue. Test if up/down is processed correctly.""" xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2') cover.travelcalculator.set_position(50) self.assertFalse(cover.is_traveling()) telegram = Telegram(GroupAddress('1/2/1'), payload=DPTBinary(0)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) self.assertTrue(cover.is_opening())
def test_process_angle(self): """Test process / reading telegrams from telegram queue. Test if position is processed correctly.""" xknx = XKNX(loop=self.loop) cover = Cover( xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2', group_address_angle='1/2/3', group_address_angle_state='1/2/4') telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) self.assertEqual(cover.current_angle(), 84)
def test_process_angle(self): """Test process / reading telegrams from telegram queue. Test if position is processed correctly.""" xknx = XKNX() cover = Cover( xknx, "TestCover", group_address_long="1/2/1", group_address_short="1/2/2", group_address_angle="1/2/3", group_address_angle_state="1/2/4", ) telegram = Telegram(GroupAddress("1/2/4"), payload=DPTArray(42)) self.loop.run_until_complete(cover.process(telegram)) self.assertEqual(cover.current_angle(), 16)
def test_process_callback(self): """Test process / reading telegrams from telegram queue. Test if callback is executed.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2', group_address_position='1/2/3', group_address_position_state='1/2/4') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) cover.register_device_updated_cb(async_after_update_callback) telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) after_update_callback.assert_called_with(cover)
def test_process_callback(self): """Test process / reading telegrams from telegram queue. Test if callback is executed.""" # pylint: disable=no-self-use xknx = XKNX(loop=self.loop) cover = Cover( xknx, 'TestCover', group_address_long='1/2/1', group_address_short='1/2/2', group_address_position='1/2/3', group_address_position_state='1/2/4') after_update_callback = Mock() async def async_after_update_callback(device): """Async callback.""" after_update_callback(device) cover.register_device_updated_cb(async_after_update_callback) telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42)) self.loop.run_until_complete(asyncio.Task(cover.process(telegram))) after_update_callback.assert_called_with(cover)