ProfileGeneric parser working, ProfileGenericObject implemented and Test for V4 telegram completed.
This commit is contained in:
parent
b6278a8991
commit
789871899c
@ -112,6 +112,41 @@ class CosemObject(DSMRObject):
|
||||
|
||||
|
||||
class ProfileGenericObject(DSMRObject):
|
||||
"""
|
||||
Represents all data in a GenericProfile value.
|
||||
All buffer values are returned as a list of MBusObjects,
|
||||
containing the datetime (timestamp) and the value.
|
||||
"""
|
||||
|
||||
def __init__(self, values):
|
||||
super().__init__(values)
|
||||
self._buffer_list = None
|
||||
|
||||
@property
|
||||
def buffer_length(self):
|
||||
return self.values[0]['value']
|
||||
|
||||
@property
|
||||
def buffer_type(self):
|
||||
return self.values[1]['value']
|
||||
|
||||
@property
|
||||
def buffer(self):
|
||||
if self._buffer_list is None:
|
||||
self._buffer_list = []
|
||||
values_offset = 2
|
||||
for i in range(self.buffer_length):
|
||||
offset = values_offset + i*2
|
||||
self._buffer_list.append(MBusObject([self.values[offset], self.values[offset + 1]]))
|
||||
return self._buffer_list
|
||||
|
||||
def __str__(self):
|
||||
output = "{}".format(self.values)
|
||||
output = "\t buffer length: {}\n".format(self.buffer_length)
|
||||
output += "\t buffer type: {}".format(self.buffer_type)
|
||||
for buffer_value in self.buffer:
|
||||
timestamp = buffer_value.datetime
|
||||
if isinstance(timestamp, datetime.datetime):
|
||||
timestamp = str(timestamp.astimezone().isoformat())
|
||||
output += "\n\t event occured at: {}".format(timestamp)
|
||||
output += "\t for: {} [{}]".format(buffer_value.value, buffer_value.unit)
|
||||
return output
|
||||
|
@ -107,7 +107,10 @@ V5 = {
|
||||
obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
|
||||
obis.LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
|
||||
obis.SHORT_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
|
||||
# POWER_EVENT_FAILURE_LOG: ProfileGenericParser(), TODO
|
||||
obis.POWER_EVENT_FAILURE_LOG:
|
||||
ProfileGenericParser(BUFFER_TYPES,
|
||||
PG_HEAD_PARSERS,
|
||||
PG_UNIDENTIFIED_BUFFERTYPE_PARSERS),
|
||||
obis.VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)),
|
||||
obis.VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)),
|
||||
obis.VOLTAGE_SAG_L3_COUNT: CosemParser(ValueParser(int)),
|
||||
|
@ -287,14 +287,30 @@ class TelegramTest(unittest.TestCase):
|
||||
unit_val='m3',
|
||||
value_type=Decimal,
|
||||
value_val=Decimal('981.443'))
|
||||
|
||||
# POWER_EVENT_FAILURE_LOG (1-0:99.97.0)
|
||||
testitem_name = 'POWER_EVENT_FAILURE_LOG'
|
||||
object_type = ProfileGenericObject
|
||||
testitem = eval("telegram.{}".format(testitem_name))
|
||||
assert isinstance(testitem, object_type)
|
||||
# assert testitem.unit == unit_val
|
||||
# assert isinstance(testitem.value, value_type)
|
||||
# assert testitem.value == value_val
|
||||
assert testitem.buffer_length == 3
|
||||
assert testitem.buffer_type == '0-0:96.7.19'
|
||||
buffer = testitem.buffer
|
||||
assert isinstance(testitem.buffer, list)
|
||||
assert len(buffer) == 3
|
||||
assert all([isinstance(item, MBusObject) for item in buffer])
|
||||
date0 = datetime.datetime(2000, 1, 4, 17, 3, 20, tzinfo=datetime.timezone.utc)
|
||||
date1 = datetime.datetime(1999, 12, 31, 23, 0, 1, tzinfo=datetime.timezone.utc)
|
||||
date2 = datetime.datetime(2000, 1, 1, 23, 0, 3, tzinfo=datetime.timezone.utc)
|
||||
assert buffer[0].datetime == date0
|
||||
assert buffer[1].datetime == date1
|
||||
assert buffer[2].datetime == date2
|
||||
assert buffer[0].value == 237126
|
||||
assert buffer[1].value == 2147583646
|
||||
assert buffer[2].value == 2317482647
|
||||
assert all([isinstance(item.value, int) for item in buffer])
|
||||
assert all([isinstance(item.unit, str) for item in buffer])
|
||||
assert all([(item.unit == 's') for item in buffer])
|
||||
self.item_names_tested.append(testitem_name)
|
||||
|
||||
# check if all items in telegram V4 specification are covered
|
||||
|
Loading…
Reference in New Issue
Block a user