Esempio n. 1
0
 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))
Esempio n. 2
0
 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, "°")
Esempio n. 3
0
 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, "")
Esempio n. 4
0
 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))
Esempio n. 5
0
 def test_4byte_float_from_knx_wrong_parameter2(self):
     """Test parsing of DPT4ByteFloat with wrong value (second parameter is a string)."""
     with self.assertRaises(ConversionError):
         DPT4ByteFloat().from_knx((0xF8, "0x23", 0x00, 0x00))
Esempio n. 6
0
 def test_4byte_float_from_knx_wrong_parameter(self):
     """Test parsing of DPT4ByteFloat with wrong value (wrong number of bytes)."""
     with self.assertRaises(ConversionError):
         DPT4ByteFloat().from_knx((0xF8, 0x01, 0x23))
Esempio n. 7
0
 def test_4byte_float_to_knx_wrong_parameter(self):
     """Test parsing of DPT4ByteFloat with wrong value (string)."""
     with self.assertRaises(ConversionError):
         DPT4ByteFloat().to_knx("fnord")
Esempio n. 8
0
 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))
Esempio n. 9
0
 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))