def test_set(self):
     """Test setting value."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueSceneNumber(
         xknx, group_address=GroupAddress("1/2/3"))
     self.loop.run_until_complete(asyncio.Task(remote_value.set(10)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'), payload=DPTArray((0x0A, ))))
     self.loop.run_until_complete(asyncio.Task(remote_value.set(11)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'), payload=DPTArray((0x0B, ))))
Beispiel #2
0
 async def broadcast_time(self, response):
     """Broadcast time to KNX bus."""
     if self.broadcast_type == DateTimeBroadcastType.DATETIME:
         broadcast_data = DPTDateTime.current_datetime_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
     elif self.broadcast_type == DateTimeBroadcastType.DATE:
         broadcast_data = DPTDate.current_date_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
     elif self.broadcast_type == DateTimeBroadcastType.TIME:
         broadcast_data = DPTTime.current_time_as_knx()
         await self.send(self.group_address,
                         DPTArray(broadcast_data),
                         response=response)
Beispiel #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)))
Beispiel #4
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)))
Beispiel #5
0
 def test_process_wrong_payload(self):
     """Test process wrong telegram (wrong payload type)."""
     xknx = XKNX(loop=self.loop)
     binary_sensor = BinarySensor(xknx, 'Warning', group_address='1/2/3')
     telegram = Telegram(GroupAddress('1/2/3'),
                         payload=DPTArray((0x1, 0x2, 0x3)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(
             asyncio.Task(binary_sensor.process(telegram)))
Beispiel #6
0
    def test_str_scaling(self):
        xknx = XKNX(self.loop, start=False)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address='1/2/3',
                        value_type="percent")
        sensor.state = DPTArray((0x40, ))

        self.assertEqual(sensor.resolve_state(), "25")
        self.assertEqual(sensor.unit_of_measurement(), "%")
Beispiel #7
0
    def test_base_temperature(self):
        """Test base temperature."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_target_temperature_state='1/2/1',
                          group_address_target_temperature='1/2/2',
                          group_address_setpoint_shift='1/2/3')

        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(21.00)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(21.00))))
        self.assertFalse(climate.initialized_for_setpoint_shift_calculations)
        self.assertEqual(climate.base_temperature, None)

        # setpoint_shift initialized after target_temperature (no temperature change)
        self.loop.run_until_complete(
            asyncio.Task(climate.set_setpoint_shift(1)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            # DEFAULT_SETPOINT_SHIFT_STEP is 0.5 -> payload = setpoint_shift * 2
            Telegram(GroupAddress('1/2/3'), payload=DPTArray(2)))
        self.assertTrue(climate.initialized_for_setpoint_shift_calculations)
        self.assertEqual(climate.base_temperature, 20.00)

        # setpoint_shift changed after initialisation
        self.loop.run_until_complete(
            asyncio.Task(climate.set_setpoint_shift(2)))
        # setpoint_shift and target_temperature are sent to the bus
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            # DEFAULT_SETPOINT_SHIFT_STEP is 0.5 -> payload = setpoint_shift * 2
            Telegram(GroupAddress('1/2/3'), payload=DPTArray(4)))
        self.assertTrue(climate.initialized_for_setpoint_shift_calculations)
        self.assertEqual(climate.base_temperature, 20.00)
        self.assertEqual(climate.target_temperature.value, 22)
Beispiel #8
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)
Beispiel #9
0
 def test_process(self):
     """Test process telegram."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueColorRGB(xknx,
                                        group_address=GroupAddress("1/2/3"))
     telegram = Telegram(group_address=GroupAddress("1/2/3"),
                         payload=DPTArray((0x64, 0x65, 0x66)))
     self.loop.run_until_complete(
         asyncio.Task(remote_value.process(telegram)))
     self.assertEqual(remote_value.value, (100, 101, 102))
Beispiel #10
0
 def test_process(self):
     """Test process telegram."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueDpt2ByteUnsigned(
         xknx, group_address=GroupAddress("1/2/3"))
     telegram = Telegram(group_address=GroupAddress("1/2/3"),
                         payload=DPTArray((0x0A, 0x0B)))
     self.loop.run_until_complete(
         asyncio.Task(remote_value.process(telegram)))
     self.assertEqual(remote_value.value, 2571)
