Ejemplo n.º 1
0
    def test_set(self):
        """Test notificationing off notification."""
        xknx = XKNX(loop=self.loop)
        notification = Notification(xknx, "Warning", group_address="1/2/3")
        self.loop.run_until_complete(notification.set("Ein Prosit!"))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(
                GroupAddress("1/2/3"),
                payload=DPTArray(DPTString().to_knx("Ein Prosit!")),
            ),
        )
        # test if message longer than 14 chars gets cropped
        self.loop.run_until_complete(notification.set("This is too long."))

        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(
                GroupAddress("1/2/3"),
                payload=DPTArray(DPTString().to_knx("This is too lo")),
            ),
        )
Ejemplo n.º 2
0
 def test_value_special_chars(self):
     """Test parsing and streaming string with special chars."""
     raw = [0x48, 0x65, 0x79, 0x21, 0x3f,
            0x24, 0x20, 0xc4, 0xd6, 0xdc,
            0xe4, 0xf6, 0xfc, 0xdf]
     string = 'Hey!?$ ÄÖÜäöüß'
     self.assertEqual(DPTString.to_knx(string), raw)
     self.assertEqual(DPTString.from_knx(raw), string)
Ejemplo n.º 3
0
 def test_value_max_string(self):
     """Test parsing and streaming large string."""
     raw = [0x41, 0x41, 0x41, 0x41, 0x41,
            0x42, 0x42, 0x42, 0x42, 0x42,
            0x43, 0x43, 0x43, 0x43]
     string = 'AAAAABBBBBCCCC'
     self.assertEqual(DPTString.to_knx(string), raw)
     self.assertEqual(DPTString.from_knx(raw), string)
Ejemplo n.º 4
0
 def test_value_empty_string(self):
     """Test parsing and streaming empty string."""
     raw = [0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00]
     string = ''
     self.assertEqual(DPTString.to_knx(string), raw)
     self.assertEqual(DPTString.from_knx(raw), string)
Ejemplo n.º 5
0
 def test_value_from_documentation(self):
     """Test parsing and streaming Example from documentation."""
     raw = [0x4B, 0x4E, 0x58, 0x20, 0x69,
            0x73, 0x20, 0x4F, 0x4B, 0x00,
            0x00, 0x00, 0x00, 0x00]
     string = 'KNX is OK'
     self.assertEqual(DPTString.to_knx(string), raw)
     self.assertEqual(DPTString.from_knx(raw), string)
Ejemplo n.º 6
0
    def test_process(self):
        """Test process telegram with notification. Test if device was updated."""
        xknx = XKNX(loop=self.loop)
        notification = Notification(xknx, 'Warning', group_address='1/2/3')
        telegram_set = Telegram(GroupAddress('1/2/3'),
                                payload=DPTArray(DPTString().to_knx("Ein Prosit!")))
        self.loop.run_until_complete(asyncio.Task(notification.process(telegram_set)))
        self.assertEqual(notification.message, "Ein Prosit!")

        telegram_unset = Telegram(GroupAddress('1/2/3'),
                                  payload=DPTArray(DPTString().to_knx("")))
        self.loop.run_until_complete(asyncio.Task(notification.process(telegram_unset)))
        self.assertEqual(notification.message, "")
Ejemplo n.º 7
0
 def test_from_knx_wrong_parameter_too_small(self):
     """Test parsing of KNX string with too less elements."""
     raw = [0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00]
     with self.assertRaises(ConversionError):
         DPTString().from_knx(raw)
Ejemplo n.º 8
0
    def test_process(self):
        """Test process telegram with notification. Test if device was updated."""
        xknx = XKNX()
        notification = Notification(xknx, "Warning", group_address="1/2/3")
        telegram_set = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(
                DPTString().to_knx("Ein Prosit!"))),
        )
        self.loop.run_until_complete(notification.process(telegram_set))
        self.assertEqual(notification.message, "Ein Prosit!")

        telegram_unset = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(DPTString().to_knx(""))),
        )
        self.loop.run_until_complete(notification.process(telegram_unset))
        self.assertEqual(notification.message, "")
Ejemplo n.º 9
0
    async def test_process(self):
        """Test process telegram with notification. Test if device was updated."""
        xknx = XKNX()
        notification = Notification(xknx, "Warning", group_address="1/2/3")
        telegram_set = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(
                DPTString().to_knx("Ein Prosit!"))),
        )
        await notification.process(telegram_set)
        assert notification.message == "Ein Prosit!"

        telegram_unset = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(DPTString().to_knx(""))),
        )
        await notification.process(telegram_unset)
        assert notification.message == ""
Ejemplo n.º 10
0
 def test_from_knx_wrong_parameter_too_small(self):
     """Test parsing of KNX string with too less elements."""
     raw = (
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     )
     with pytest.raises(ConversionError):
         DPTString.from_knx(raw)
