Exemplo n.º 1
0
 def test_high_temperature(self):
     """Test parsing and streaming of DPT2ByteFloat 500.00, 499.84, 500.16. Testing rounding issues."""
     self.assertEqual(DPT2ByteFloat().to_knx(500.00), (0x2E, 0x1A))
     self.assertAlmostEqual(DPT2ByteFloat().from_knx((0x2E, 0x1A)), 499.84)
     self.assertAlmostEqual(DPT2ByteFloat().from_knx((0x2E, 0x1B)), 500.16)
     self.assertEqual(DPT2ByteFloat().to_knx(499.84), (0x2E, 0x1A))
     self.assertEqual(DPT2ByteFloat().to_knx(500.16), (0x2E, 0x1B))
Exemplo n.º 2
0
    def test_target_temperature_up(self):
        """Test increase target temperature."""
        # 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')

        self.loop.run_until_complete(
            asyncio.Task(climate.set_setpoint_shift(3)))
        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(6)))

        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)

        # First change
        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(8)))
        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)

        # Second change
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(23.50)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'), payload=DPTArray(7)))
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(23.50))))
        self.assertEqual(climate.target_temperature.value, 23.50)

        # Test max target temperature
        # Base (20) - setpoint_shift_max (6)
        self.assertEqual(climate.target_temperature_max, 26.00)

        # third change - limit exceeded, setting to max
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(26.50)))
        self.assertEqual(climate.target_temperature_max, 26.00)
        self.assertEqual(climate.setpoint_shift, 6)
Exemplo n.º 3
0
    def test_target_temperature_down(self):
        """Test decrease target temperature."""
        # 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')

        self.loop.run_until_complete(
            asyncio.Task(climate.setpoint_shift.set(1)))
        self.assertEqual(xknx.telegrams.qsize(), 1)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'), payload=DPTArray(1)))

        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))))

        # First change
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(21.00)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'),
                                  payload=DPTArray(0xFD)))  # -3
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(21.00))))
        self.assertEqual(climate.target_temperature.value, 21.00)

        # Second change
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(19.50)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'),
                                  payload=DPTArray(0xFA)))  # -3
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(19.50))))
        self.assertEqual(climate.target_temperature.value, 19.50)

        # Test min target temperature
        self.assertEqual(climate.target_temperature_min, 19.50)

        # third change - limit exceeded, setting to max
        with self.assertRaises(DeviceIllegalValue):
            self.loop.run_until_complete(
                asyncio.Task(climate.set_target_temperature(19.00)))
Exemplo n.º 4
0
    def test_very_cold_temperature(self):
        """
        Test parsing and streaming of DPT2ByteFloat -1000.00,-999.68, -1000.32.

        Testing rounding issues of negative values.
        """
        self.assertEqual(DPT2ByteFloat().to_knx(-1000.00), (0xB1, 0xE6))
        self.assertEqual(DPT2ByteFloat().from_knx((0xB1, 0xE6)), -999.68)
        self.assertEqual(DPT2ByteFloat().from_knx((0xB1, 0xE5)), -1000.32)
        self.assertEqual(DPT2ByteFloat().to_knx(-999.68), (0xB1, 0xE6))
        self.assertEqual(DPT2ByteFloat().to_knx(-1000.32), (0xB1, 0xE5))
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def test_max(self):
     """Test parsing and streaming of DPT2ByteFloat with maximum value."""
     self.assertEqual(DPT2ByteFloat().to_knx(DPT2ByteFloat.value_max),
                      (0x7F, 0xFF))
     self.assertEqual(DPT2ByteFloat().from_knx((0x7F, 0xFF)),
                      DPT2ByteFloat.value_max)
Exemplo n.º 8
0
    def test_target_temperature_down(self):
        """Test decrease target temperature."""
        # 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')

        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.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, 22.0)

        # First change
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(20.50)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'),
                                  payload=DPTArray(0xFD)))  # -3
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(20.50))))
        self.assertEqual(climate.target_temperature.value, 20.50)

        # Second change
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(19.00)))
        self.assertEqual(xknx.telegrams.qsize(), 2)
        self.assertEqual(xknx.telegrams.get_nowait(),
                         Telegram(GroupAddress('1/2/3'),
                                  payload=DPTArray(0xFA)))  # -6
        self.assertEqual(
            xknx.telegrams.get_nowait(),
            Telegram(GroupAddress('1/2/2'),
                     payload=DPTArray(DPT2ByteFloat().to_knx(19.00))))
        self.assertEqual(climate.target_temperature.value, 19.00)

        # Test min target temperature
        # Base (22) - setpoint_shift_min (6)
        self.assertEqual(climate.target_temperature_min, 16.00)

        # third change - limit exceeded, setting to min
        self.loop.run_until_complete(
            asyncio.Task(climate.set_target_temperature(15.50)))
        self.assertEqual(climate.target_temperature_min, 16.00)
        self.assertEqual(climate.setpoint_shift, -6)
