issue-51-telegram work in progress

This commit is contained in:
Nigel Dokter 2023-02-15 13:55:26 +01:00
parent ad25fd4182
commit b7f3af00b9
2 changed files with 18 additions and 1 deletions

View File

@ -93,6 +93,12 @@ class Telegram(object):
output = ""
for attr, value in self:
output += "{}: \t {}\n".format(attr, str(value))
for channel_id, mbus_device in self._mbus_channel_devices.items():
output += f'MBUS DEVICE (channel: {channel_id})\n'
for obis_name, value in mbus_device:
output += f'\t{obis_name}: \t {value} \n'
return output
def to_json(self):
@ -348,7 +354,7 @@ class MbusDevice:
yield attr, value
def __str__(self):
output = ""
output = "CHANNEL_ID: \t {}\n".format(self.channel_id)
for attr, value in self:
output += "{}: \t {}\n".format(attr, str(value))
return output

View File

@ -48,3 +48,14 @@ class MbusDeviceTest(unittest.TestCase):
'EQUIPMENT_IDENTIFIER_GAS': {'value': '4730303339303031393336393930363139', 'unit': None},
'HOURLY_GAS_METER_READING': {'datetime': '2020-04-26T22:30:01+02:00', 'value': 246.138, 'unit': 'm3'}}
)
def test_str(self):
self.assertEqual(
str(self.mbus_device),
(
'CHANNEL_ID: 1\n'
'DEVICE_TYPE: 3 [None]\n'
'EQUIPMENT_IDENTIFIER_GAS: 4730303339303031393336393930363139 [None]\n'
'HOURLY_GAS_METER_READING: 246.138 [m3] at 2020-04-26T22:30:01+02:00\n'
)
)