def test_high_temperature(self): """Test parsing and streaming of DPTFloat 500.00, 499.84, 500.16. Testing rounding issues.""" self.assertEqual(DPTFloat().to_knx(500.00), (0x2E, 0x1A)) self.assertAlmostEqual(DPTFloat().from_knx((0x2E, 0x1A)), 499.84) self.assertAlmostEqual(DPTFloat().from_knx((0x2E, 0x1B)), 500.16) self.assertEqual(DPTFloat().to_knx(499.84), (0x2E, 0x1A)) self.assertEqual(DPTFloat().to_knx(500.16), (0x2E, 0x1B))
def test_very_cold_temperature(self): """Test parsing and streaming of DPTFloat -1000.00,-999.68, -1000.32. Testing rounding issues of negative values.""" self.assertEqual(DPTFloat().to_knx(-1000.00), (0xB1, 0xE6)) self.assertEqual(DPTFloat().from_knx((0xB1, 0xE6)), -999.68) self.assertEqual(DPTFloat().from_knx((0xB1, 0xE5)), -1000.32) self.assertEqual(DPTFloat().to_knx(-999.68), (0xB1, 0xE6)) self.assertEqual(DPTFloat().to_knx(-1000.32), (0xB1, 0xE5))
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(Address('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(Address('1/2/2'), payload=DPTArray(DPTFloat().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(Address('1/2/3'), payload=DPTArray(0xFD))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(Address('1/2/2'), payload=DPTArray(DPTFloat().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(Address('1/2/3'), payload=DPTArray(0xFA))) # -3 self.assertEqual( xknx.telegrams.get_nowait(), Telegram(Address('1/2/2'), payload=DPTArray(DPTFloat().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)))
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=20, setpoint_shift_min=-20) self.loop.run_until_complete(asyncio.Task(climate.setpoint_shift.set(10))) self.assertEqual(xknx.telegrams.qsize(), 1) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(Address('1/2/3'), payload=DPTArray(10))) 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(Address('1/2/2'), payload=DPTArray(DPTFloat().to_knx(23.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(Address('1/2/3'), payload=DPTArray(20))) self.assertEqual( xknx.telegrams.get_nowait(), Telegram(Address('1/2/2'), payload=DPTArray(DPTFloat().to_knx(24.00)))) self.assertEqual(climate.target_temperature.value, 24.00) # Test max/min target temperature self.assertEqual(climate.target_temperature_max, 24.00) self.assertEqual(climate.target_temperature_min, 20.00)
def test_high_temperature(self): self.assertEqual(DPTFloat().to_knx(500.00), (0x2E, 0x1A)) self.assertAlmostEqual(DPTFloat().from_knx((0x2E, 0x1A)), 499.84) self.assertAlmostEqual(DPTFloat().from_knx((0x2E, 0x1B)), 500.16) self.assertEqual(DPTFloat().to_knx(499.84), (0x2E, 0x1A)) self.assertEqual(DPTFloat().to_knx(500.16), (0x2E, 0x1B))
def test_zero_value(self): self.assertEqual(DPTFloat().to_knx(0.00), (0x00, 0x00)) self.assertEqual(DPTFloat().from_knx((0x00, 0x00)), 0.00)
def test_room_temperature(self): self.assertEqual(DPTFloat().to_knx(21.00), (0x0c, 0x1a)) self.assertEqual(DPTFloat().from_knx((0x0c, 0x1a)), 21.00)
def test_to_knx_max_exceeded(self): with self.assertRaises(ConversionError): DPTFloat().to_knx(DPTFloat.value_max + 1)
def test_room_temperature(self): """Test parsing and streaming of DPTFloat 21.00. Room temperature.""" self.assertEqual(DPTFloat().to_knx(21.00), (0x0c, 0x1a)) self.assertEqual(DPTFloat().from_knx((0x0c, 0x1a)), 21.00)
def test_max(self): self.assertEqual(DPTFloat().to_knx(DPTFloat.value_max), (0x7F, 0xFF)) self.assertEqual(DPTFloat().from_knx((0x7F, 0xFF)), DPTFloat.value_max)
def test_close_to_max(self): self.assertEqual(DPTFloat().to_knx(670433.28), (0x7F, 0xFE)) self.assertEqual(DPTFloat().from_knx((0x7F, 0xFE)), 670433.28)
def test_to_knx_wrong_parameter(self): """Test parsing of DPTFloat with wrong value (string).""" with self.assertRaises(ConversionError): DPTFloat().to_knx("fnord")
def test_from_knx_wrong_parameter(self): """Test parsing of DPTFloat with wrong value (wrong number of bytes).""" with self.assertRaises(ConversionError): DPTFloat().from_knx((0xF8, 0x01, 0x23))
def test_close_to_min(self): """Test parsing and streaming of DPTFloat with minimum value +1.""" self.assertEqual(DPTFloat().to_knx(-670760.96), (0xF8, 0x01)) self.assertEqual(DPTFloat().from_knx((0xF8, 0x01)), -670760.96)
def test_to_knx_max_exceeded(self): """Test parsing of DPTFloat with wrong value (overflow).""" with self.assertRaises(ConversionError): DPTFloat().to_knx(DPTFloat.value_max + 1)
def test_close_to_max(self): """Test parsing and streaming of DPTFloat with maximum value -1.""" self.assertEqual(DPTFloat().to_knx(670433.28), (0x7F, 0xFE)) self.assertEqual(DPTFloat().from_knx((0x7F, 0xFE)), 670433.28)
def test_min(self): """Test parsing and streaming of DPTFloat with minimum value.""" self.assertEqual(DPTFloat().to_knx(DPTFloat.value_min), (0xF8, 0x00)) self.assertEqual(DPTFloat().from_knx((0xF8, 0x00)), DPTFloat.value_min)
def test_max(self): """Test parsing and streaming of DPTFloat with maximum value.""" self.assertEqual(DPTFloat().to_knx(DPTFloat.value_max), (0x7F, 0xFF)) self.assertEqual(DPTFloat().from_knx((0x7F, 0xFF)), DPTFloat.value_max)
def test_minor_negative_temperature(self): self.assertEqual(DPTFloat().to_knx(-10.00), (0x84, 0x18)) self.assertEqual(DPTFloat().from_knx((0x84, 0x18)), -10.00)
def test_from_knx_wrong_parameter2(self): """Test parsing of DPTFloat with wrong value (second parameter is a string).""" with self.assertRaises(ConversionError): DPTFloat().from_knx((0xF8, "0x23"))
def test_very_cold_temperature(self): self.assertEqual(DPTFloat().to_knx(-1000.00), (0xB1, 0xE6)) self.assertEqual(DPTFloat().from_knx((0xB1, 0xE6)), -999.68) self.assertEqual(DPTFloat().from_knx((0xB1, 0xE5)), -1000.32) self.assertEqual(DPTFloat().to_knx(-999.68), (0xB1, 0xE6)) self.assertEqual(DPTFloat().to_knx(-1000.32), (0xB1, 0xE5))
def test_from_knx_wrong_parameter2(self): with self.assertRaises(ConversionError): DPTFloat().from_knx((0xF8, "0x23"))
def test_min(self): self.assertEqual(DPTFloat().to_knx(DPTFloat.value_min), (0xF8, 0x00)) self.assertEqual(DPTFloat().from_knx((0xF8, 0x00)), DPTFloat.value_min)
def test_zero_value(self): """Test parsing and streaming of DPTFloat zero value.""" self.assertEqual(DPTFloat().to_knx(0.00), (0x00, 0x00)) self.assertEqual(DPTFloat().from_knx((0x00, 0x00)), 0.00)
def test_close_to_min(self): self.assertEqual(DPTFloat().to_knx(-670760.96), (0xF8, 0x01)) self.assertEqual(DPTFloat().from_knx((0xF8, 0x01)), -670760.96)
def test_value_taken_from_live_thermostat(self): self.assertEqual(DPTFloat().to_knx(16.96), (0x06, 0xa0)) self.assertEqual(DPTFloat().from_knx((0x06, 0xa0)), 16.96)
def test_to_knx_wrong_parameter(self): with self.assertRaises(ConversionError): DPTFloat().to_knx("fnord")
def test_minor_negative_temperature(self): """Test parsing and streaming of DPTFloat -10.00. Testing negative values.""" self.assertEqual(DPTFloat().to_knx(-10.00), (0x84, 0x18)) self.assertEqual(DPTFloat().from_knx((0x84, 0x18)), -10.00)
def test_value_from_documentation(self): self.assertEqual(DPTFloat().to_knx(-30.00), (0x8a, 0x24)) self.assertEqual(DPTFloat().from_knx((0x8a, 0x24)), -30.00)
def test_value_taken_from_live_thermostat(self): """Test parsing and streaming of DPTFloat 19.96.""" self.assertEqual(DPTFloat().to_knx(16.96), (0x06, 0xa0)) self.assertEqual(DPTFloat().from_knx((0x06, 0xa0)), 16.96)