Пример #1
0
    def test_read_state(self):
        """Test read state while waiting for the result."""
        xknx = XKNX()
        remote_value = RemoteValueSwitch(xknx, group_address_state="1/2/3")

        with patch("xknx.remote_value.RemoteValue.payload_valid") as patch_valid, patch(
            "xknx.core.ValueReader.read", new_callable=MagicMock
        ) as patch_read:
            patch_valid.return_value = True

            fut = asyncio.Future()
            telegram = Telegram(GroupAddress("1/2/3"), payload=DPTBinary(1))
            fut.set_result(telegram)
            patch_read.return_value = fut

            self.loop.run_until_complete(remote_value.read_state(wait_for_result=True))

            self.assertTrue(remote_value.value)
Пример #2
0
    def test_read_state_none(self):
        """Test read state while waiting for the result but got None."""
        xknx = XKNX()
        remote_value = RemoteValueSwitch(xknx, group_address_state="1/2/3")

        with patch("xknx.remote_value.RemoteValue.payload_valid") as patch_valid, patch(
            "xknx.core.ValueReader.read", new_callable=MagicMock
        ) as patch_read, patch("logging.Logger.warning") as mock_info:
            fut = asyncio.Future()
            fut.set_result(None)
            patch_valid.return_value = False
            patch_read.return_value = fut

            self.loop.run_until_complete(remote_value.read_state(wait_for_result=True))

            mock_info.assert_called_with(
                "Could not sync group address '%s' (%s - %s)",
                GroupAddress("1/2/3"),
                "Unknown",
                "State",
            )