Ejemplo n.º 1
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     light = Light(
         xknx,
         'Office.Light_1',
         group_address_switch='1/7/1',
         group_address_switch_state='1/7/2',
         group_address_brightness='1/7/3',
         group_address_brightness_state='1/7/4',
         group_address_color='1/7/5',
         group_address_color_state='1/7/6',
         group_address_tunable_white='1/7/7',
         group_address_tunable_white_state='1/7/8',
         group_address_color_temperature='1/7/9',
         group_address_color_temperature_state='1/7/10',
         group_address_rgbw='1/7/11',
         group_address_rgbw_state='1/7/12',
     )
     self.assertTrue(light.has_group_address(GroupAddress('1/7/1')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/2')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/3')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/4')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/5')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/6')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/7')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/8')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/9')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/10')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/11')))
     self.assertTrue(light.has_group_address(GroupAddress('1/7/12')))
     self.assertFalse(light.has_group_address(GroupAddress('1/7/13')))
Ejemplo n.º 2
0
    def test_len(self):
        """Test len() function."""
        xknx = XKNX(loop=self.loop)
        devices = Devices()
        self.assertEqual(len(devices), 0)

        light1 = Light(xknx,
                       'Living-Room.Light_1',
                       group_address_switch='1/6/7')
        devices.add(light1)
        self.assertEqual(len(devices), 1)

        sensor1 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1',
                               significant_bit=2)
        devices.add(sensor1)
        self.assertEqual(len(devices), 2)

        sensor2 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1',
                               significant_bit=3)
        devices.add(sensor2)
        self.assertEqual(len(devices), 3)

        light2 = Light(xknx,
                       'Living-Room.Light_2',
                       group_address_switch='1/6/8')
        devices.add(light2)
        self.assertEqual(len(devices), 4)
Ejemplo n.º 3
0
    def test_get_item(self):
        """Test get item by name or by index."""
        xknx = XKNX()

        light1 = Light(xknx,
                       "Living-Room.Light_1",
                       group_address_switch="1/6/7")

        switch1 = Switch(xknx, "TestOutlet_1", group_address="1/2/3")

        light2 = Light(xknx,
                       "Living-Room.Light_2",
                       group_address_switch="1/6/8")

        switch2 = Switch(xknx, "TestOutlet_2", group_address="1/2/4")

        self.assertEqual(xknx.devices["Living-Room.Light_1"], light1)
        self.assertEqual(xknx.devices["TestOutlet_1"], switch1)
        self.assertEqual(xknx.devices["Living-Room.Light_2"], light2)
        self.assertEqual(xknx.devices["TestOutlet_2"], switch2)
        with self.assertRaises(KeyError):
            # pylint: disable=pointless-statement
            xknx.devices["TestOutlet_2sdds"]

        self.assertEqual(xknx.devices[0], light1)
        self.assertEqual(xknx.devices[1], switch1)
        self.assertEqual(xknx.devices[2], light2)
        self.assertEqual(xknx.devices[3], switch2)
        with self.assertRaises(IndexError):
            # pylint: disable=pointless-statement
            xknx.devices[4]
Ejemplo n.º 4
0
    def test_iter(self):
        """Test __iter__() function."""
        xknx = XKNX()
        devices = Devices()

        light1 = Light(xknx,
                       "Living-Room.Light_1",
                       group_address_switch="1/6/7")
        devices.add(light1)

        sensor1 = BinarySensor(xknx,
                               "DiningRoom.Motion.Sensor",
                               group_address_state="3/0/1")
        devices.add(sensor1)

        sensor2 = BinarySensor(xknx,
                               "DiningRoom.Motion.Sensor",
                               group_address_state="3/0/1")
        devices.add(sensor2)

        light2 = Light(xknx,
                       "Living-Room.Light_2",
                       group_address_switch="1/6/8")

        devices.add(light2)

        self.assertEqual(tuple(devices.__iter__()),
                         (light1, sensor1, sensor2, light2))
