Exemple #1
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""
        # pylint: disable=no-self-use
        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCover",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/3",
            group_address_position="1/2/4",
            group_address_position_state="1/2/5",
            group_address_angle="1/2/6",
            group_address_angle_state="1/2/7",
        )

        after_update_callback = Mock()

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

        cover.register_device_updated_cb(async_after_update_callback)
        for address, payload, feature in [
            ("1/2/1", DPTBinary(1), "long"),
            ("1/2/2", DPTBinary(1), "short"),
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/5", DPTArray(42), "position state"),
            ("1/2/6", DPTArray(42), "angle"),
            ("1/2/7", DPTArray(51), "angle state"),
        ]:
            with self.subTest(address=address, feature=feature):
                telegram = Telegram(
                    destination_address=GroupAddress(address),
                    payload=GroupValueWrite(payload),
                )
                self.loop.run_until_complete(cover.process(telegram))
                after_update_callback.assert_called_with(cover)
                after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(
            GroupAddress("1/2/3"), payload=GroupValueWrite(DPTBinary(1))
        )
        self.loop.run_until_complete(cover.process(telegram))
        after_update_callback.assert_not_called()
        self.loop.run_until_complete(cover.set_down())
        self.loop.run_until_complete(cover.process(telegram))
        after_update_callback.assert_called_with(cover)
Exemple #2
0
    async def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""

        xknx = XKNX()
        cover = Cover(
            xknx,
            "TestCoverProcessCallback",
            group_address_long="1/2/1",
            group_address_short="1/2/2",
            group_address_stop="1/2/3",
            group_address_position="1/2/4",
            group_address_position_state="1/2/5",
            group_address_angle="1/2/6",
            group_address_angle_state="1/2/7",
        )

        after_update_callback = AsyncMock()

        cover.register_device_updated_cb(after_update_callback)
        for address, payload, _feature in [
            ("1/2/1", DPTBinary(1), "long"),
            ("1/2/2", DPTBinary(1), "short"),
            ("1/2/4", DPTArray(42), "position"),
            ("1/2/5", DPTArray(42), "position state"),
            ("1/2/6", DPTArray(42), "angle"),
            ("1/2/7", DPTArray(51), "angle state"),
        ]:
            telegram = Telegram(
                destination_address=GroupAddress(address),
                payload=GroupValueWrite(payload),
            )
            await cover.process(telegram)
            after_update_callback.assert_called_with(cover)
            after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(GroupAddress("1/2/3"),
                            payload=GroupValueWrite(DPTBinary(1)))
        await cover.process(telegram)
        after_update_callback.assert_not_called()
        await cover.set_down()
        await cover.process(telegram)
        after_update_callback.assert_called_with(cover)

        await cover.stop()  # clean up tasks
Exemple #3
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        cover = Cover(xknx,
                      'TestCover',
                      group_address_long='1/2/1',
                      group_address_short='1/2/2',
                      group_address_stop='1/2/3',
                      group_address_position='1/2/4',
                      group_address_position_state='1/2/5',
                      group_address_angle='1/2/6',
                      group_address_angle_state='1/2/7')

        after_update_callback = Mock()

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

        cover.register_device_updated_cb(async_after_update_callback)
        for address, payload, feature in [
            ('1/2/1', DPTBinary(1), "long"), ('1/2/2', DPTBinary(1), "short"),
            ('1/2/4', DPTArray(42), "position"),
            ('1/2/5', DPTArray(42), "position state"),
            ('1/2/6', DPTArray(42), "angle"),
            ('1/2/7', DPTArray(51), "angle state")
        ]:
            with self.subTest(address=address, feature=feature):
                telegram = Telegram(GroupAddress(address), payload=payload)
                self.loop.run_until_complete(
                    asyncio.Task(cover.process(telegram)))
                after_update_callback.assert_called_with(cover)
                after_update_callback.reset_mock()
        # Stop only when cover is travelling
        telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
        self.loop.run_until_complete(asyncio.Task(cover.process(telegram)))
        after_update_callback.assert_not_called()
        self.loop.run_until_complete(asyncio.Task(cover.set_down()))
        self.loop.run_until_complete(asyncio.Task(cover.process(telegram)))
        after_update_callback.assert_called_with(cover)
Exemple #4
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        cover = Cover(xknx,
                      'TestCover',
                      group_address_long='1/2/1',
                      group_address_short='1/2/2',
                      group_address_position='1/2/3',
                      group_address_position_state='1/2/4')

        after_update_callback = Mock()

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

        cover.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42))
        self.loop.run_until_complete(asyncio.Task(cover.process(telegram)))

        after_update_callback.assert_called_with(cover)
Exemple #5
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        cover = Cover(
            xknx,
            'TestCover',
            group_address_long='1/2/1',
            group_address_short='1/2/2',
            group_address_position='1/2/3',
            group_address_position_state='1/2/4')

        after_update_callback = Mock()

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

        telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(42))
        self.loop.run_until_complete(asyncio.Task(cover.process(telegram)))

        after_update_callback.assert_called_with(cover)