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)
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)
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)
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)
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)
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))
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"))
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)
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)
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)
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)
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)
def test_to_knx_wrong_parameter(self): """Test parsing of DPT2ByteFloat with wrong value (string).""" with self.assertRaises(ConversionError): DPT2ByteFloat().to_knx("fnord")
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)