Пример #1
0
 def test_xyycolor_value(self):
     """Test DPTColorXYY parsing and streaming with valid value."""
     assert DPTColorXYY.to_knx(((0.2, 0.2), 128)) == (
         0x33,
         0x33,
         0x33,
         0x33,
         0x80,
         0x03,
     )
     assert DPTColorXYY.from_knx((0x33, 0x33, 0x33, 0x33, 0x80, 0x03)) == (
         (0.2, 0.2),
         128,
     )
     assert DPTColorXYY.to_knx(XYYColor(color=(0.8, 0.8), brightness=204)) == (
         0xCC,
         0xCC,
         0xCC,
         0xCC,
         0xCC,
         0x03,
     )
     assert DPTColorXYY.from_knx((0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0x03)) == XYYColor(
         color=(0.8, 0.8), brightness=204
     )
Пример #2
0
 def test_xyycolor_value_max_value(self):
     """Test DPTColorXYY parsing and streaming."""
     assert DPTColorXYY.to_knx(((1, 1), 255)) == (0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03)
     assert DPTColorXYY.from_knx((0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03)) == (
         (1, 1),
         255,
     )
Пример #3
0
    def test_xyycolor_value_none_value(self):
        """Test DPTColorXYY parsing and streaming with null values."""
        assert DPTColorXYY.to_knx((None, 0)) == (0x00, 0x00, 0x00, 0x00, 0x00, 0x01)
        assert DPTColorXYY.from_knx((0x00, 0x00, 0x00, 0x00, 0x00, 0x01)) == (None, 0)

        assert DPTColorXYY.to_knx(((0, 0), None)) == (
            0x00,
            0x00,
            0x00,
            0x00,
            0x00,
            0x02,
        )
        assert DPTColorXYY.from_knx((0x00, 0x00, 0x00, 0x00, 0x00, 0x02)) == (
            (0, 0),
            None,
        )

        assert DPTColorXYY.to_knx((None, None)) == (0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
        assert DPTColorXYY.from_knx((0x00, 0x00, 0x00, 0x00, 0x00, 0x00)) == (
            None,
            None,
        )
Пример #4
0
 def from_knx(self, payload: DPTArray) -> XYYColor:
     """Convert current payload to value."""
     return DPTColorXYY.from_knx(payload.value)
Пример #5
0
 def to_knx(self, value: XYYColor) -> DPTArray:
     """Convert value to payload."""
     return DPTArray(DPTColorXYY.to_knx(value))
Пример #6
0
 def test_xyycolor_wrong_value_from_knx(self):
     """Test DPTColorXYY parsing with wrong value."""
     with pytest.raises(ConversionError):
         DPTColorXYY.from_knx((0xFF, 0x4E, 0x12))
Пример #7
0
 def test_xyycolor_wrong_value_to_knx(self):
     """Test DPTColorXYY parsing with wrong value."""
     with pytest.raises(ConversionError):
         DPTColorXYY.to_knx(None)
         DPTColorXYY.to_knx((0xFF, 0x4E, 0x12))
         DPTColorXYY.to_knx(1)
         DPTColorXYY.to_knx(((0x00, 0xFF, 0x4E), 0x12))
         DPTColorXYY.to_knx(((0xFF, 0x4E), (0x12, 0x00)))
         DPTColorXYY.to_knx(((0, 0), "a"))
         DPTColorXYY.to_knx(((0, 0), 0.4))
Пример #8
0
 def test_xyycolor_value_min_value(self):
     """Test DPTColorXYY parsing and streaming with null values."""
     assert DPTColorXYY.to_knx(((0, 0), 0)) == (0x00, 0x00, 0x00, 0x00, 0x00, 0x03)
     assert DPTColorXYY.from_knx((0x00, 0x00, 0x00, 0x00, 0x00, 0x03)) == ((0, 0), 0)
Пример #9
0
 def test_xyycolor_to_knx_exceed_limits(self):
     """Test initialization of DPTColorXYY with wrong value (Overflow)."""
     with pytest.raises(ConversionError):
         DPTColorXYY.to_knx(((1.1, 0), 0))
         DPTColorXYY.to_knx(((0, 1.1), 0))
         DPTColorXYY.to_knx(((0, 0), 256))
Пример #10
0
 def test_xyycolor_assert_min_exceeded(self):
     """Test initialization of DPTColorXYY with wrong value (Underflow)."""
     with pytest.raises(ConversionError):
         DPTColorXYY.to_knx(((-0.1, 0), 0))
         DPTColorXYY.to_knx(((0, -0.1), 0))
         DPTColorXYY.to_knx(((0, 0), -1))