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_range_year(self): """Test Exception when parsing DPTDate from KNX with wrong year.""" with pytest.raises(ConversionError): DPTDate.from_knx((0x04, 0x01, 0x64))
def test_from_knx_wrong_range_month(self): """Test Exception when parsing DPTDAte from KNX with wrong month.""" with pytest.raises(ConversionError): DPTDate.from_knx((0x04, 0x00, 0x59))
def test_from_knx_wrong_parameter(self): """Test parsing from DPTDate object from wrong binary values.""" with pytest.raises(ConversionError): DPTDate.from_knx((0xF8, 0x23))
def test_from_knx_future_date(self): """Test parsing of DPTDate object from binary values. Example 3.""" assert DPTDate.from_knx((0x04, 0x0C, 0x59)) == time.strptime( "2089-12-4", "%Y-%m-%d" )
def test_from_knx_old_date(self): """Test parsing of DPTDate object from binary values. Example 2.""" assert DPTDate.from_knx((0x1F, 0x01, 0x5A)) == time.strptime( "1990-01-31", "%Y-%m-%d" )
def test_from_knx(self): """Test parsing of DPTDate object from binary values. Example 1.""" assert DPTDate.from_knx((0x04, 0x01, 0x02)) == time.strptime( "2002-01-04", "%Y-%m-%d" )