Ejemplo n.º 11
0
 def test_value_from_documentation(self):
     """Test parsing and streaming Example from documentation."""
     raw = (
         0x4B,
         0x4E,
         0x58,
         0x20,
         0x69,
         0x73,
         0x20,
         0x4F,
         0x4B,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     )
     string = "KNX is OK"
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == string
Ejemplo n.º 12
0
 def test_value_special_chars(self):
     """Test parsing and streaming string with special chars."""
     raw = (
         0x48,
         0x65,
         0x79,
         0x21,
         0x3F,
         0x24,
         0x20,
         0xC4,
         0xD6,
         0xDC,
         0xE4,
         0xF6,
         0xFC,
         0xDF,
     )
     string = "Hey!?$ ÄÖÜäöüß"
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == string
Ejemplo n.º 13
0
 def test_value_max_string(self):
     """Test parsing and streaming large string."""
     raw = (
         0x41,
         0x41,
         0x41,
         0x41,
         0x41,
         0x42,
         0x42,
         0x42,
         0x42,
         0x42,
         0x43,
         0x43,
         0x43,
         0x43,
     )
     string = "AAAAABBBBBCCCC"
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == string
Ejemplo n.º 14
0
 def test_value_empty_string(self):
     """Test parsing and streaming empty string."""
     raw = (
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     )
     string = ""
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == string
Ejemplo n.º 15
0
 def test_value_special_chars(self):
     """Test parsing and streaming string with special chars."""
     raw = [
         0x48,
         0x65,
         0x79,
         0x21,
         0x3F,
         0x24,
         0x20,
         0xC4,
         0xD6,
         0xDC,
         0xE4,
         0xF6,
         0xFC,
         0xDF,
     ]
     string = "Hey!?$ ÄÖÜäöüß"
     self.assertEqual(DPTString.to_knx(string), raw)
     self.assertEqual(DPTString.from_knx(raw), string)
Ejemplo n.º 16
0
 def test_set(self):
     """Test notificationing off notification."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     self.loop.run_until_complete(
         asyncio.Task(notification.set("Ein Prosit!")))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'),
                  payload=DPTArray(DPTString().to_knx("Ein Prosit!"))))
Ejemplo n.º 17
0
 async def _process_message(self, telegram):
     """Process incoming telegram for on/off state."""
     if not isinstance(telegram.payload, DPTArray):
         raise CouldNotParseTelegram("payload not of type DPTArray",
                                     payload=telegram.payload,
                                     device_name=self.name)
     if len(telegram.payload.value) != 14:
         raise CouldNotParseTelegram("payload has invalid length!=14",
                                     length=len(telegram.payload.value),
                                     device_name=self.name)
     await self._set_internal_message(DPTString().from_knx(
         telegram.payload.value))
Ejemplo n.º 18
0
    async def test_set(self):
        """Test notificationing off notification."""
        xknx = XKNX()
        notification = Notification(xknx, "Warning", group_address="1/2/3")
        await notification.set("Ein Prosit!")
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(
                DPTString().to_knx("Ein Prosit!"))),
        )
        # test if message longer than 14 chars gets cropped
        await notification.set("This is too long.")

        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(
                DPTArray(DPTString().to_knx("This is too lo"))),
        )
Ejemplo n.º 19
0
 def test_to_knx_invalid_chars(self):
     """Test streaming string with invalid chars."""
     raw = (
         0x4D,
         0x61,
         0x74,
         0x6F,
         0x75,
         0x3F,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     )
     string = "Matouš"
     knx_string = "Matou?"
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == knx_string
Ejemplo n.º 20
0
    async def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback was called."""

        xknx = XKNX()
        notification = Notification(xknx, "Warning", group_address="1/2/3")
        after_update_callback = AsyncMock()
        notification.register_device_updated_cb(after_update_callback)

        telegram_set = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(
                DPTString().to_knx("Ein Prosit!"))),
        )
        await notification.process(telegram_set)
        after_update_callback.assert_called_with(notification)
Ejemplo n.º 21
0
    def test_process_callback(self):
        """Test process / reading telegrams from telegram queue. Test if callback was called."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        notification = Notification(xknx, 'Warning', group_address='1/2/3')
        after_update_callback = Mock()

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

        notification.register_device_updated_cb(async_after_update_callback)
        telegram_set = Telegram(GroupAddress('1/2/3'),
                                payload=DPTArray(DPTString().to_knx("Ein Prosit!")))
        self.loop.run_until_complete(asyncio.Task(notification.process(telegram_set)))
        after_update_callback.assert_called_with(notification)
Ejemplo n.º 22
0
 def test_from_knx_wrong_parameter_too_large(self):
     """Test parsing of KNX string with too many elements."""
     raw = (
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
         0x00,
     )
     with self.assertRaises(ConversionError):
         DPTString().from_knx(raw)
Ejemplo n.º 23
0
 def test_to_knx_ascii_invalid_chars(self, string, knx_string, raw):
     """Test streaming ASCII string with invalid chars."""
     assert DPTString.to_knx(string) == raw
     assert DPTString.from_knx(raw) == knx_string
Ejemplo n.º 24
0
 def from_knx(self, payload):
     """Convert current payload to value."""
     return DPTString.from_knx(payload.value)
Ejemplo n.º 25
0
 async def set(self, message):
     """Set message."""
     cropped_message = message[:14]
     await self.send(self.group_address,
                     DPTArray(DPTString().to_knx(cropped_message)))
     await self._set_internal_message(cropped_message)
Ejemplo n.º 26
0
 def test_to_knx_too_long(self):
     """Test serializing DPTString to KNX with wrong value (to long)."""
     with pytest.raises(ConversionError):
         DPTString.to_knx("AAAAABBBBBCCCCx")
Ejemplo n.º 27
0
 def from_knx(self, payload: DPTArray) -> str:
     """Convert current payload to value."""
     return DPTString.from_knx(payload.value)
Ejemplo n.º 28
0
 def test_from_knx_wrong_parameter_length(self, raw):
     """Test parsing of KNX string with wrong elements length."""
     with pytest.raises(ConversionError):
         DPTString.from_knx(raw)
Ejemplo n.º 29
0
 def to_knx(self, value: str) -> DPTArray:
     """Convert value to payload."""
     return DPTArray(DPTString.to_knx(value))