async def test_process_callback_always(self): """Test process / reading telegrams from telegram queue. Test if callback is called.""" xknx = XKNX() sensor = RawValue( xknx, "TestSensor", 2, group_address="1/2/3", always_callback=True, ) after_update_callback = AsyncMock() sensor.register_device_updated_cb(after_update_callback) telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray((0x01, 0x02))), ) await sensor.process(telegram) after_update_callback.assert_called_with(sensor) assert sensor.last_telegram == telegram # every telegram shall trigger callback after_update_callback.reset_mock() await sensor.process(telegram) after_update_callback.assert_called_with(sensor)
async def test_respond_to_read(self): """Test respond_to_read function.""" xknx = XKNX() responding = RawValue( xknx, "TestSensor1", 2, group_address="1/1/1", respond_to_read=True, ) non_responding = RawValue( xknx, "TestSensor2", 2, group_address="1/1/1", respond_to_read=False, ) responding_multiple = RawValue( xknx, "TestSensor3", 2, group_address=["1/1/1", "3/3/3"], group_address_state="2/2/2", respond_to_read=True, ) # set initial payload of RawValue responding.remote_value.value = 256 non_responding.remote_value.value = 256 responding_multiple.remote_value.value = 256 read_telegram = Telegram(destination_address=GroupAddress("1/1/1"), payload=GroupValueRead()) # verify no response when respond is False await non_responding.process(read_telegram) assert xknx.telegrams.qsize() == 0 # verify response when respond is True await responding.process(read_telegram) assert xknx.telegrams.qsize() == 1 response = xknx.telegrams.get_nowait() assert response == Telegram( destination_address=GroupAddress("1/1/1"), payload=GroupValueResponse(DPTArray((0x01, 0x00))), ) # verify no response when GroupValueRead request is not for group_address await responding_multiple.process(read_telegram) assert xknx.telegrams.qsize() == 1 response = xknx.telegrams.get_nowait() assert response == Telegram( destination_address=GroupAddress("1/1/1"), payload=GroupValueResponse(DPTArray((0x01, 0x00))), ) await responding_multiple.process( Telegram(destination_address=GroupAddress("2/2/2"), payload=GroupValueRead())) await responding_multiple.process( Telegram(destination_address=GroupAddress("3/3/3"), payload=GroupValueRead())) assert xknx.telegrams.qsize() == 0
def test_string(self): """Test RawValue string representation.""" xknx = XKNX() value = RawValue(xknx, "Raw", 1, group_address="1/2/3") value.remote_value.value = 4 assert ( str(value) == '<RawValue name="Raw" addresses=<1/2/3, None, [], 4 /> value=4/>')
def _create_raw_value(xknx: XKNX, config: ConfigType) -> RawValue: """Return a KNX RawValue to be used within XKNX.""" return RawValue( xknx, name=config[CONF_NAME], payload_length=config[SelectSchema.CONF_PAYLOAD_LENGTH], group_address=config[KNX_ADDRESS], group_address_state=config.get(CONF_STATE_ADDRESS), respond_to_read=config[CONF_RESPOND_TO_READ], sync_state=config[CONF_SYNC_STATE], )
async def test_payloads( self, payload_length, raw_payload, expected_state, ): """Test raw value types.""" xknx = XKNX() raw_value = RawValue( xknx, "Test", payload_length=payload_length, group_address="1/2/3", ) telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(value=raw_payload), ) await raw_value.process(telegram) assert raw_value.resolve_state() == expected_state assert raw_value.last_telegram == telegram
async def test_set_1(self): """Test set with raw value.""" xknx = XKNX() raw_value = RawValue(xknx, "TestSensor", 1, group_address="1/2/3") await raw_value.set(75) assert xknx.telegrams.qsize() == 1 telegram = xknx.telegrams.get_nowait() assert telegram == Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray((0x4B, ))), )