Exemplo n.º 1
0
 def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(notification.process(telegram)))
Exemplo n.º 2
0
 def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX()
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     telegram = Telegram(GroupAddress("1/2/3"), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(notification.process(telegram))
Exemplo n.º 3
0
 def test_do(self):
     """Test 'do' functionality."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     self.loop.run_until_complete(
         asyncio.Task(notification.do("message:Ein Prosit!")))
     self.assertEqual(notification.message, "Ein Prosit!")
Exemplo n.º 4
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3', group_address_state='1/2/4')
     self.assertTrue(notification.has_group_address(GroupAddress('1/2/3')))
     self.assertTrue(notification.has_group_address(GroupAddress('1/2/4')))
     self.assertFalse(notification.has_group_address(GroupAddress('2/2/2')))
Exemplo n.º 5
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3', group_address_state='1/2/4')
     self.assertTrue(notification.has_group_address(GroupAddress('1/2/3')))
     self.assertTrue(notification.has_group_address(GroupAddress('1/2/4')))
     self.assertFalse(notification.has_group_address(GroupAddress('2/2/2')))
Exemplo n.º 6
0
 def test_state_addresses(self):
     """Test expose sensor returns empty list as state addresses."""
     xknx = XKNX(loop=self.loop)
     notification_1 = Notification(xknx, 'Warning', group_address='1/2/3', group_address_state='1/2/4')
     notification_2 = Notification(xknx, 'Warning', group_address='1/2/5')
     self.assertEqual(notification_1.state_addresses(), [GroupAddress('1/2/4')])
     self.assertEqual(notification_2.state_addresses(), [])
Exemplo n.º 7
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")),
            ),
        )
Exemplo n.º 8
0
 def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(notification.process(telegram)))
Exemplo n.º 9
0
 def test_process_payload_invalid_length(self):
     """Test process wrong telegram (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray((23, 24)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(notification.process(telegram)))
Exemplo n.º 10
0
 def test_process_payload_invalid_length(self):
     """Test process wrong telegram (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray((23, 24)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(notification.process(telegram)))
Exemplo n.º 11
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(notification.do("execute")))
         mock_warn.assert_called_with('Could not understand action %s for device %s', 'execute', 'Warning')
     self.assertEqual(xknx.telegrams.qsize(), 0)
Exemplo n.º 12
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(notification.do("execute")))
         mock_warn.assert_called_with('Could not understand action %s for device %s', 'execute', 'Warning')
     self.assertEqual(xknx.telegrams.qsize(), 0)
Exemplo n.º 13
0
 def test_do(self):
     """Test 'do' functionality."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     self.loop.run_until_complete(notification.do("message:Ein Prosit!"))
     self.loop.run_until_complete(
         xknx.devices.process(xknx.telegrams.get_nowait()))
     self.assertEqual(notification.message, "Ein Prosit!")
Exemplo n.º 14
0
 def test_sync_state(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, "Warning", group_address='1/2/3')
     self.loop.run_until_complete(asyncio.Task(notification.sync(False)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram, Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))
Exemplo n.º 15
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!"))))
Exemplo n.º 16
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(notification.do("execute"))
         mock_warn.assert_called_with(
             "Could not understand action %s for device %s", "execute",
             "Warning")
     self.assertEqual(xknx.telegrams.qsize(), 0)
Exemplo n.º 17
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx,
                                 "Warning",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     self.assertTrue(notification.has_group_address(GroupAddress("1/2/3")))
     self.assertTrue(notification.has_group_address(GroupAddress("1/2/4")))
     self.assertFalse(notification.has_group_address(GroupAddress("2/2/2")))
Exemplo n.º 18
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX()
     notification = Notification(xknx,
                                 "Warning",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     assert notification.has_group_address(GroupAddress("1/2/3"))
     assert notification.has_group_address(GroupAddress("1/2/4"))
     assert not notification.has_group_address(GroupAddress("2/2/2"))
Exemplo n.º 19
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!"))))
Exemplo n.º 20
0
 def test_process_payload_invalid_length(self):
     """Test process wrong telegram (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTArray((23, 24))),
     )
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(notification.process(telegram))
Exemplo n.º 21
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, "")
Exemplo n.º 22
0
 def test_sync_state(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(
         xknx,
         "Warning",
         group_address='1/2/3',
         group_address_state='1/2/4')
     self.loop.run_until_complete(asyncio.Task(notification.sync(False)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/4'), TelegramType.GROUP_READ))
Exemplo n.º 23
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, "")
Exemplo n.º 24
0
 def test_notification(self):
     """Test string representation of notification object."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, name='Alarm', group_address='1/2/3')
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" group_address="GroupAddress("1/2/3")" message="" />'
     )
     notification.message = 'Einbrecher im Haus'
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" group_address="GroupAddress("1/2/3")" message="Einbrecher im Haus" />'
     )
Exemplo n.º 25
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)
Exemplo n.º 26
0
 def test_sync_state(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX()
     notification = Notification(xknx,
                                 "Warning",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     self.loop.run_until_complete(notification.sync())
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(destination_address=GroupAddress("1/2/4"),
                  payload=GroupValueRead()),
     )
Exemplo n.º 27
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)
Exemplo n.º 28
0
 def test_notification(self):
     """Test string representation of notification object."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(
         xknx,
         name='Alarm',
         group_address='1/2/3',
         group_address_state='1/2/4')
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" group_address="GroupAddress("1/2/3")" group_address_state="GroupAddress("1/2/4")" message="" />')
     notification.message = 'Einbrecher im Haus'
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" group_address="GroupAddress("1/2/3")" group_address_state="GroupAddress("1/2/4")" '
         'message="Einbrecher im Haus" />')
Exemplo n.º 29
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)
Exemplo n.º 30
0
 def parse_group_notification(self, entries):
     """Parse a sensor section of xknx.yaml."""
     for entry in entries:
         notification = Notification.from_config(
             self.xknx,
             entry,
             entries[entry])
         self.xknx.devices.add(notification)
Exemplo n.º 31
0
 def parse_group_notification(self, entries):
     """Parse a sensor section of xknx.yaml."""
     for entry in entries:
         notification = Notification.from_config(
             self.xknx,
             entry,
             entries[entry])
         self.xknx.devices.add(notification)
Exemplo n.º 32
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, "")
Exemplo n.º 33
0
 def test_config_notification(self):
     """Test reading DateTime object from config file."""
     xknx = XKNX(config='xknx.yaml', loop=self.loop)
     self.assertEqual(
         xknx.devices['AlarmWindow'],
         Notification(xknx,
                      'AlarmWindow',
                      group_address='2/7/1',
                      device_updated_cb=xknx.devices.device_updated))
Exemplo n.º 34
0
 async def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX()
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(1)),
     )
     with pytest.raises(CouldNotParseTelegram):
         await notification.process(telegram)
Exemplo n.º 35
0
 def test_notification(self):
     """Test string representation of notification object."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx,
                                 name='Alarm',
                                 group_address='1/2/3',
                                 group_address_state='1/2/4')
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" message="GroupAddress("1/2/3")/GroupAddress("1/2/4")/None/None" />'
     )
     self.loop.run_until_complete(
         asyncio.Task(notification.set('Einbrecher im Haus')))
     self.assertEqual(
         str(notification), '<Notification name="Alarm" '
         'message="GroupAddress("1/2/3")/'
         'GroupAddress("1/2/4")/'
         '<DPTArray value="[0x45,0x69,0x6e,0x62,0x72,0x65,0x63,0x68,0x65,0x72,0x20,0x69,0x6d,0x20]" />/'
         'Einbrecher im " />')