Ejemplo n.º 5
0
    def test_device_by_group_address(self):
        """Test get devices by group address."""
        xknx = XKNX()
        devices = Devices()

        light1 = Light(xknx,
                       "Living-Room.Light_1",
                       group_address_switch="1/6/7")
        devices.add(light1)

        sensor1 = BinarySensor(xknx,
                               "DiningRoom.Motion.Sensor",
                               group_address_state="3/0/1")
        devices.add(sensor1)

        sensor2 = BinarySensor(xknx,
                               "DiningRoom.Motion.Sensor",
                               group_address_state="3/0/1")
        devices.add(sensor2)

        light2 = Light(xknx,
                       "Living-Room.Light_2",
                       group_address_switch="1/6/8")
        devices.add(light2)

        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress("1/6/7"))),
            (light1, ))
        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress("1/6/8"))),
            (light2, ))
        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress("3/0/1"))),
            (sensor1, sensor2),
        )
Ejemplo n.º 6
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX()
     light = Light(
         xknx,
         "Office.Light_1",
         group_address_switch="1/7/1",
         group_address_switch_state="1/7/2",
         group_address_brightness="1/7/3",
         group_address_brightness_state="1/7/4",
         group_address_color="1/7/5",
         group_address_color_state="1/7/6",
         group_address_tunable_white="1/7/7",
         group_address_tunable_white_state="1/7/8",
         group_address_color_temperature="1/7/9",
         group_address_color_temperature_state="1/7/10",
         group_address_rgbw="1/7/11",
         group_address_rgbw_state="1/7/12",
     )
     self.assertTrue(light.has_group_address(GroupAddress("1/7/1")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/2")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/3")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/4")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/5")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/6")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/7")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/8")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/9")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/10")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/11")))
     self.assertTrue(light.has_group_address(GroupAddress("1/7/12")))
     self.assertFalse(light.has_group_address(GroupAddress("1/7/13")))
Ejemplo n.º 7
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus. Testing with a Light without dimm functionality."""
        xknx = XKNX()
        light = Light(
            xknx,
            name="TestLight",
            group_address_switch_state="1/2/3",
            group_address_brightness_state="1/2/5",
            group_address_color_state="1/2/6",
            group_address_tunable_white_state="1/2/7",
            group_address_color_temperature_state="1/2/8",
            group_address_rgbw_state="1/2/9",
        )
        self.loop.run_until_complete(light.sync())

        self.assertEqual(xknx.telegrams.qsize(), 6)

        telegrams = []
        for _ in range(6):
            telegrams.append(xknx.telegrams.get_nowait())

        test_telegrams = [
            Telegram(GroupAddress("1/2/3"), TelegramType.GROUP_READ),
            Telegram(GroupAddress("1/2/5"), TelegramType.GROUP_READ),
            Telegram(GroupAddress("1/2/6"), TelegramType.GROUP_READ),
            Telegram(GroupAddress("1/2/7"), TelegramType.GROUP_READ),
            Telegram(GroupAddress("1/2/8"), TelegramType.GROUP_READ),
            Telegram(GroupAddress("1/2/9"), TelegramType.GROUP_READ),
        ]

        self.assertEqual(len(set(telegrams)), 6)
        self.assertEqual(set(telegrams), set(test_telegrams))
Ejemplo n.º 8
0
    def test_iter(self):
        """Test __iter__() function."""
        xknx = XKNX(loop=self.loop)
        devices = Devices()

        light1 = Light(xknx,
                       'Living-Room.Light_1',
                       group_address_switch='1/6/7')
        devices.add(light1)

        sensor1 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1',
                               significant_bit=2)
        devices.add(sensor1)

        sensor2 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1',
                               significant_bit=3)
        devices.add(sensor2)

        light2 = Light(xknx,
                       'Living-Room.Light_2',
                       group_address_switch='1/6/8')

        devices.add(light2)

        self.assertEqual(
            tuple(devices.__iter__()),
            (light1, sensor1, sensor2, light2))
Ejemplo n.º 9
0
    def test_sync_state_address(self):
        """Test sync function / sending group reads to KNX bus. Testing with a Light with dimm functionality."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_switch_state='1/2/4',
                      group_address_brightness='1/2/5',
                      group_address_brightness_state='1/2/6',
                      group_address_color='1/2/7',
                      group_address_color_state='1/2/8')
        self.loop.run_until_complete(asyncio.Task(light.sync(False)))

        self.assertEqual(xknx.telegrams.qsize(), 3)

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram1, Telegram(GroupAddress('1/2/4'),
                                TelegramType.GROUP_READ))
        telegram2 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram2, Telegram(GroupAddress('1/2/8'),
                                TelegramType.GROUP_READ))
        telegram3 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram3, Telegram(GroupAddress('1/2/6'),
                                TelegramType.GROUP_READ))
