Пример #1
0
 def test_warn_to_knx(self):
     """Test for warning if to_knx is not implemented."""
     xknx = XKNX()
     remote_value = RemoteValue(xknx)
     with patch("logging.Logger.warning") as mock_warn:
         remote_value.to_knx(23)
         mock_warn.assert_called_with("'to_knx()' not implemented for %s",
                                      "RemoteValue")
Пример #2
0
 def test_warn_to_knx(self):
     """Test for warning if to_knx is not implemented."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValue(xknx)
     with patch('logging.Logger.warning') as mock_warn:
         remote_value.to_knx(23)
         mock_warn.assert_called_with('to_knx not implemented for %s',
                                      'RemoteValue')
Пример #3
0
    async def test_get_set_value(self):
        """Test value getter and setter."""
        xknx = XKNX()
        remote_value = RemoteValue(xknx)
        remote_value.to_knx = lambda value: DPTArray(
            DPT2ByteFloat.to_knx(value))
        remote_value.after_update_cb = AsyncMock()

        assert remote_value.value is None
        remote_value.value = 2.2
        assert remote_value.value == 2.2
        # invalid value raises ConversionError
        with pytest.raises(ConversionError):
            remote_value.value = "a"
        # new value is used in response Telegram
        test_payload = remote_value.to_knx(2.2)
        remote_value._send = AsyncMock()
        await remote_value.respond()
        remote_value._send.assert_called_with(test_payload, response=True)
        # callback is not called when setting value programmatically
        remote_value.after_update_cb.assert_not_called()
        # no Telegram was sent to the queue
        assert xknx.telegrams.qsize() == 0
Пример #4
0
    async def test_set_value(self):
        """Test set_value awaitable."""
        xknx = XKNX()
        remote_value = RemoteValue(xknx)
        remote_value.to_knx = lambda value: DPTArray(
            DPT2ByteFloat.to_knx(value))
        remote_value.after_update_cb = AsyncMock()

        await remote_value.update_value(3.3)
        assert remote_value.value == 3.3
        remote_value.after_update_cb.assert_called_once()
        assert xknx.telegrams.qsize() == 0
        # invalid value raises ConversionError
        with pytest.raises(ConversionError):
            await remote_value.update_value("a")
        assert remote_value.value == 3.3