Пример #1
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')

        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()
Пример #2
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')

        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()
Пример #3
0
 def resolve_state(self):
     """Return the current state of the sensor as a human readable string."""
     # pylint: disable=invalid-name,too-many-return-statements
     if self.state is None:
         return None
     elif self.value_type == 'percent' and \
             isinstance(self.state, DPTArray) and \
             len(self.state.value) == 1:
         # TODO: Instanciate DPTScaling object with DPTArray class
         return "{0}".format(DPTScaling().from_knx(self.state.value))
     elif self.value_type == 'humidity':
         return DPTHumidity().from_knx(self.state.value)
     elif self.value_type == 'temperature':
         return DPTTemperature().from_knx(self.state.value)
     elif self.value_type == 'illuminance':
         return DPTLux().from_knx(self.state.value)
     elif self.value_type == 'speed_ms':
         return DPTWsp().from_knx(self.state.value)
     elif self.value_type == 'current':
         return DPTUElCurrentmA().from_knx(self.state.value)
     elif isinstance(self.state, DPTArray):
         return ','.join('0x%02x' % i for i in self.state.value)
     elif isinstance(self.state, DPTBinary):
         return "{0:b}".format(self.state.value)
     raise TypeError()
Пример #4
0
    def _process_setpoint(self, telegram):
        if not isinstance(telegram.payload, DPTArray) \
                or len(telegram.payload.value) != 2:
            raise CouldNotParseTelegram()

        self.setpoint = DPTTemperature().from_knx(
            (telegram.payload.value[0], telegram.payload.value[1]))
        self.after_update()
Пример #5
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)
Пример #6
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)
Пример #7
0
    def test_process_callback_temp(self):
        # pylint: disable=no-self-use
        xknx = XKNX(self.loop, start=False)
        thermostat = Thermostat(xknx,
                                'TestThermostat',
                                group_address_temperature='1/2/3',
                                group_address_setpoint='1/2/4')

        after_update_callback = Mock()
        thermostat.after_update_callback = after_update_callback

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

        after_update_callback.assert_called_with(thermostat)
Пример #8
0
    def test_process_callback_temp(self):
        """Test process / reading telegrams from telegram queue. Test if callback is executed when receiving temperature."""
        # pylint: disable=no-self-use
        xknx = XKNX(loop=self.loop)
        climate = Climate(xknx,
                          'TestClimate',
                          group_address_temperature='1/2/3')

        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/3'))
        telegram.payload = DPTArray(DPTTemperature().to_knx(21.34))
        self.loop.run_until_complete(asyncio.Task(climate.process(telegram)))
        after_update_callback.assert_called_with(climate)
Пример #9
0
    def test_EndTOEnd_group_write_2bytes(self):
        # Incoming Temperature from thermostat
        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x13, 0x29, 0x00,
                0xbc, 0xd0, 0x14, 0x02, 0x08, 0x01, 0x03, 0x00,
                0x80, 0x07, 0xc1))

        knxipframe = KNXIPFrame()
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.telegram
        self.assertEqual(telegram,
                         Telegram(Address("2049"),
                                  payload=DPTArray(
                                      DPTTemperature().to_knx(19.85))))

        knxipframe2 = KNXIPFrame()
        knxipframe2.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe2.body.src_addr = Address("1.4.2")
        knxipframe2.body.telegram = telegram
        knxipframe2.body.set_hops(5)
        knxipframe2.normalize()

        self.assertEqual(knxipframe2.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe2.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe2.to_knx(), list(raw))
Пример #10
0
    def test_EndTOEnd_group_write_2bytes(self):
        """Test parsing and streaming CEMIFrame KNX/IP packet, setting value of thermostat."""
        # Incoming Temperature from thermostat
        raw = ((0x06, 0x10, 0x05, 0x30, 0x00, 0x13, 0x29, 0x00, 0xbc, 0xd0,
                0x14, 0x02, 0x08, 0x01, 0x03, 0x00, 0x80, 0x07, 0xc1))
        xknx = XKNX(loop=self.loop)
        knxipframe = KNXIPFrame(xknx)
        knxipframe.from_knx(raw)
        telegram = knxipframe.body.telegram
        self.assertEqual(
            telegram,
            Telegram(GroupAddress("2049"),
                     payload=DPTArray(DPTTemperature().to_knx(19.85))))

        knxipframe2 = KNXIPFrame(xknx)
        knxipframe2.init(KNXIPServiceType.ROUTING_INDICATION)
        knxipframe2.body.src_addr = PhysicalAddress("1.4.2")
        knxipframe2.body.telegram = telegram
        knxipframe2.body.set_hops(5)
        knxipframe2.normalize()

        self.assertEqual(knxipframe2.header.to_knx(), list(raw[0:6]))
        self.assertEqual(knxipframe2.body.to_knx(), list(raw[6:]))
        self.assertEqual(knxipframe2.to_knx(), list(raw))
Пример #11
0
 def to_knx(self, value):
     """Convert value to payload."""
     return DPTArray(DPTTemperature.to_knx(value))
Пример #12
0
 def test_temperature_assert_min_exceeded(self):
     """Testing parsing of DPTTemperature with wrong value."""
     with self.assertRaises(ConversionError):
         DPTTemperature().to_knx(-274)
Пример #13
0
 def test_temperature_settings(self):
     """Test attributes of DPTTemperature."""
     self.assertEqual(DPTTemperature().value_min, -273)
     self.assertEqual(DPTTemperature().value_max, 670760)
     self.assertEqual(DPTTemperature().unit, "°C")
     self.assertEqual(DPTTemperature().resolution, 1)
Пример #14
0
 def test_temperature_assert_min_exceeded(self):
     with self.assertRaises(ConversionError):
         DPTTemperature().to_knx(-274)
Пример #15
0
 def test_temperature_assert_min_exceeded_from_knx(self):
     with self.assertRaises(ConversionError):
         DPTTemperature().from_knx((0xB1, 0xE6))  # -1000
Пример #16
0
 def test_temperature_settings(self):
     self.assertEqual(DPTTemperature().value_min, -273)
     self.assertEqual(DPTTemperature().value_max, 670760)
     self.assertEqual(DPTTemperature().unit, "C")
     self.assertEqual(DPTTemperature().resolution, 1)
Пример #17
0
 def test_temperature_assert_min_exceeded_from_knx(self):
     """Testing parsing of DPTTemperature with wrong value."""
     with self.assertRaises(ConversionError):
         DPTTemperature().from_knx((0xB1, 0xE6))  # -1000
Пример #18
0
 def from_knx(self, payload):
     """Convert current payload to value."""
     return DPTTemperature.from_knx(payload.value)
Пример #19
0
 def to_knx(self, value):
     """Convert value to payload."""
     return DPTArray(DPTTemperature.to_knx(value))
Пример #20
0
 def from_knx(self, payload):
     """Convert current payload to value."""
     return DPTTemperature.from_knx(payload.value)