def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) sensor = Sensor(xknx, 'TestSensor', group_address='1/2/3') self.loop.run_until_complete(asyncio.Task(sensor.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(Address('1/2/3'), TelegramType.GROUP_READ))
def test_sync_passive(self): """Test sync function / not sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) sensor = Sensor(xknx, 'TestSensor', value_type="temperature", group_address_state='1/2/3', sync_state=False) self.loop.run_until_complete(asyncio.Task(sensor.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 0) with self.assertRaises(asyncio.queues.QueueEmpty): xknx.telegrams.get_nowait()
def test_sync_with_wait(self): """Test sync with wait_for_result=True.""" xknx = XKNX() sensor = Sensor( xknx, "Sensor", group_address_state="1/2/3", value_type="wind_speed_ms" ) with patch( "xknx.remote_value.RemoteValue.read_state", new_callable=MagicMock ) as read_state_mock: fut = asyncio.Future() fut.set_result(None) read_state_mock.return_value = fut self.loop.run_until_complete(sensor.sync(wait_for_result=True)) read_state_mock.assert_called_with(wait_for_result=True)
def test_sync(self): """Test sync function / sending group reads to KNX bus.""" xknx = XKNX(loop=self.loop) sensor = Sensor( xknx, 'TestSensor', value_type="temperature", group_address_state='1/2/3') self.loop.run_until_complete(asyncio.Task(sensor.sync(False))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual(telegram, Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))