Exemplo n.º 1
0
 def test_process_speed_wrong_payload(self):  # pylint: disable=invalid-name
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
Exemplo n.º 2
0
 def test_do(self):
     """Test 'do' functionality."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
     self.loop.run_until_complete(asyncio.Task(fan.do("speed:50")))
     self.assertEqual(fan.current_speed, 50)
     self.loop.run_until_complete(asyncio.Task(fan.do("speed:25")))
     self.assertEqual(fan.current_speed, 25)
Exemplo n.º 3
0
 def test_process_fan_payload_invalid_length(self):
     """Test process wrong telegrams. (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray((23, 24)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
Exemplo n.º 4
0
 def test_process_speed_wrong_payload(self):  # pylint: disable=invalid-name
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name="TestFan",
               group_address_speed='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTBinary(1))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
Exemplo n.º 5
0
    async def test_set_speed(self):
        """Test setting the speed of a Fan."""
        xknx = XKNX()
        fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
        await fan.set_speed(55)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # 140 is 55% as byte (0...255)
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        await fan.process(telegram)
        assert fan.is_on == True

        # A speed of 0 will turn off the fan implicitly if there is no
        # dedicated switch GA
        await fan.set_speed(0)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        # 140 is 55% as byte (0...255)
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan.process(telegram)
        assert fan.is_on == False

        fan_with_switch = Fan(
            xknx,
            name="TestFan",
            group_address_speed="1/2/3",
            group_address_switch="4/5/6",
        )
        await fan_with_switch.turn_on()
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("4/5/6"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        await fan_with_switch.process(telegram)
        assert fan_with_switch.is_on == True

        # A speed of 0 will not turn off the fan implicitly if there is a
        # dedicated switch GA defined. So we only expect a speed change telegram,
        # but no state switch one.
        await fan_with_switch.set_speed(0)
        assert xknx.telegrams.qsize() == 1
        telegram = xknx.telegrams.get_nowait()
        assert telegram == Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan_with_switch.process(telegram)
        assert fan_with_switch.is_on == True
Exemplo n.º 6
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name="TestFan",
               group_address_speed='1/2/3')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(fan.do("execute")))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with('Could not understand action %s for device %s', 'execute', 'TestFan')
Exemplo n.º 7
0
 def test_do(self):
     """Test 'do' functionality."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name="TestFan",
               group_address_speed='1/2/3')
     self.loop.run_until_complete(asyncio.Task(fan.do("speed:50")))
     self.assertEqual(fan.current_speed, 50)
     self.loop.run_until_complete(asyncio.Task(fan.do("speed:25")))
     self.assertEqual(fan.current_speed, 25)
Exemplo n.º 8
0
 def test_process_fan_payload_invalid_length(self):
     """Test process wrong telegrams. (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name="TestFan",
               group_address_speed='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray((23, 24)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
Exemplo n.º 9
0
 def test_do_speed(self):
     """Test 'do' functionality."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     self.loop.run_until_complete(fan.do("speed:50"))
     self.loop.run_until_complete(xknx.devices.process(xknx.telegrams.get_nowait()))
     self.assertEqual(fan.current_speed, 50)
     self.loop.run_until_complete(fan.do("speed:25"))
     self.loop.run_until_complete(xknx.devices.process(xknx.telegrams.get_nowait()))
     self.assertEqual(fan.current_speed, 25)
Exemplo n.º 10
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               'TestFan',
               group_address_speed='1/7/1',
               group_address_speed_state='1/7/2')
     self.assertTrue(fan.has_group_address(GroupAddress('1/7/1')))
     self.assertTrue(fan.has_group_address(GroupAddress('1/7/2')))
     self.assertFalse(fan.has_group_address(GroupAddress('1/7/3')))
Exemplo n.º 11
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
     with patch('logging.Logger.warning') as mock_warn:
         self.loop.run_until_complete(asyncio.Task(fan.do("execute")))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with(
             'Could not understand action %s for device %s', 'execute',
             'TestFan')
Exemplo n.º 12
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               'TestFan',
               group_address_speed='1/7/1',
               group_address_speed_state='1/7/2')
     self.assertTrue(fan.has_group_address(GroupAddress('1/7/1')))
     self.assertTrue(fan.has_group_address(GroupAddress('1/7/2')))
     self.assertFalse(fan.has_group_address(GroupAddress('1/7/3')))
Exemplo n.º 13
0
 def test_set_speed(self):
     """Test setting the speed of a Fan."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
     self.loop.run_until_complete(asyncio.Task(fan.set_speed(55)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     # 140 is 55% as byte (0...255)
     self.assertEqual(
         telegram, Telegram(GroupAddress('1/2/3'), payload=DPTArray(140)))
Exemplo n.º 14
0
    def test_process_speed(self):
        """Test process / reading telegrams from telegram queue. Test if speed is processed."""
        xknx = XKNX(loop=self.loop)
        fan = Fan(xknx, name="TestFan", group_address_speed='1/2/3')
        self.assertEqual(fan.current_speed, None)

        # 140 is 55% as byte (0...255)
        telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray(140))
        self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
        self.assertEqual(fan.current_speed, 55)
Exemplo n.º 15
0
 def test_wrong_do(self):
     """Test wrong do command."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     with patch("logging.Logger.warning") as mock_warn:
         self.loop.run_until_complete(fan.do("execute"))
         self.assertEqual(xknx.telegrams.qsize(), 0)
         mock_warn.assert_called_with(
             "Could not understand action %s for device %s", "execute",
             "TestFan")
Exemplo n.º 16
0
 def test_process_speed_wrong_payload(self):  # pylint: disable=invalid-name
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(1)),
     )
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(fan.process(telegram))
Exemplo n.º 17
0
 def test_process_fan_payload_invalid_length(self):
     """Test process wrong telegrams. (wrong payload length)."""
     # pylint: disable=invalid-name
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="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(fan.process(telegram))
Exemplo n.º 18
0
 def test_set_speed(self):
     """Test setting the speed of a Fan."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name="TestFan",
               group_address_speed='1/2/3')
     self.loop.run_until_complete(asyncio.Task(fan.set_speed(55)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     # 140 is 55% as byte (0...255)
     self.assertEqual(telegram,
                      Telegram(GroupAddress('1/2/3'), payload=DPTArray(140)))
Exemplo n.º 19
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX(loop=self.loop)
        fan = Fan(xknx, name="TestFan", group_address_speed_state='1/2/3')
        self.loop.run_until_complete(asyncio.Task(fan.sync(False)))

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

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram1, Telegram(GroupAddress('1/2/3'),
                                TelegramType.GROUP_READ))
Exemplo n.º 20
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX()
     fan = Fan(
         xknx,
         "TestFan",
         group_address_speed="1/7/1",
         group_address_speed_state="1/7/2",
     )
     self.assertTrue(fan.has_group_address(GroupAddress("1/7/1")))
     self.assertTrue(fan.has_group_address(GroupAddress("1/7/2")))
     self.assertFalse(fan.has_group_address(GroupAddress("1/7/3")))
Exemplo n.º 21
0
    def test_process_speed(self):
        """Test process / reading telegrams from telegram queue. Test if speed is processed."""
        xknx = XKNX(loop=self.loop)
        fan = Fan(xknx,
                  name="TestFan",
                  group_address_speed='1/2/3')
        self.assertEqual(fan.current_speed, None)

        # 140 is 55% as byte (0...255)
        telegram = Telegram(GroupAddress('1/2/3'), payload=DPTArray(140))
        self.loop.run_until_complete(asyncio.Task(fan.process(telegram)))
        self.assertEqual(fan.current_speed, 55)
Exemplo n.º 22
0
    def test_process_speed(self):
        """Test process / reading telegrams from telegram queue. Test if speed is processed."""
        xknx = XKNX()
        fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
        self.assertEqual(fan.current_speed, None)

        # 140 is 55% as byte (0...255)
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        self.loop.run_until_complete(fan.process(telegram))
        self.assertEqual(fan.current_speed, 55)
Exemplo n.º 23
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX(loop=self.loop)
        fan = Fan(xknx,
                  name="TestFan",
                  group_address_speed_state='1/2/3')
        self.loop.run_until_complete(asyncio.Task(fan.sync(False)))

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

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(telegram1,
                         Telegram(GroupAddress('1/2/3'), TelegramType.GROUP_READ))
Exemplo n.º 24
0
    def test_sync(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX()
        fan = Fan(xknx, name="TestFan", group_address_speed_state="1/2/3")
        self.loop.run_until_complete(fan.sync())

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

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram1,
            Telegram(destination_address=GroupAddress("1/2/3"),
                     payload=GroupValueRead()),
        )
Exemplo n.º 25
0
 def test_do_oscillation(self):
     """Test 'do' functionality."""
     xknx = XKNX()
     fan = Fan(
         xknx,
         name="TestFan",
         group_address_speed="1/2/3",
         group_address_oscillation="1/2/4",
     )
     self.loop.run_until_complete(fan.do("oscillation:True"))
     self.loop.run_until_complete(xknx.devices.process(xknx.telegrams.get_nowait()))
     self.assertTrue(fan.current_oscillation)
     self.loop.run_until_complete(fan.do("oscillation:False"))
     self.loop.run_until_complete(xknx.devices.process(xknx.telegrams.get_nowait()))
     self.assertFalse(fan.current_oscillation)
Exemplo n.º 26
0
 def test_set_speed(self):
     """Test setting the speed of a Fan."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     self.loop.run_until_complete(fan.set_speed(55))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     # 140 is 55% as byte (0...255)
     self.assertEqual(
         telegram,
         Telegram(
             destination_address=GroupAddress("1/2/3"),
             payload=GroupValueWrite(DPTArray(140)),
         ),
     )
Exemplo n.º 27
0
    async def test_process_speed(self):
        """Test process / reading telegrams from telegram queue. Test if speed is processed."""
        xknx = XKNX()
        fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
        assert fan.is_on is False
        assert fan.current_speed is None

        # 140 is 55% as byte (0...255)
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        await fan.process(telegram)
        # Setting a speed for a fan that has no dedicated switch GA,
        # should turn on the fan.
        assert fan.is_on is True
        assert fan.current_speed == 55

        # Now set a speed of zero which should turn off the fan.
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan.process(telegram)
        assert fan.is_on is False
        assert fan.current_speed == 0
Exemplo n.º 28
0
 def test_has_group_address(self):
     """Test has_group_address."""
     xknx = XKNX()
     fan = Fan(
         xknx,
         "TestFan",
         group_address_speed="1/7/1",
         group_address_speed_state="1/7/2",
         group_address_oscillation="1/6/1",
         group_address_oscillation_state="1/6/2",
     )
     assert fan.has_group_address(GroupAddress("1/7/1"))
     assert fan.has_group_address(GroupAddress("1/7/2"))
     assert not fan.has_group_address(GroupAddress("1/7/3"))
     assert fan.has_group_address(GroupAddress("1/6/1"))
     assert fan.has_group_address(GroupAddress("1/6/2"))
Exemplo n.º 29
0
    async def test_process_switch(self):
        """Test process / reading telegrams from telegram queue. Test if switch is handled correctly."""
        xknx = XKNX()
        fan = Fan(
            xknx,
            name="TestFan",
            group_address_speed="1/2/3",
            group_address_switch="4/5/6",
        )
        assert fan.is_on is False
        assert fan.current_speed is None

        # 140 is 55% as byte (0...255)
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        await fan.process(telegram)
        # Setting a speed for a fan with dedicated switch GA,
        # should not turn on the fan
        assert fan.is_on is False
        assert fan.current_speed == 55

        # Now turn on the fan via its switch GA
        telegram = Telegram(
            destination_address=GroupAddress("4/5/6"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        await fan.process(telegram)
        assert fan.is_on is True
        assert fan.current_speed == 55

        # Setting a speed of 0 should not turn off the fan
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(0)),
        )
        await fan.process(telegram)
        assert fan.is_on is True
        assert fan.current_speed == 0

        # Set the speed again so we can verify that switching off the fan does not
        # modify the set speed
        telegram = Telegram(
            destination_address=GroupAddress("1/2/3"),
            payload=GroupValueWrite(DPTArray(140)),
        )
        await fan.process(telegram)
        assert fan.is_on is True
        assert fan.current_speed == 55

        # Now turn off the fan via the dedicated switch GA
        telegram = Telegram(
            destination_address=GroupAddress("4/5/6"),
            payload=GroupValueWrite(DPTBinary(0)),
        )
        await fan.process(telegram)
        assert fan.is_on is False
        assert fan.current_speed == 55
Exemplo n.º 30
0
    def test_sync_state_address(self):
        """Test sync function / sending group reads to KNX bus."""
        xknx = XKNX()
        fan = Fan(
            xknx,
            name="TestFan",
            group_address_speed="1/2/3",
            group_address_speed_state="1/2/4",
        )
        self.loop.run_until_complete(fan.sync())

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

        telegram1 = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram1, Telegram(GroupAddress("1/2/4"),
                                TelegramType.GROUP_READ))
Exemplo n.º 31
0
    def test_process_oscillation(self):
        """Test process / reading telegrams from telegram queue. Test if oscillation is processed."""
        xknx = XKNX()
        fan = Fan(
            xknx,
            name="TestFan",
            group_address_speed="1/2/3",
            group_address_oscillation="1/2/5",
        )
        self.assertEqual(fan.current_oscillation, None)

        telegram = Telegram(
            destination_address=GroupAddress("1/2/5"),
            payload=GroupValueWrite(DPTBinary(1)),
        )
        self.loop.run_until_complete(fan.process(telegram))
        self.assertTrue(fan.current_oscillation)
Exemplo n.º 32
0
 def parse_group_fan(self, entries):
     """Parse a fan section of xknx.yaml."""
     for entry in entries:
         fan = Fan.from_config(
             self.xknx,
             entry,
             entries[entry])
         self.xknx.devices.add(fan)
Exemplo n.º 33
0
 def test_config_fan(self):
     """Test reading Fan from config file."""
     self.assertEqual(
         TestConfig.xknx.devices['Kitchen.Fan_1'],
         Fan(TestConfig.xknx,
             'Kitchen.Fan_1',
             group_address_speed='1/3/21',
             group_address_speed_state='1/3/22',
             device_updated_cb=TestConfig.xknx.devices.device_updated))
Exemplo n.º 34
0
 async def test_sync(self):
     """Test sync function / sending group reads to KNX bus."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed_state="1/2/3")
     await fan.sync()
     assert xknx.telegrams.qsize() == 1
     telegram1 = xknx.telegrams.get_nowait()
     assert telegram1 == Telegram(destination_address=GroupAddress("1/2/3"),
                                  payload=GroupValueRead())
Exemplo n.º 35
0
 def test_set_oscillation(self):
     """Test setting the oscillation of a Fan."""
     xknx = XKNX()
     fan = Fan(
         xknx,
         name="TestFan",
         group_address_speed="1/2/3",
         group_address_oscillation="1/2/5",
     )
     self.loop.run_until_complete(fan.set_oscillation(False))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(
             destination_address=GroupAddress("1/2/5"),
             payload=GroupValueWrite(DPTBinary(0)),
         ),
     )
Exemplo n.º 36
0
 async def test_process_fan_payload_invalid_length(self):
     """Test process wrong telegrams. (wrong payload length)."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTArray((23, 24))),
     )
     with pytest.raises(CouldNotParseTelegram):
         await fan.process(telegram)
Exemplo n.º 37
0
 async def test_process_speed_wrong_payload(self):
     """Test process wrong telegrams. (wrong payload type)."""
     xknx = XKNX()
     fan = Fan(xknx, name="TestFan", group_address_speed="1/2/3")
     telegram = Telegram(
         destination_address=GroupAddress("1/2/3"),
         payload=GroupValueWrite(DPTBinary(1)),
     )
     with pytest.raises(CouldNotParseTelegram):
         await fan.process(telegram)
Exemplo n.º 38
0
 def test_fan(self):
     """Test string representation of fan object."""
     xknx = XKNX(loop=self.loop)
     fan = Fan(xknx,
               name='Dunstabzug',
               group_address_speed='1/2/3',
               group_address_speed_state='1/2/4')
     self.assertEqual(
         str(fan),
         '<Fan name="Dunstabzug" speed="GroupAddress("1/2/3")/GroupAddress("1/2/4")/None/None" />'
     )
Exemplo n.º 39
0
 def test_config_fan(self):
     """Test reading Fan from config file."""
     self.assertEqual(
         TestConfig.xknx.devices["Kitchen.Fan_1"],
         Fan(
             TestConfig.xknx,
             "Kitchen.Fan_1",
             group_address_speed="1/3/21",
             group_address_speed_state="1/3/22",
         ),
     )