Ejemplo n.º 10
0
    def test_get_item(self):
        """Test get item by name or by index."""
        xknx = XKNX()
        light1 = Light(xknx,
                       "Living-Room.Light_1",
                       group_address_switch="1/6/7")
        switch1 = Switch(xknx, "TestOutlet_1", group_address="1/2/3")
        light2 = Light(xknx,
                       "Living-Room.Light_2",
                       group_address_switch="1/6/8")
        switch2 = Switch(xknx, "TestOutlet_2", group_address="1/2/4")

        assert xknx.devices["Living-Room.Light_1"] == light1
        assert xknx.devices["TestOutlet_1"] == switch1
        assert xknx.devices["Living-Room.Light_2"] == light2
        assert xknx.devices["TestOutlet_2"] == switch2
        with pytest.raises(KeyError):
            # pylint: disable=pointless-statement
            xknx.devices["TestOutlet_2sdds"]

        assert xknx.devices[0] == light1
        assert xknx.devices[1] == switch1
        assert xknx.devices[2] == light2
        assert xknx.devices[3] == switch2
        with pytest.raises(IndexError):
            # pylint: disable=pointless-statement
            xknx.devices[4]
Ejemplo n.º 11
0
    def test_device_by_group_address(self):
        """Test get devices by group address."""
        xknx = XKNX(loop=self.loop)
        devices = Devices()

        light1 = Light(xknx,
                       'Living-Room.Light_1',
                       group_address_switch='1/6/7')
        devices.add(light1)

        sensor1 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1')
        devices.add(sensor1)

        sensor2 = BinarySensor(xknx,
                               'DiningRoom.Motion.Sensor',
                               group_address_state='3/0/1')
        devices.add(sensor2)

        light2 = Light(xknx,
                       'Living-Room.Light_2',
                       group_address_switch='1/6/8')
        devices.add(light2)

        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress('1/6/7'))),
            (light1, ))
        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress('1/6/8'))),
            (light2, ))
        self.assertEqual(
            tuple(devices.devices_by_group_address(GroupAddress('3/0/1'))),
            (sensor1, sensor2))
Ejemplo n.º 12
0
 def test_set_brightness_not_dimmable(self):
     """Test setting the brightness of a non dimmable Light."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3')
     self.loop.run_until_complete(asyncio.Task(light.set_brightness(23)))
     self.assertEqual(xknx.telegrams.qsize(), 0)  # Nothing should happen
Ejemplo n.º 13
0
    def test_contains(self):
        """Test __contains__() function."""
        xknx = XKNX()
        Light(xknx, "Living-Room.Light_1", group_address_switch="1/6/7")
        Light(xknx, "Living-Room.Light_2", group_address_switch="1/6/8")

        assert "Living-Room.Light_1" in xknx.devices
        assert "Living-Room.Light_2" in xknx.devices
        assert "Living-Room.Light_3" not in xknx.devices
Ejemplo n.º 14
0
 def test_set_brightness_not_dimmable(self):
     """Test setting the brightness of a non dimmable Light."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     light = Light(xknx, name="TestLight", group_address_switch="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(light.set_brightness(23))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with("Dimming not supported for device %s",
                                      "TestLight")
Ejemplo n.º 15
0
 def test_set_color_not_possible(self):
     """Test setting the color of a non light without color."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     light = Light(xknx, name="TestLight", group_address_switch="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(light.set_color((23, 24, 25)))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with("Colors not supported for device %s",
                                      "TestLight")
Ejemplo n.º 16
0
 def test_set_tw_unsupported(self):
     """Test setting the tunable white value of a non tw Light."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     light = Light(xknx, name="TestLight", group_address_switch="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(light.set_tunable_white(23))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with(
             "Tunable white not supported for device %s", "TestLight")