Exemplo n.º 9
0
 def test_value_from_documentation(self):
     """Test parsing and streaming of DPT2ByteFloat -30.00. Example from the internet[tm]."""
     self.assertEqual(DPT2ByteFloat().to_knx(-30.00), (0x8a, 0x24))
     self.assertEqual(DPT2ByteFloat().from_knx((0x8a, 0x24)), -30.00)
Exemplo n.º 10
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing of DPT2ByteFloat with wrong value (string)."""
     with self.assertRaises(ConversionError):
         DPT2ByteFloat().to_knx("fnord")
Exemplo n.º 11
0
 def test_to_knx_max_exceeded(self):
     """Test parsing of DPT2ByteFloat with wrong value (overflow)."""
     with self.assertRaises(ConversionError):
         DPT2ByteFloat().to_knx(DPT2ByteFloat.value_max + 1)
Exemplo n.º 12
0
 def test_close_to_min(self):
     """Test parsing and streaming of DPT2ByteFloat with minimum value +1."""
     self.assertEqual(DPT2ByteFloat().to_knx(-670760.96), (0xF8, 0x01))
     self.assertEqual(DPT2ByteFloat().from_knx((0xF8, 0x01)), -670760.96)
Exemplo n.º 13
0
 def test_close_to_max(self):
     """Test parsing and streaming of DPT2ByteFloat with maximum value -1."""
     self.assertEqual(DPT2ByteFloat().to_knx(670433.28), (0x7F, 0xFE))
     self.assertEqual(DPT2ByteFloat().from_knx((0x7F, 0xFE)), 670433.28)
Exemplo n.º 14
0
 def test_from_knx_wrong_parameter2(self):
     """Test parsing of DPT2ByteFloat with wrong value (second parameter is a string)."""
     with self.assertRaises(ConversionError):
         DPT2ByteFloat().from_knx((0xF8, "0x23"))
Exemplo n.º 15
0
 def test_value_taken_from_live_thermostat(self):
     """Test parsing and streaming of DPT2ByteFloat 19.96."""
     self.assertEqual(DPT2ByteFloat().to_knx(16.96), (0x06, 0xa0))
     self.assertEqual(DPT2ByteFloat().from_knx((0x06, 0xa0)), 16.96)
Exemplo n.º 16
0
 def test_minor_negative_temperature(self):
     """Test parsing and streaming of DPT2ByteFloat -10.00. Testing negative values."""
     self.assertEqual(DPT2ByteFloat().to_knx(-10.00), (0x84, 0x18))
     self.assertEqual(DPT2ByteFloat().from_knx((0x84, 0x18)), -10.00)
Exemplo n.º 17
0
 def test_zero_value(self):
     """Test parsing and streaming of DPT2ByteFloat zero value."""
     self.assertEqual(DPT2ByteFloat().to_knx(0.00), (0x00, 0x00))
     self.assertEqual(DPT2ByteFloat().from_knx((0x00, 0x00)), 0.00)
Exemplo n.º 18
0
 def test_room_temperature(self):
     """Test parsing and streaming of DPT2ByteFloat 21.00. Room temperature."""
     self.assertEqual(DPT2ByteFloat().to_knx(21.00), (0x0c, 0x1a))
     self.assertEqual(DPT2ByteFloat().from_knx((0x0c, 0x1a)), 21.00)
Exemplo n.º 19
0
 def test_min(self):
     """Test parsing and streaming of DPT2ByteFloat with minimum value."""
     self.assertEqual(DPT2ByteFloat().to_knx(DPT2ByteFloat.value_min),
                      (0xF8, 0x00))
     self.assertEqual(DPT2ByteFloat().from_knx((0xF8, 0x00)),
                      DPT2ByteFloat.value_min)
Exemplo n.º 20
0
 def test_from_knx_wrong_parameter(self):
     """Test parsing of DPT2ByteFloat with wrong value (wrong number of bytes)."""
     with self.assertRaises(ConversionError):
         DPT2ByteFloat().from_knx((0xF8, 0x01, 0x23))