def test_4byte_float_values_from_voltage_meter(self): """Test parsing DPT4ByteFloat from voltage meter.""" self.assertEqual( round(DPT4ByteFloat().from_knx((0x43, 0x65, 0xE3, 0xD7)), 2), 229.89) self.assertEqual(DPT4ByteFloat().to_knx(229.89), (0x43, 0x65, 0xE3, 0xD7))
def test_14_055(self): """Test DPTPhaseAngleDeg object.""" self.assertEqual(DPT4ByteFloat().from_knx((0x42, 0xEF, 0x00, 0x00)), 119.5) self.assertEqual(DPT4ByteFloat().to_knx(119.5), (0x42, 0xEF, 0x00, 0x00)) self.assertEqual(DPTPhaseAngleDeg().unit, "°")
def test_14_057(self): """Test DPT4ByteFloat object.""" self.assertEqual( round(DPT4ByteFloat().from_knx((0x3F, 0x71, 0xEB, 0x86)), 7), 0.9450001) self.assertEqual(DPT4ByteFloat().to_knx(0.945000052452), (0x3F, 0x71, 0xEB, 0x86)) self.assertEqual(DPT4ByteFloat().unit, "")
def test_4byte_float_special_value(self): """Test parsing and streaming of DPT4ByteFloat special value.""" assert math.isnan(DPT4ByteFloat.from_knx((0x7F, 0xC0, 0x00, 0x00))) assert DPT4ByteFloat.to_knx(float("nan")) == (0x7F, 0xC0, 0x00, 0x00) assert math.isinf(DPT4ByteFloat.from_knx((0x7F, 0x80, 0x00, 0x00))) assert DPT4ByteFloat.to_knx(float("inf")) == (0x7F, 0x80, 0x00, 0x00) assert DPT4ByteFloat.from_knx((0xFF, 0x80, 0x00, 0x00)) == float("-inf") assert DPT4ByteFloat.to_knx(float("-inf")) == (0xFF, 0x80, 0x00, 0x00) assert DPT4ByteFloat.from_knx((0x80, 0x00, 0x00, 0x00)) == float("-0") assert DPT4ByteFloat.to_knx(float("-0")) == (0x80, 0x00, 0x00, 0x00)
def test_4byte_flaot_from_knx_unpack_error(self): """Test DPT4ByteFloat parsing with unpack error.""" with patch("struct.unpack") as unpack_mock: unpack_mock.side_effect = struct.error() with pytest.raises(ConversionError): DPT4ByteFloat.from_knx((0x01, 0x23, 0x02, 0x02))
def test_4byte_float_from_knx_wrong_parameter2(self): """Test parsing of DPT4ByteFloat with wrong value (second parameter is a string).""" with pytest.raises(ConversionError): DPT4ByteFloat.from_knx((0xF8, "0x23", 0x00, 0x00))
def test_4byte_float_from_knx_wrong_parameter(self): """Test parsing of DPT4ByteFloat with wrong value (wrong number of bytes).""" with pytest.raises(ConversionError): DPT4ByteFloat.from_knx((0xF8, 0x01, 0x23))
def test_4byte_float_to_knx_wrong_parameter(self): """Test parsing of DPT4ByteFloat with wrong value (string).""" with pytest.raises(ConversionError): DPT4ByteFloat.to_knx("fnord")
def test_4byte_float_zero_value(self): """Test parsing and streaming of DPT4ByteFloat zero value.""" assert DPT4ByteFloat.from_knx((0x00, 0x00, 0x00, 0x00)) == 0.00 assert DPT4ByteFloat.to_knx(0.00) == (0x00, 0x00, 0x00, 0x00)
def test_4byte_float_values_from_voltage_meter(self): """Test parsing DPT4ByteFloat from voltage meter.""" assert DPT4ByteFloat.from_knx((0x43, 0x65, 0xE3, 0xD7)) == 229.89 assert DPT4ByteFloat.to_knx(229.89) == (0x43, 0x65, 0xE3, 0xD7)
def test_14_057(self): """Test DPT4ByteFloat object.""" assert DPT4ByteFloat.from_knx((0x3F, 0x71, 0xEB, 0x86)) == 0.9450001 assert DPT4ByteFloat.to_knx(0.945000052452) == (0x3F, 0x71, 0xEB, 0x86) assert DPT4ByteFloat.unit == ""
def test_14_055(self): """Test DPTPhaseAngleDeg object.""" assert DPT4ByteFloat.from_knx((0x42, 0xEF, 0x00, 0x00)) == 119.5 assert DPT4ByteFloat.to_knx(119.5) == (0x42, 0xEF, 0x00, 0x00) assert DPTPhaseAngleDeg.unit == "°"
def test_4byte_float_values_from_power_meter(self): """Test parsing DPT4ByteFloat value from power meter.""" assert DPT4ByteFloat.from_knx((0x43, 0xC6, 0x80, 00)) == 397 assert DPT4ByteFloat.to_knx(397) == (0x43, 0xC6, 0x80, 00) assert DPT4ByteFloat.from_knx((0x42, 0x38, 0x00, 00)) == 46 assert DPT4ByteFloat.to_knx(46) == (0x42, 0x38, 0x00, 00)
def test_4byte_float_zero_value(self): """Test parsing and streaming of DPT4ByteFloat zero value.""" self.assertEqual(DPT4ByteFloat().from_knx((0x00, 0x00, 0x00, 0x00)), 0.00) self.assertEqual(DPT4ByteFloat().to_knx(0.00), (0x00, 0x00, 0x00, 0x00))
def test_4byte_float_values_from_power_meter(self): """Test parsing DPT4ByteFloat value from power meter.""" self.assertEqual(DPT4ByteFloat().from_knx((0x43, 0xC6, 0x80, 00)), 397) self.assertEqual(DPT4ByteFloat().to_knx(397), (0x43, 0xC6, 0x80, 00)) self.assertEqual(DPT4ByteFloat().from_knx((0x42, 0x38, 0x00, 00)), 46) self.assertEqual(DPT4ByteFloat().to_knx(46), (0x42, 0x38, 0x00, 00))
def test_4byte_flaot_from_knx_unpack_error(self): """Test DPT4ByteFloat parsing with unpack error.""" with patch('struct.unpack') as unpackMock: unpackMock.side_effect = struct.error() with self.assertRaises(ConversionError): DPT4ByteFloat().from_knx((0x01, 0x23, 0x02, 0x02))