issue-51-telegram work in progress

This commit is contained in:
2023-02-08 11:53:08 +01:00
parent ef66c8422c
commit ee2db04ec0
2 changed files with 55 additions and 25 deletions
+31 -17
View File
@@ -321,31 +321,45 @@ class TelegramTest(unittest.TestCase):
assert item_names_tested_set == V4_name_set
def test_len(self):
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(TELEGRAM_V5_TWO_MBUS)
self.assertEqual(len(telegram), 35)
def test_get(self):
""" Retrieve MBUS device without supplying channel which fetches all (two) records found. """
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(TELEGRAM_V5_TWO_MBUS)
mbus_1 = telegram.get(obis.HOURLY_GAS_METER_READING, channel=1)
mbus_2 = telegram.get(obis.HOURLY_GAS_METER_READING, channel=2)
gas_values = telegram.get(obis.HOURLY_GAS_METER_READING)
self.assertEqual(type(mbus_1), MBusObject)
self.assertEqual(mbus_1.channel, 1)
self.assertEqual(mbus_1.value, 0)
self.assertEqual(len(gas_values), 2)
self.assertEqual(type(mbus_2), MBusObject)
self.assertEqual(mbus_2.channel, 2)
self.assertEqual(mbus_2.value, Decimal('246.138'))
gas_value_1 = gas_values[0]
self.assertEqual(type(gas_value_1), MBusObject)
self.assertEqual(gas_value_1.channel, 1)
self.assertEqual(gas_value_1.value, 0)
def test_get_without_channel(self):
""" Retrieve MBUS device without supplying channel which fetches the first MBUS record found """
gas_value_2 = gas_values[1]
self.assertEqual(type(gas_value_2), MBusObject)
self.assertEqual(gas_value_2.channel, 2)
self.assertEqual(gas_value_2.value, Decimal('246.138'))
def test_get_with_channel(self):
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(TELEGRAM_V5_TWO_MBUS)
mbus = telegram.get(obis.HOURLY_GAS_METER_READING)
gas_value_1 = telegram.get(obis.HOURLY_GAS_METER_READING, channel=1)
gas_value_2 = telegram.get(obis.HOURLY_GAS_METER_READING, channel=2)
self.assertEqual(type(mbus), MBusObject)
self.assertEqual(mbus.channel, 1)
self.assertEqual(mbus.value, 0)
self.assertEqual(type(gas_value_1), MBusObject)
self.assertEqual(gas_value_1.channel, 1)
self.assertEqual(gas_value_1.value, 0)
self.assertEqual(type(gas_value_2), MBusObject)
self.assertEqual(gas_value_2.channel, 2)
self.assertEqual(gas_value_2.value, Decimal('246.138'))
def test_get_unknown_value(self):
""" Retrieve MBUS device without supplying channel which fetches the first MBUS record found """
@@ -354,13 +368,13 @@ class TelegramTest(unittest.TestCase):
# Test valid OBIS reference with wrong channel
with self.assertRaises(LookupError) as exception_context:
telegram.get_by_channel(obis.HOURLY_GAS_METER_READING, channel=123)
telegram.get(obis.HOURLY_GAS_METER_READING, channel=123)
self.assertEqual(
str(exception_context.exception),
'No value found for OBIS reference "\d-\d:24\.2\.1.+?\\r\\n" on channel "123"'
'No value found for OBIS reference "\\d-\\d:24\\.2\\.1.+?\\r\\n" on channel "123"'
)
# Test invalid OBIS reference
with self.assertRaises(LookupError):
telegram.get_by_channel('invalid_obis_reference', channel=1)
telegram.get('invalid_obis_reference', channel=1)