Beispiel #11
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!"))))
Beispiel #12
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)))
Beispiel #13
0
    def test_target_temperature_modified_step(self):
        """Test increase target temperature with modified step size."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_target_temperature='1/2/2',
                          group_address_setpoint_shift='1/2/3',
                          setpoint_shift_step=0.1,
                          setpoint_shift_max=10,
                          setpoint_shift_min=-10)

        self.loop.run_until_complete(
            asyncio.Task(climate.set_setpoint_shift(3)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            # setpoint_shift_step is 0.1 -> payload = setpoint_shift * 10
            Telegram(GroupAddress('1/2/3'), payload=DPTArray(30)))

        self.loop.run_until_complete(
            asyncio.Task(climate.target_temperature.set(23.00)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(23.00))))
        self.assertEqual(climate.base_temperature, 20.00)
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(24.00)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'), payload=DPTArray(40)))
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(24.00))))
        self.assertEqual(climate.target_temperature.value, 24.00)

        # Test max/min target temperature
        self.assertEqual(climate.target_temperature_max, 30.00)
        self.assertEqual(climate.target_temperature_min, 10.00)
Beispiel #14
0
    def test_str_temp(self):
        """Test resolve state with temperature sensor."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address='1/2/3',
                        value_type="temperature")
        sensor.state = DPTArray((0x0c, 0x1a))

        self.assertEqual(sensor.resolve_state(), 21.00)
        self.assertEqual(sensor.unit_of_measurement(), "°C")
Beispiel #15
0
 def test_process_operation_mode_payload_invalid_length(self):
     """Test process wrong telegram for operation mode (wrong payload length)."""
     xknx = XKNX(loop=self.loop)
     climate = Climate(xknx,
                       'TestClimate',
                       group_address_operation_mode='1/2/5',
                       group_address_controller_status='1/2/3')
     telegram = Telegram(GroupAddress('1/2/5'), payload=DPTArray((23, 24)))
     with self.assertRaises(CouldNotParseTelegram):
         self.loop.run_until_complete(
             asyncio.Task(climate.process(telegram)))
