def test_process(self): """Test process telegram.""" xknx = XKNX() remote_value = RemoteValueControl(xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise") telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0xB)), ) self.assertEqual(remote_value.value, None) self.loop.run_until_complete(remote_value.process(telegram)) self.assertEqual(remote_value.value, 25)
def test_set(self): """Test setting value.""" xknx = XKNX() remote_value = RemoteValueControl(xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise") self.loop.run_until_complete(asyncio.Task(remote_value.set(25))) self.assertEqual(xknx.telegrams.qsize(), 1) telegram = xknx.telegrams.get_nowait() self.assertEqual( telegram, Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0xB)), ), )
def test_to_process_error(self): """Test process errornous telegram.""" xknx = XKNX() remote_value = RemoteValueControl(xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise") with self.assertRaises(CouldNotParseTelegram): telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray(0x01)), ) self.loop.run_until_complete(remote_value.process(telegram)) with self.assertRaises(ConversionError): telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0x10)), ) self.loop.run_until_complete(remote_value.process(telegram)) # pylint: disable=pointless-statement remote_value.value
async def test_process(self): """Test process telegram.""" xknx = XKNX() remote_value = RemoteValueControl( xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise" ) telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0xB)), ) assert remote_value.value is None await remote_value.process(telegram) assert remote_value.value == 25
async def test_set(self): """Test setting value.""" xknx = XKNX() remote_value = RemoteValueControl( xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise" ) await remote_value.set(25) assert xknx.telegrams.qsize() == 1 telegram = xknx.telegrams.get_nowait() assert telegram == Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0xB)), )
async def test_to_process_error(self): """Test process errornous telegram.""" xknx = XKNX() remote_value = RemoteValueControl(xknx, group_address=GroupAddress("1/2/3"), value_type="stepwise") telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTArray(0x01)), ) assert await remote_value.process(telegram) is False telegram = Telegram( destination_address=GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(0x10)), ) assert await remote_value.process(telegram) is False assert remote_value.value is None
def __init__( self, xknx: XKNX, name: str, group_address_state: GroupAddressesType | None = None, sync_state: bool = True, always_callback: bool = False, value_type: int | str | None = None, ha_value_template: Any = None, device_updated_cb: DeviceCallbackType | None = None, ): """Initialize Sensor class.""" super().__init__(xknx, name, device_updated_cb) self.sensor_value: RemoteValueControl | RemoteValueSensor if isinstance(value_type, str) and value_type in [ "stepwise_dimming", "stepwise_blinds", "startstop_dimming", "startstop_blinds", ]: self.sensor_value = RemoteValueControl( xknx, group_address_state=group_address_state, sync_state=sync_state, value_type=value_type, device_name=self.name, after_update_cb=self.after_update, ) else: self.sensor_value = RemoteValueSensor( xknx, group_address_state=group_address_state, sync_state=sync_state, value_type=value_type, device_name=self.name, after_update_cb=self.after_update, ) self.always_callback = always_callback self.ha_value_template = ha_value_template
def __init__( self, xknx: "XKNX", name: str, group_address_state: Optional["GroupAddressableType"] = None, sync_state: bool = True, always_callback: bool = False, value_type: Optional[str] = None, device_updated_cb: Optional[DeviceCallbackType] = None, ): """Initialize Sensor class.""" # pylint: disable=too-many-arguments super().__init__(xknx, name, device_updated_cb) self.sensor_value: Union[RemoteValueControl, RemoteValueSensor] if value_type in [ "stepwise_dimming", "stepwise_blinds", "startstop_dimming", "startstop_blinds", ]: self.sensor_value = RemoteValueControl( xknx, group_address_state=group_address_state, sync_state=sync_state, value_type=value_type, device_name=self.name, after_update_cb=self.after_update, ) else: self.sensor_value = RemoteValueSensor( xknx, group_address_state=group_address_state, sync_state=sync_state, value_type=value_type, device_name=self.name, after_update_cb=self.after_update, ) self.always_callback = always_callback
def test_wrong_value_type(self): """Test initializing with wrong value_type.""" xknx = XKNX() with pytest.raises(ConversionError): RemoteValueControl(xknx, value_type="wrong_value_type")