Exemplo n.º 1
0
 def resolve_state(self):
     """Return the current state of the sensor as a human readable string."""
     # pylint: disable=invalid-name,too-many-return-statements
     if self.state is None:
         return None
     elif self.value_type == 'percent' and \
             isinstance(self.state, DPTArray) and \
             len(self.state.value) == 1:
         # TODO: Instanciate DPTScaling object with DPTArray class
         return "{0}".format(DPTScaling().from_knx(self.state.value))
     elif self.value_type == 'humidity':
         return DPTHumidity().from_knx(self.state.value)
     elif self.value_type == 'temperature':
         return DPTTemperature().from_knx(self.state.value)
     elif self.value_type == 'illuminance':
         return DPTLux().from_knx(self.state.value)
     elif self.value_type == 'speed_ms':
         return DPTWsp().from_knx(self.state.value)
     elif self.value_type == 'current':
         return DPTUElCurrentmA().from_knx(self.state.value)
     elif isinstance(self.state, DPTArray):
         return ','.join('0x%02x' % i for i in self.state.value)
     elif isinstance(self.state, DPTBinary):
         return "{0:b}".format(self.state.value)
     raise TypeError()
Exemplo n.º 2
0
 def test_current_wrong_value_from_knx(self):
     """Test DPTUElCurrentmA parsing with wrong value."""
     with self.assertRaises(ConversionError):
         DPTUElCurrentmA().from_knx((0xFF, 0x4E, 0x12))
Exemplo n.º 3
0
 def test_current_value_1234(self):
     """Test DPTUElCurrentmA parsing and streaming 4660mA."""
     self.assertEqual(DPTUElCurrentmA().to_knx(4660), (0x12, 0x34))
     self.assertEqual(DPTUElCurrentmA().from_knx((0x12, 0x34)), 4660)
Exemplo n.º 4
0
 def test_current_value_78(self):
     """Test DPTUElCurrentmA parsing and streaming 78mA."""
     self.assertEqual(DPTUElCurrentmA().to_knx(78), (0x00, 0x4E))
     self.assertEqual(DPTUElCurrentmA().from_knx((0x00, 0x4E)), 78)
Exemplo n.º 5
0
 def test_current_value_38(self):
     """Test DPTUElCurrentmA parsing and streaming 38mA."""
     self.assertEqual(DPTUElCurrentmA().to_knx(38), (0x00, 0x26))
     self.assertEqual(DPTUElCurrentmA().from_knx((0x00, 0x26)), 38)
Exemplo n.º 6
0
 def test_current_value_min_value(self):
     """Test DPTUElCurrentmA parsing and streaming with null values."""
     self.assertEqual(DPTUElCurrentmA().to_knx(0), (0x00, 0x00))
     self.assertEqual(DPTUElCurrentmA().from_knx((0x00, 0x00)), 0)
Exemplo n.º 7
0
 def test_current_value_max_value(self):
     """Test DPTUElCurrentmA parsing and streaming."""
     self.assertEqual(DPTUElCurrentmA().to_knx(65535), (0xFF, 0xFF))
     self.assertEqual(DPTUElCurrentmA().from_knx((0xFF, 0xFF)), 65535)
Exemplo n.º 8
0
 def test_current_to_knx_exceed_limits(self):
     """Test initialization of DPTUElCurrentmA with wrong value (Overflow)."""
     with self.assertRaises(ConversionError):
         DPTUElCurrentmA().to_knx(65536)
Exemplo n.º 9
0
 def test_current_assert_min_exceeded(self):
     """Test initialization of DPTUElCurrentmA with wrong value (Underflow)."""
     with self.assertRaises(ConversionError):
         DPTUElCurrentmA().to_knx(-1)
Exemplo n.º 10
0
 def test_current_settings(self):
     """Test members of DPTUElCurrentmA."""
     self.assertEqual(DPTUElCurrentmA().value_min, 0)
     self.assertEqual(DPTUElCurrentmA().value_max, 65535)
     self.assertEqual(DPTUElCurrentmA().unit, "mA")
     self.assertEqual(DPTUElCurrentmA().resolution, 1)