def test_payload_valid_preassigned_mode(self):
        """Test if setpoint_shift_mode is assigned properly by payload length."""
        xknx = XKNX()
        remote_value_6 = RemoteValueSetpointShift(
            xknx=xknx, setpoint_shift_mode=SetpointShiftMode.DPT6010
        )
        remote_value_9 = RemoteValueSetpointShift(
            xknx=xknx, setpoint_shift_mode=SetpointShiftMode.DPT9002
        )
        dpt_6_payload = DPTArray(DPTValue1Count.to_knx(1))
        dpt_9_payload = DPTArray(DPTTemperature.to_knx(1))

        assert remote_value_6.dpt_class == DPTValue1Count
        assert remote_value_6.payload_valid(None) is None
        assert remote_value_6.payload_valid(dpt_9_payload) is None
        assert remote_value_6.payload_valid(DPTArray((1, 2, 3, 4))) is None
        assert remote_value_6.payload_valid(DPTBinary(1)) is None
        assert remote_value_6.payload_valid(dpt_6_payload) == dpt_6_payload

        assert remote_value_9.dpt_class == DPTTemperature
        assert remote_value_9.payload_valid(None) is None
        assert remote_value_9.payload_valid(dpt_6_payload) is None
        assert remote_value_9.payload_valid(DPTArray((1, 2, 3))) is None
        assert remote_value_9.payload_valid(DPTBinary(1)) is None
        assert remote_value_9.payload_valid(dpt_9_payload) == dpt_9_payload
Beispiel #2
0
    def test_process_callback_updated_via_telegram(self):
        """Test if after_update_callback is called after update of Climate object."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_temperature='1/2/1',
                          group_address_target_temperature='1/2/2',
                          group_address_setpoint_shift='1/2/3')

        after_update_callback = Mock()

        async def async_after_update_callback(device):
            """Async callback."""
            after_update_callback(device)

        climate.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram(GroupAddress('1/2/1'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/2'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/3'),
                            payload=DPTArray(DPTValue1Count.to_knx(-4)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()
Beispiel #3
0
    def test_payload_valid_mode_assignment(self):
        """Test if setpoint_shift_mode is assigned properly by payload length."""
        xknx = XKNX()
        remote_value = RemoteValueSetpointShift(xknx=xknx)
        dpt_6_payload = DPTArray(DPTValue1Count.to_knx(1))
        dpt_9_payload = DPTArray(DPTTemperature.to_knx(1))

        with pytest.raises(CouldNotParseTelegram):
            remote_value.payload_valid(DPTBinary(0))
        with pytest.raises(CouldNotParseTelegram):
            remote_value.payload_valid(DPTArray((0, 1, 2)))

        # DPT 6 - payload_length 1
        assert remote_value.dpt_class is None
        assert remote_value.payload_valid(dpt_6_payload) == dpt_6_payload
        assert remote_value.dpt_class == SetpointShiftMode.DPT6010.value
        with pytest.raises(CouldNotParseTelegram):
            # DPT 9 is invalid now
            remote_value.payload_valid(dpt_9_payload)

        remote_value.dpt_class = None
        # DPT 9 - payload_length 2
        assert remote_value.payload_valid(dpt_9_payload) == dpt_9_payload
        assert remote_value.dpt_class == SetpointShiftMode.DPT9002.value
        with pytest.raises(CouldNotParseTelegram):
            # DPT 6 is invalid now
            remote_value.payload_valid(dpt_6_payload)
 def to_knx(self, value: float) -> DPTArray:
     """Convert value to payload."""
     if self.dpt_class is None:
         raise ConversionError("Setpoint shift DPT not initialized for %s" %
                               self.device_name)
     if self.dpt_class == DPTValue1Count:
         converted_value = int(value / self.setpoint_shift_step)
         return DPTArray(DPTValue1Count.to_knx(converted_value))
     return DPTArray(DPTTemperature.to_knx(value))
Beispiel #5
0
 def to_knx(self, value: int) -> DPTArray:
     """Convert value to payload."""
     return DPTArray(DPTValue1Count.to_knx(value))
 def to_knx(self, value: float) -> DPTArray:
     """Convert value to payload."""
     converted_value = int(value / self.setpoint_shift_step)
     return DPTArray(DPTValue1Count.to_knx(converted_value))