From b7f3af00b98a57ed3908f67846ddbc05116cfb4c Mon Sep 17 00:00:00 2001 From: Nigel Dokter Date: Wed, 15 Feb 2023 13:55:26 +0100 Subject: [PATCH] issue-51-telegram work in progress --- dsmr_parser/objects.py | 8 +++++++- test/objects/test_mbusdevice.py | 11 +++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/dsmr_parser/objects.py b/dsmr_parser/objects.py index a4e4ca6..d2896b8 100644 --- a/dsmr_parser/objects.py +++ b/dsmr_parser/objects.py @@ -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 diff --git a/test/objects/test_mbusdevice.py b/test/objects/test_mbusdevice.py index 4cc20fb..63484dc 100644 --- a/test/objects/test_mbusdevice.py +++ b/test/objects/test_mbusdevice.py @@ -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' + ) + )