Ejemplo n.º 1
0
    def test_payload_valid(self):
        """Test payload_valid method."""
        xknx = XKNX()
        remote_value = RemoteValueSensor(xknx=xknx, value_type="pulse")
        valid_payload = DPTArray(DPTValue1Ucount.to_knx(1))

        assert remote_value.dpt_class == DPTValue1Ucount
        with pytest.raises(CouldNotParseTelegram):
            remote_value.payload_valid(None)
        with pytest.raises(CouldNotParseTelegram):
            remote_value.payload_valid(DPTArray((1, 2, 3, 4)))
        with pytest.raises(CouldNotParseTelegram):
            remote_value.payload_valid(DPTBinary(1))
        assert remote_value.payload_valid(valid_payload) == valid_payload
Ejemplo n.º 2
0
 def test_from_knx_wrong_parameter2(self):
     """Test parsing of DPTValue1Ucount with wrong value (array containing string)."""
     with self.assertRaises(ConversionError):
         DPTValue1Ucount().from_knx(("0x23"))
Ejemplo n.º 3
0
 def test_from_knx_wrong_value(self):
     """Test parsing of DPTValue1Ucount with value which exceeds limits."""
     with self.assertRaises(ConversionError):
         DPTValue1Ucount().from_knx((0x256, ))
Ejemplo n.º 4
0
 def test_from_knx_wrong_parameter(self):
     """Test parsing of DPTValue1Ucount with wrong value (3 byte array)."""
     with self.assertRaises(ConversionError):
         DPTValue1Ucount().from_knx((0x01, 0x02, 0x03))
Ejemplo n.º 5
0
 def test_to_knx_wrong_parameter(self):
     """Test parsing of DPTValue1Ucount with wrong value (string)."""
     with self.assertRaises(ConversionError):
         DPTValue1Ucount().to_knx("fnord")
Ejemplo n.º 6
0
 def test_to_knx_max_exceeded(self):
     """Test parsing of DPTValue1Ucount with wrong value (overflow)."""
     with self.assertRaises(ConversionError):
         DPTValue1Ucount().to_knx(DPTValue1Ucount.value_max + 1)
Ejemplo n.º 7
0
 def test_value_min(self):
     """Test parsing and streaming of DPTValue1Ucount 0."""
     self.assertEqual(DPTValue1Ucount().to_knx(0), (0x00, ))
     self.assertEqual(DPTValue1Ucount().from_knx((0x00, )), 0)
Ejemplo n.º 8
0
 def test_value_max(self):
     """Test parsing and streaming of DPTValue1Ucount 255."""
     self.assertEqual(DPTValue1Ucount().to_knx(255), (0xFF, ))
     self.assertEqual(DPTValue1Ucount().from_knx((0xFF, )), 255)
Ejemplo n.º 9
0
 def test_value_50(self):
     """Test parsing and streaming of DPTValue1Ucount 50."""
     self.assertEqual(DPTValue1Ucount().to_knx(50), (0x32, ))
     self.assertEqual(DPTValue1Ucount().from_knx((0x32, )), 50)
 def from_knx(self, payload: DPTArray) -> int:
     """Convert current payload to value."""
     return DPTValue1Ucount.from_knx(payload.value)
 def to_knx(self, value: int) -> DPTArray:
     """Convert value to payload."""
     return DPTArray(DPTValue1Ucount.to_knx(value))
Ejemplo n.º 12
0
 def test_value_50(self):
     """Test parsing and streaming of DPTValue1Ucount 50."""
     assert DPTValue1Ucount.to_knx(50) == (0x32,)
     assert DPTValue1Ucount.from_knx((0x32,)) == 50
Ejemplo n.º 13
0
 def test_to_knx_min_exceeded(self):
     """Test parsing of DPTValue1Ucount with wrong value (underflow)."""
     with pytest.raises(ConversionError):
         DPTValue1Ucount.to_knx(DPTValue1Ucount.value_min - 1)
Ejemplo n.º 14
0
 def test_value_min(self):
     """Test parsing and streaming of DPTValue1Ucount 0."""
     assert DPTValue1Ucount.to_knx(0) == (0x00,)
     assert DPTValue1Ucount.from_knx((0x00,)) == 0
Ejemplo n.º 15
0
 def test_value_max(self):
     """Test parsing and streaming of DPTValue1Ucount 255."""
     assert DPTValue1Ucount.to_knx(255) == (0xFF,)
     assert DPTValue1Ucount.from_knx((0xFF,)) == 255