Exemplo n.º 1
0
 def test_to_knx_wrong_values(self):
     """Test serializing map with keys of invalid values to DPTControlStepCode."""
     # with self.assertRaises(ConversionError):
     #     DPTControlStepCode.to_knx({"control": -1, "step_code": 0})
     # with self.assertRaises(ConversionError):
     #     DPTControlStepCode.to_knx({"control": 2, "step_code": 0})
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"control": 0, "step_code": -1})
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"control": 0, "step_code": 0x8})
Exemplo n.º 2
0
 def test_from_knx(self):
     """Test parsing DPTControlStepCode types from KNX."""
     for raw in range(16):
         control = 1 if raw >> 3 else 0
         valueref = {"control": control, "step_code": raw & 0x07}
         value = DPTControlStepCode.from_knx((raw, ))
         assert value == valueref
Exemplo n.º 3
0
 def __init__(
     self,
     xknx: XKNX,
     group_address: GroupAddressesType | None = None,
     group_address_state: GroupAddressesType | None = None,
     sync_state: bool | int | float | str = True,
     value_type: str | None = None,
     device_name: str | None = None,
     feature_name: str = "Control",
     after_update_cb: AsyncCallbackType | None = None,
 ):
     """Initialize control remote value."""
     if value_type is None:
         raise ConversionError("no value type given",
                               device_name=device_name)
     _dpt_class = DPTControlStepCode.parse_transcoder(value_type)
     if _dpt_class is None:
         raise ConversionError("invalid value type",
                               value_type=value_type,
                               device_name=device_name)
     self.dpt_class: type[DPTControlStepCode] = _dpt_class
     super().__init__(
         xknx,
         group_address,
         group_address_state,
         sync_state=sync_state,
         device_name=device_name,
         feature_name=feature_name,
         after_update_cb=after_update_cb,
     )
Exemplo n.º 4
0
 def test_from_knx_inverted(self):
     """Test parsing DPTControlStepCode types from KNX."""
     for raw in range(16):
         control = 0 if raw >> 3 else 1
         valueref = {"control": control, "step_code": raw & 0x07}
         value = DPTControlStepCode.from_knx(raw, invert=True)
         self.assertEqual(value, valueref)
Exemplo n.º 5
0
 def test_to_knx(self):
     """Test serializing values to DPTControlStepCode."""
     for rawref in range(16):
         control = 1 if rawref >> 3 else 0
         raw = DPTControlStepCode.to_knx(
             {"control": control, "step_code": rawref & 0x07}
         )
         assert raw == (rawref,)
Exemplo n.º 6
0
 def test_to_knx_inverted(self):
     """Test serializing values to DPTControlStepCode in inverted mode."""
     for rawref in range(16):
         control = 0 if rawref >> 3 else 1
         raw = DPTControlStepCode.to_knx(
             {
                 "control": control,
                 "step_code": rawref & 0x07
             }, invert=True)
         self.assertEqual(raw, rawref)
Exemplo n.º 7
0
 def test_from_knx_wrong_value(self):
     """Test parsing invalid DPTControlStepCode type from KNX."""
     with pytest.raises(ConversionError):
         DPTControlStepCode.from_knx((0x1F, ))
Exemplo n.º 8
0
 def test_to_knx_wrong_value_types(self):
     """Test serializing map with keys of invalid type to DPTControlStepCode."""
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"control": ""})
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"step_code": ""})
Exemplo n.º 9
0
 def test_to_knx_wrong_keys(self):
     """Test serializing map with missing keys to DPTControlStepCode."""
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"control": 0})
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx({"step_code": 0})
Exemplo n.º 10
0
 def test_to_knx_wrong_type(self):
     """Test serializing wrong type to DPTControlStepCode."""
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx("")
     with pytest.raises(ConversionError):
         DPTControlStepCode.to_knx(0)