def from_knx(self, payload): """Convert current payload to value.""" # if self.datetime_type == DateTimeType.DATETIME: # datetime_data = DPTDateTime.from_knx(payload.value) if self.datetime_type == DateTimeType.DATE: datetime_data = DPTDate.from_knx(payload.value) elif self.datetime_type == DateTimeType.TIME: datetime_data = DPTTime.from_knx(payload.value) return datetime_data
def test_from_knx_wrong_type(self): """Test parsing from DPTTime object from wrong binary values (wrong type).""" with pytest.raises(ConversionError): DPTTime.from_knx((0xF8, "0x23"))
def test_from_knx_wrong_bytes(self): """Test parsing from DPTTime object from wrong binary values (wrong bytes).""" with pytest.raises(ConversionError): # this parameter exceeds limit DPTTime.from_knx((0xF7, 0x3B, 0x3C))
def test_from_knx_min(self): """Test parsing of DPTTime object from binary values. Example 3.""" assert DPTTime.from_knx((0x0, 0x0, 0x0)) == time.strptime("0 0 0", "%H %M %S")
def test_from_knx_max(self): """Test parsing of DPTTime object from binary values. Example 2.""" assert DPTTime.from_knx((0xF7, 0x3B, 0x3B)) == time.strptime( "23 59 59 0", "%H %M %S %w" )
def test_from_knx(self): """Test parsing of DPTTime object from binary values. Example 1.""" assert DPTTime.from_knx((0x4D, 0x17, 0x2A)) == time.strptime( "13 23 42 2", "%H %M %S %w" )