Example #1
0
    def test_process(self):
        """Test if telegram is handled by the correct process_* method."""
        xknx = XKNX(loop=self.loop)
        device = Device(xknx, "TestDevice")

        with patch(
                "xknx.devices.Device.process_group_read") as mock_group_read:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_read.return_value = fut
            telegram = Telegram(
                GroupAddress("1/2/1"),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_READ,
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_read.assert_called_with(telegram)

        with patch(
                "xknx.devices.Device.process_group_write") as mock_group_write:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_write.return_value = fut
            telegram = Telegram(
                GroupAddress("1/2/1"),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_WRITE,
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_write.assert_called_with(telegram)

        with patch("xknx.devices.Device.process_group_response"
                   ) as mock_group_response:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_response.return_value = fut
            telegram = Telegram(
                GroupAddress("1/2/1"),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_RESPONSE,
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_response.assert_called_with(telegram)
Example #2
0
    def test_process(self):
        """Test if telegram is handled by the correct process_* method."""
        xknx = XKNX(loop=self.loop)
        device = Device(xknx, 'TestDevice')

        with patch('xknx.devices.Device.process_group_read') as mock_group_read:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_read.return_value = fut
            telegram = Telegram(
                GroupAddress('1/2/1'),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_READ)
            self.loop.run_until_complete(asyncio.Task(device.process(telegram)))
            mock_group_read.assert_called_with(telegram)

        with patch('xknx.devices.Device.process_group_write') as mock_group_write:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_write.return_value = fut
            telegram = Telegram(
                GroupAddress('1/2/1'),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_WRITE)
            self.loop.run_until_complete(asyncio.Task(device.process(telegram)))
            mock_group_write.assert_called_with(telegram)

        with patch('xknx.devices.Device.process_group_response') as mock_group_response:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_response.return_value = fut
            telegram = Telegram(
                GroupAddress('1/2/1'),
                payload=DPTArray((0x01, 0x02)),
                telegramtype=TelegramType.GROUP_RESPONSE)
            self.loop.run_until_complete(asyncio.Task(device.process(telegram)))
            mock_group_response.assert_called_with(telegram)
Example #3
0
    def test_process(self):
        """Test if telegram is handled by the correct process_* method."""
        xknx = XKNX()
        device = Device(xknx, "TestDevice")

        with patch("xknx.devices.Device.process_group_read") as mock_group_read:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_read.return_value = fut
            telegram = Telegram(
                destination_address=GroupAddress("1/2/1"), payload=GroupValueRead()
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_read.assert_called_with(telegram)

        with patch("xknx.devices.Device.process_group_write") as mock_group_write:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_write.return_value = fut
            telegram = Telegram(
                destination_address=GroupAddress("1/2/1"),
                payload=GroupValueWrite(DPTArray((0x01, 0x02))),
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_write.assert_called_with(telegram)

        with patch("xknx.devices.Device.process_group_response") as mock_group_response:
            fut = asyncio.Future()
            fut.set_result(None)
            mock_group_response.return_value = fut
            telegram = Telegram(
                destination_address=GroupAddress("1/2/1"),
                payload=GroupValueResponse(DPTArray((0x01, 0x02))),
            )
            self.loop.run_until_complete(device.process(telegram))
            mock_group_response.assert_called_with(telegram)