Exemplo n.º 36
0
 def test_config_notification(self):
     """Test reading DateTime object from config file."""
     self.assertEqual(
         TestConfig.xknx.devices['AlarmWindow'],
         Notification(
             TestConfig.xknx,
             'AlarmWindow',
             group_address='2/7/1',
             group_address_state='2/7/2',
             device_updated_cb=TestConfig.xknx.devices.device_updated))
Exemplo n.º 37
0
 async def test_process_payload_invalid_length(self):
     """Test process wrong telegram (wrong payload length)."""
     xknx = XKNX()
     notification = Notification(xknx, "Warning", group_address="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTArray((23, 24))),
     )
     with pytest.raises(CouldNotParseTelegram):
         await notification.process(telegram)
Exemplo n.º 38
0
 def test_config_notification(self):
     """Test reading DateTime object from config file."""
     self.assertEqual(
         TestConfig.xknx.devices["AlarmWindow"],
         Notification(
             TestConfig.xknx,
             "AlarmWindow",
             group_address="2/7/1",
             group_address_state="2/7/2",
         ),
     )
Exemplo n.º 39
0
 async def test_sync_state(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX()
     notification = Notification(xknx,
                                 "Warning",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     await notification.sync()
     assert xknx.telegrams.qsize() == 1
     telegram = xknx.telegrams.get_nowait()
     assert telegram == Telegram(destination_address=GroupAddress("1/2/4"),
                                 payload=GroupValueRead())
Exemplo n.º 40
0
 def test_notification(self):
     """Test string representation of notification object."""
     xknx = XKNX()
     notification = Notification(xknx,
                                 name="Alarm",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" message="GroupAddress("1/2/3")/GroupAddress("1/2/4")/None/None" />',
     )
     self.loop.run_until_complete(notification.set("Einbrecher im Haus"))
     self.loop.run_until_complete(
         notification.process(xknx.telegrams.get_nowait()))
     self.assertEqual(
         str(notification),
         '<Notification name="Alarm" '
         'message="GroupAddress("1/2/3")/'
         'GroupAddress("1/2/4")/'
         '<DPTArray value="[0x45,0x69,0x6e,0x62,0x72,0x65,0x63,0x68,0x65,0x72,0x20,0x69,0x6d,0x20]" />/'
         'Einbrecher im " />',
     )
Exemplo n.º 41
0
 async def test_notification(self):
     """Test string representation of notification object."""
     xknx = XKNX()
     notification = Notification(xknx,
                                 name="Alarm",
                                 group_address="1/2/3",
                                 group_address_state="1/2/4")
     assert (
         str(notification) ==
         '<Notification name="Alarm" message=<1/2/3, 1/2/4, [], None /> />')
     await notification.set("Einbrecher im Haus")
     await notification.process(xknx.telegrams.get_nowait())
     assert (str(notification) == '<Notification name="Alarm" '
             "message=<1/2/3, 1/2/4, [], 'Einbrecher im ' /> />")
Exemplo n.º 42
0
 def test_do(self):
     """Test 'do' functionality."""
     xknx = XKNX(loop=self.loop)
     notification = Notification(xknx, 'Warning', group_address='1/2/3')
     self.loop.run_until_complete(asyncio.Task(notification.do("message:Ein Prosit!")))
     self.assertEqual(notification.message, "Ein Prosit!")