Skip to content

Commit

Permalink
sml: Create a decoding method for OBIS
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdcr committed May 19, 2023
1 parent afdf9f9 commit bfe28af
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def __init__(self, fields: tuple, values: list) -> None:
if self[key] == b'':
del self[key]

@staticmethod
def decode_obis(value: bytes) -> str:
return '%d-%d:%d.%d.%d*%d' % (
value[0], value[1], value[2], value[3], value[4], value[5]
)

@staticmethod
def decode_server_id(value: bytes) -> str:
if value[0] in (9, 10) and len(value) == 10:
Expand Down Expand Up @@ -273,9 +279,7 @@ def __init__(self, values: list) -> None:

name = self.get('objName')
if name and len(name) == 6:
self['objName'] = '%d-%d:%d.%d.%d*%d' % (
name[0], name[1], name[2], name[3], name[4], name[5]
)
self['objName'] = self.decode_obis(self['objName'])

unit = self.get('unit')
if unit:
Expand Down

0 comments on commit bfe28af

Please sign in to comment.