Ejemplo n.º 17
0
 def test_process_color_temperature_wrong_payload(self):
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color_temperature='1/2/5')
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
Ejemplo n.º 18
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_brightness='1/2/5')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(light.do("execute")))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with('Could not understand action %s for device %s', 'execute', 'TestLight')
Ejemplo n.º 19
0
    def test_contains(self):
        """Test __contains__() function."""
        xknx = XKNX(loop=self.loop)

        Light(xknx, "Living-Room.Light_1", group_address_switch="1/6/7")

        Light(xknx, "Living-Room.Light_2", group_address_switch="1/6/8")

        self.assertTrue("Living-Room.Light_1" in xknx.devices)
        self.assertTrue("Living-Room.Light_2" in xknx.devices)
        self.assertFalse("Living-Room.Light_3" in xknx.devices)
Ejemplo n.º 20
0
 def test_process_color(self):
     """Test process / reading telegrams from telegram queue. Test if color is processed."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color='1/2/5')
     self.assertEqual(light.current_color, (None, None))
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23, 24, 25)))
     self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
     self.assertEqual(light.current_color, ((23, 24, 25), None))
Ejemplo n.º 21
0
 def test_set_color_temp_unsupported(self):
     """Test setting the color temperature value of an unsupported Light."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     light = Light(xknx, name="TestLight", group_address_switch="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(light.set_color_temperature(4000))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with(
             "Absolute Color Temperature not supported for device %s",
             "TestLight")
Ejemplo n.º 22
0
 def test_process_color_temperature_payload_invalid_length(self):
     """Test process wrong telegrams. (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color_temperature='1/2/5')
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
Ejemplo n.º 23
0
 def test_set_color_rgbw_not_possible(self):
     """Test setting RGBW value of a non light without color."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color='1/2/4')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(light.set_color((23, 24, 25), 26)))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with('RGBW not supported for device %s', 'TestLight')
Ejemplo n.º 24
0
 def test_set_color_temp(self):
     """Test setting the color temperature value of a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_color_temperature='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_color_temperature(4000)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/5'), payload=DPTArray((0x0F, 0xA0, ))))
Ejemplo n.º 25
0
 def test_process_tunable_white_wrong_payload(self):
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX()
     light = Light(
         xknx,
         name="TestLight",
         group_address_switch="1/2/3",
         group_address_tunable_white="1/2/5",
     )
     telegram = Telegram(GroupAddress("1/2/5"), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(light.process(telegram))
Ejemplo n.º 26
0
    def test_process_tunable_white(self):
        """Test process / reading telegrams from telegram queue. Test if tunable white is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_tunable_white='1/2/5')
        self.assertEqual(light.current_tunable_white, None)

        telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray(23))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.current_tunable_white, 23)
Ejemplo n.º 27
0
 def test_set_tw(self):
     """Test setting the tunable white value of a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_tunable_white='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_tunable_white(23)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/5'), payload=DPTArray(23)))
Ejemplo n.º 28
0
 def test_set_on(self):
     """Test switching on a Light."""
     xknx = XKNX(loop=self.loop)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_brightness='1/2/5')
     self.loop.run_until_complete(asyncio.Task(light.set_on()))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(Address('1/2/3'), payload=DPTBinary(1)))
Ejemplo n.º 29
0
    def test_process_dimm(self):
        """Test process / reading telegrams from telegram queue. Test if brightness is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.brightness, 0)

        telegram = Telegram(Address('1/2/5'), payload=DPTArray(23))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.brightness, 23)
Ejemplo n.º 30
0
    def test_process_color_temperature(self):
        """Test process / reading telegrams from telegram queue. Test if color temperature is processed."""
        xknx = XKNX(loop=self.loop)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_color_temperature='1/2/5')
        self.assertEqual(light.current_color_temperature, None)

        telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((0x0F, 0xA0, )))
        self.loop.run_until_complete(asyncio.Task(light.process(telegram)))
        self.assertEqual(light.current_color_temperature, 4000)
Ejemplo n.º 31
0
 def parse_group_light(self, entries):
     """Parse a light section of xknx.yaml."""
     for entry in entries:
         light = Light.from_config(
             self.xknx,
             entry,
             entries[entry])
         self.xknx.devices.add(light)