Ejemplo n.º 1
0
 def test_mode_to_knx(self):
     """Test parsing DPTHVACMode to KNX."""
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.AUTO), (0x00,))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.COMFORT), (0x01,))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.STANDBY), (0x02,))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.NIGHT), (0x03,))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.FROST_PROTECTION), (0x04,))
Ejemplo n.º 2
0
 def test_mode_from_knx(self):
     """Test parsing DPTHVACMode from KNX."""
     self.assertEqual(DPTHVACMode.from_knx((0x00,)), HVACOperationMode.AUTO)
     self.assertEqual(DPTHVACMode.from_knx((0x01,)), HVACOperationMode.COMFORT)
     self.assertEqual(DPTHVACMode.from_knx((0x02,)), HVACOperationMode.STANDBY)
     self.assertEqual(DPTHVACMode.from_knx((0x03,)), HVACOperationMode.NIGHT)
     self.assertEqual(DPTHVACMode.from_knx((0x04,)), HVACOperationMode.FROST_PROTECTION)
Ejemplo n.º 3
0
 def test_mode_to_knx(self):
     """Test parsing DPTHVACMode to KNX."""
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.AUTO), (0x00, ))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.COMFORT),
                      (0x01, ))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.STANDBY),
                      (0x02, ))
     self.assertEqual(DPTHVACMode.to_knx(HVACOperationMode.NIGHT), (0x03, ))
     self.assertEqual(
         DPTHVACMode.to_knx(HVACOperationMode.FROST_PROTECTION), (0x04, ))
Ejemplo n.º 4
0
 def test_mode_from_knx(self):
     """Test parsing DPTHVACMode from KNX."""
     self.assertEqual(DPTHVACMode.from_knx((0x00, )),
                      HVACOperationMode.AUTO)
     self.assertEqual(DPTHVACMode.from_knx((0x01, )),
                      HVACOperationMode.COMFORT)
     self.assertEqual(DPTHVACMode.from_knx((0x02, )),
                      HVACOperationMode.STANDBY)
     self.assertEqual(DPTHVACMode.from_knx((0x03, )),
                      HVACOperationMode.NIGHT)
     self.assertEqual(DPTHVACMode.from_knx((0x04, )),
                      HVACOperationMode.FROST_PROTECTION)
Ejemplo n.º 5
0
 def _process_operation_mode(self, telegram):
     """Process incoming telegram for operation mode."""
     if not isinstance(telegram.payload, DPTArray) \
             or len(telegram.payload.value) != 1:
         raise CouldNotParseTelegram()
     operation_mode = DPTHVACMode.from_knx(telegram.payload.value)
     yield from self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 6
0
 async def set_operation_mode(self, operation_mode):
     """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
     if not self.supports_operation_mode:
         raise DeviceIllegalValue("operation mode not supported", operation_mode)
     if self.group_address_operation_mode is not None:
         await self.send(
             self.group_address_operation_mode,
             DPTArray(DPTHVACMode.to_knx(operation_mode)))
     if self.group_address_operation_mode_protection is not None:
         protection_mode = operation_mode == HVACOperationMode.FROST_PROTECTION
         await self.send(
             self.group_address_operation_mode_protection,
             DPTBinary(protection_mode))
     if self.group_address_operation_mode_night is not None:
         night_mode = operation_mode == HVACOperationMode.NIGHT
         await self.send(
             self.group_address_operation_mode_night,
             DPTBinary(night_mode))
     if self.group_address_operation_mode_comfort is not None:
         comfort_mode = operation_mode == HVACOperationMode.COMFORT
         await self.send(
             self.group_address_operation_mode_comfort,
             DPTBinary(comfort_mode))
     if self.group_address_controller_status is not None:
         await self.send(
             self.group_address_controller_status,
             DPTArray(DPTControllerStatus.to_knx(operation_mode)))
     if self.group_address_controller_mode is not None:
         await self.send(
             self.group_address_controller_mode,
             DPTArray(DPTHVACContrMode.to_knx(operation_mode)))
     await self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 7
0
 async def set_operation_mode(self, operation_mode):
     """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
     if not self.supports_operation_mode:
         raise DeviceIllegalValue("operation mode not supported",
                                  operation_mode)
     if self.group_address_operation_mode is not None:
         await self.send(self.group_address_operation_mode,
                         DPTArray(DPTHVACMode.to_knx(operation_mode)))
     if self.group_address_operation_mode_protection is not None:
         protection_mode = operation_mode == HVACOperationMode.FROST_PROTECTION
         await self.send(self.group_address_operation_mode_protection,
                         DPTBinary(protection_mode))
     if self.group_address_operation_mode_night is not None:
         night_mode = operation_mode == HVACOperationMode.NIGHT
         await self.send(self.group_address_operation_mode_night,
                         DPTBinary(night_mode))
     if self.group_address_operation_mode_comfort is not None:
         comfort_mode = operation_mode == HVACOperationMode.COMFORT
         await self.send(self.group_address_operation_mode_comfort,
                         DPTBinary(comfort_mode))
     if self.group_address_controller_status is not None:
         await self.send(
             self.group_address_controller_status,
             DPTArray(DPTControllerStatus.to_knx(operation_mode)))
     if self.group_address_controller_mode is not None:
         await self.send(self.group_address_controller_mode,
                         DPTArray(DPTHVACContrMode.to_knx(operation_mode)))
     await self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 8
0
 async def _process_operation_mode(self, telegram):
     """Process incoming telegram for operation mode."""
     if not isinstance(telegram.payload, DPTArray) \
             or len(telegram.payload.value) != 1:
         raise CouldNotParseTelegram("invalid payload", payload=telegram.payload, device_name=self.name)
     operation_mode = DPTHVACMode.from_knx(telegram.payload.value)
     await self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 9