Beispiel #16
0
    def test_process_temperature(self):
        """Test process / reading telegrams from telegram queue. Test if temperature is processed correctly."""
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_temperature='1/2/3')

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        self.assertEqual(climate.temperature.value, 21.34)
Beispiel #17
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)))
Beispiel #18
0
    def test_process_percent(self):
        """Test reading percent expose sensor from bus."""
        xknx = XKNX(loop=self.loop)
        expose_sensor = ExposeSensor(xknx,
                                     'TestSensor',
                                     value_type='percent',
                                     group_address='1/2/3')
        expose_sensor.sensor_value.payload = DPTArray((0x40, ))

        telegram = Telegram(GroupAddress('1/2/3'))
        telegram.telegramtype = TelegramType.GROUP_READ
        self.loop.run_until_complete(
            asyncio.Task(expose_sensor.process(telegram)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        telegram = xknx.telegrams.get_nowait()
        self.assertEqual(
            telegram,
            Telegram(GroupAddress('1/2/3'),
                     TelegramType.GROUP_RESPONSE,
                     payload=DPTArray((0x40, ))))
Beispiel #19
0
    def test_process_setpoint(self):
        xknx = XKNX(self.loop, start=False)
        thermostat = Thermostat(xknx,
                                'TestThermostat',
                                group_address_setpoint='1/2/3')

        telegram = Telegram(Address('1/2/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        thermostat.process(telegram)

        self.assertEqual(thermostat.setpoint, 21.34)
Beispiel #20
0
    def test_str_percent(self):
        """Test resolve state with percent sensor."""
        xknx = XKNX(loop=self.loop)
        expose_sensor = ExposeSensor(xknx,
                                     'TestSensor',
                                     group_address='1/2/3',
                                     value_type="percent")
        expose_sensor.sensor_value.payload = DPTArray((0x40, ))

        self.assertEqual(expose_sensor.resolve_state(), 75)
        self.assertEqual(expose_sensor.unit_of_measurement(), "%")
Beispiel #21
0
 def test_process_operation_mode(self):
     """Test process / reading telegrams from telegram queue. Test if setpoint is processed correctly."""
     xknx = XKNX(loop=self.loop)
     climate = Climate(
         xknx,
         'TestClimate',
         group_address_operation_mode='1/2/5',
         group_address_controller_status='1/2/3')
     for operation_mode in HVACOperationMode:
         telegram = Telegram(Address('1/2/5'))
         telegram.payload = DPTArray(DPTHVACMode.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
         self.assertEqual(climate.operation_mode, operation_mode)
     for operation_mode in HVACOperationMode:
         if operation_mode == HVACOperationMode.AUTO:
             continue
         telegram = Telegram(Address('1/2/3'))
         telegram.payload = DPTArray(DPTControllerStatus.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
         self.assertEqual(climate.operation_mode, operation_mode)
Beispiel #22
0
    def test_str_electric_potential(self):
        """Test resolve state with voltage sensor."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address_state='1/2/3',
                        value_type="electric_potential")
        sensor.sensor_value.payload = DPTArray((0x43, 0x65, 0xE3, 0xD7))

        self.assertEqual(round(sensor.resolve_state(), 2), 229.89)
        self.assertEqual(sensor.unit_of_measurement(), "V")
Beispiel #23
0
    def test_str_humidity(self):
        """Test resolve state with humidity sensor."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address='1/2/3',
                        value_type="humidity")
        sensor.state = DPTArray((0x0e, 0x73))

        self.assertEqual(sensor.resolve_state(), 33.02)
        self.assertEqual(sensor.unit_of_measurement(), "%")
Beispiel #24
0
    def test_str_power(self):
        """Test resolve state with power sensor."""
        xknx = XKNX(loop=self.loop)
        sensor = Sensor(xknx,
                        'TestSensor',
                        group_address='1/2/3',
                        value_type="power")
        sensor.sensor_value.payload = DPTArray((0x43, 0xC6, 0x80, 00))

        self.assertEqual(sensor.resolve_state(), 397)
        self.assertEqual(sensor.unit_of_measurement(), "W")
Beispiel #25
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))
Beispiel #26
0
 def test_set(self):
     """Test setting value."""
     xknx = XKNX(loop=self.loop)
     remote_value = RemoteValueDpt2ByteUnsigned(
         xknx, group_address=GroupAddress("1/2/3"))
     self.loop.run_until_complete(asyncio.Task(remote_value.set(2571)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'), payload=DPTArray((0x0A, 0x0B))))
     self.loop.run_until_complete(asyncio.Task(remote_value.set(5500)))
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(
         telegram,
         Telegram(GroupAddress('1/2/3'), payload=DPTArray((
             0x15,
             0x7C,
         ))))
Beispiel #27
0
    def test_process_callback_updated_via_telegram(self):
        """Test if after_update_callback is called after update of Climate object."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_temperature='1/2/1',
                          group_address_target_temperature='1/2/2',
                          group_address_setpoint_shift='1/2/3',
                          group_address_operation_mode='1/2/4')

        after_update_callback = Mock()

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

        climate.register_device_updated_cb(async_after_update_callback)

        telegram = Telegram(GroupAddress('1/2/1'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/2'),
                            payload=DPTArray(DPTTemperature.to_knx(23)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/3'),
                            payload=DPTArray(DPTValue1Count.to_knx(-4)))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()

        telegram = Telegram(GroupAddress('1/2/4'), payload=DPTArray(1))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
        after_update_callback.reset_mock()
Beispiel #28
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)
Beispiel #29
0
 def test_set_brightness(self):
     xknx = XKNX(self.loop, start=False)
     light = Light(xknx,
                   name="TestLight",
                   group_address_switch='1/2/3',
                   group_address_dimm='1/2/4',
                   group_address_brightness='1/2/5')
     light.set_brightness(23)
     self.assertEqual(xknx.telegrams.qsize(), 1)
     telegram = xknx.telegrams.get_nowait()
     self.assertEqual(telegram,
                      Telegram(Address('1/2/5'), payload=DPTArray(23)))
Beispiel #30
0
    def test_process_dimm(self):
        xknx = XKNX(self.loop, start=False)
        light = Light(xknx,
                      name="TestLight",
                      group_address_switch='1/2/3',
                      group_address_dimm='1/2/4',
                      group_address_brightness='1/2/5')
        self.assertEqual(light.brightness, 0)

        telegram = Telegram(Address('1/2/5'), payload=DPTArray(23))
        light.process(telegram)
        self.assertEqual(light.brightness, 23)