Exemple #1
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, "")
Exemple #2
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)
Exemple #3
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!"))))
Exemple #4
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))
Exemple #5
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)
Exemple #6
0
 def set(self, message):
     """Set message."""
     cropped_message = message[:14]
     yield from self.send(self.group_address,
                          DPTArray(DPTString().to_knx(cropped_message)))
     yield from self._set_internal_message(cropped_message)
Exemple #7
0
 def test_to_knx_too_long(self):
     """Test serializing DPTString to KNX with wrong value (to long)."""
     with self.assertRaises(ConversionError):
         DPTString().to_knx("AAAAABBBBBCCCCx")
Exemple #8
0
 def test_to_knx_wrong_parameter(self):
     """Test serializing DPTString to KNX with wrong value (int)."""
     with self.assertRaises(ConversionError):
         DPTString().to_knx(123)
Exemple #9
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing of DPT2ByteFloat with wrong value (string)."""
     with self.assertRaises(ConversionError):
         DPTString().to_knx(123)