0
 async def _process_operation_mode(self, telegram):
     """Process incoming telegram for operation mode."""
     if not isinstance(telegram.payload, DPTArray) \
             or len(telegram.payload.value) != 1:
         raise CouldNotParseTelegram("invalid payload", payload=telegram.payload, device_name=self.name)
     operation_mode = DPTHVACMode.from_knx(telegram.payload.value)
     await self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 10
0
    def test_set_operation_mode(self):
        """Test set_operation_mode."""
        xknx = XKNX(loop=self.loop)
        climate_mode = ClimateMode(xknx,
                                   'TestClimate',
                                   group_address_operation_mode='1/2/4')

        for operation_mode in DPT_20102_MODES:
            self.loop.run_until_complete(
                asyncio.Task(climate_mode.set_operation_mode(operation_mode)))
            self.assertEqual(xknx.telegrams.qsize(), 1)
            telegram = xknx.telegrams.get_nowait()
            self.assertEqual(
                telegram,
                Telegram(GroupAddress('1/2/4'),
                         payload=DPTArray(DPTHVACMode.to_knx(operation_mode))))
Ejemplo n.º 11
0
    def test_set_operation_mode(self):
        """Test set_operation_mode."""
        xknx = XKNX(loop=self.loop)
        climate_mode = ClimateMode(
            xknx,
            'TestClimate',
            group_address_operation_mode='1/2/4')

        for operation_mode in DPT_20102_MODES:
            self.loop.run_until_complete(asyncio.Task(climate_mode.set_operation_mode(operation_mode)))
            self.assertEqual(xknx.telegrams.qsize(), 1)
            telegram = xknx.telegrams.get_nowait()
            self.assertEqual(
                telegram,
                Telegram(
                    GroupAddress('1/2/4'),
                    payload=DPTArray(DPTHVACMode.to_knx(operation_mode))))
Ejemplo n.º 12
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_mode = ClimateMode(
         xknx,
         'TestClimate',
         group_address_operation_mode='1/2/5',
         group_address_controller_status='1/2/3')
     for operation_mode in DPT_20102_MODES:
         telegram = Telegram(GroupAddress('1/2/5'))
         telegram.payload = DPTArray(DPTHVACMode.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate_mode.process(telegram)))
         self.assertEqual(climate_mode.operation_mode, operation_mode)
     for operation_mode in DPT_20102_MODES:
         if operation_mode == HVACOperationMode.AUTO:
             continue
         telegram = Telegram(GroupAddress('1/2/3'))
         telegram.payload = DPTArray(DPTControllerStatus.to_knx(operation_mode))
         self.loop.run_until_complete(asyncio.Task(climate_mode.process(telegram)))
         self.assertEqual(climate_mode.operation_mode, operation_mode)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def set_operation_mode(self, operation_mode):
     """Set the operation mode of a thermostat. Send new operation_mode to BUS and update internal state."""
     if not self.supports_operation_mode:
         return
     if self.group_address_operation_mode is not None:
         yield from self.send(self.group_address_operation_mode,
                              DPTArray(DPTHVACMode.to_knx(operation_mode)))
     if self.group_address_operation_mode_protection is not None:
         protection_mode = operation_mode == HVACOperationMode.FROST_PROTECTION
         yield from self.send(self.group_address_operation_mode_protection,
                              DPTBinary(protection_mode))
     if self.group_address_operation_mode_night is not None:
         night_mode = operation_mode == HVACOperationMode.NIGHT
         yield from self.send(self.group_address_operation_mode_night,
                              DPTBinary(night_mode))
     if self.group_address_operation_mode_comfort is not None:
         comfort_mode = operation_mode == HVACOperationMode.COMFORT
         yield from self.send(self.group_address_operation_mode_comfort,
                              DPTBinary(comfort_mode))
     if self.group_address_controller_status is not None:
         yield from self.send(
             self.group_address_controller_status,
             DPTArray(DPTControllerStatus.to_knx(operation_mode)))
     yield from self._set_internal_operation_mode(operation_mode)
Ejemplo n.º 15
0
 def test_mode_from_knx_wrong_value(self):
     """Test parsing of DPTControllerStatus with wrong value)."""
     with self.assertRaises(ConversionError):
         DPTHVACMode.from_knx((1, 2))
Ejemplo n.º 16
0
 def test_mode_to_knx_wrong_value(self):
     """Test serializing DPTHVACMode to KNX with wrong value."""
     with self.assertRaises(ConversionError):
         DPTHVACMode.to_knx(5)
Ejemplo n.º 17
0
 def test_mode_from_knx_wrong_code(self):
     """Test parsing of DPTHVACMode with wrong code."""
     with self.assertRaises(CouldNotParseKNXIP):
         DPTHVACMode.from_knx((0x05, ))
Ejemplo n.º 18
0
 def test_mode_from_knx_wrong_code(self):
     """Test parsing of DPTHVACMode with wrong code."""
     with self.assertRaises(CouldNotParseKNXIP):
         DPTHVACMode.from_knx((0x05,))
Ejemplo n.º 19
0
 def test_mode_from_knx_wrong_value(self):
     """Test parsing of DPTControllerStatus with wrong value)."""
     with self.assertRaises(ConversionError):
         DPTHVACMode.from_knx((1, 2))
Ejemplo n.º 20
0
 def test_mode_to_knx_wrong_value(self):
     """Test serializing DPTHVACMode to KNX with wrong value."""
     with self.assertRaises(ConversionError):
         DPTHVACMode.to_knx(5)