Compare commits
4
Commits
development
..
v0.9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9b0a85e84b | ||
|
|
1dca6ab396 | ||
|
|
efc09df71f | ||
|
|
de5c884d8d |
+2
-2
@@ -1,9 +1,9 @@
|
||||
Change Log
|
||||
----------
|
||||
|
||||
**0.9** (2017-03-02)
|
||||
**0.9** (2017-05-12)
|
||||
|
||||
- allow the telegram specification to optionally be autodetected
|
||||
- added DSMR v5 serial settings
|
||||
|
||||
**0.8** (2017-01-26)
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ into a dictionary.
|
||||
from dsmr_parser import telegram_specifications
|
||||
from dsmr_parser.parsers import TelegramParser
|
||||
|
||||
# String is formatted in separate lines for readability.
|
||||
telegram_str = (
|
||||
'/ISk5\2MT382-1000\r\n'
|
||||
'\r\n'
|
||||
|
||||
@@ -23,6 +23,9 @@ def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
||||
elif dsmr_version == '4':
|
||||
specification = telegram_specifications.V4
|
||||
serial_settings = SERIAL_SETTINGS_V4
|
||||
elif dsmr_version == '5':
|
||||
specification = telegram_specifications.V5
|
||||
serial_settings = SERIAL_SETTINGS_V4
|
||||
else:
|
||||
raise NotImplementedError("No telegram parser found for version: %s",
|
||||
dsmr_version)
|
||||
|
||||
@@ -4,7 +4,3 @@ class ParseError(Exception):
|
||||
|
||||
class InvalidChecksumError(ParseError):
|
||||
pass
|
||||
|
||||
|
||||
class TelegramSpecificationMatchError(ParseError):
|
||||
pass
|
||||
|
||||
+4
-13
@@ -4,18 +4,16 @@ import re
|
||||
from PyCRC.CRC16 import CRC16
|
||||
|
||||
from dsmr_parser.objects import MBusObject, CosemObject
|
||||
from dsmr_parser.exceptions import ParseError, InvalidChecksumError, \
|
||||
TelegramSpecificationMatchError
|
||||
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TelegramParser(object):
|
||||
|
||||
def __init__(self, telegram_specification=None, apply_checksum_validation=True):
|
||||
def __init__(self, telegram_specification, apply_checksum_validation=True):
|
||||
"""
|
||||
:param telegram_specification: determines how the telegram is parsed.
|
||||
Will attempt to autodetect if omitted.
|
||||
:param telegram_specification: determines how the telegram is parsed
|
||||
:param apply_checksum_validation: validate checksum if applicable for
|
||||
telegram DSMR version (v4 and up).
|
||||
:type telegram_specification: dict
|
||||
@@ -41,10 +39,8 @@ class TelegramParser(object):
|
||||
..
|
||||
}
|
||||
:raises ParseError:
|
||||
:raises InvalidChecksumError:
|
||||
"""
|
||||
if not self.telegram_specification:
|
||||
self.telegram_specification = \
|
||||
match_telegram_specification(telegram_data)
|
||||
|
||||
if self.apply_checksum_validation \
|
||||
and self.telegram_specification['checksum_support']:
|
||||
@@ -122,11 +118,6 @@ def match_telegram_specification(telegram_data):
|
||||
else:
|
||||
return specification
|
||||
|
||||
raise TelegramSpecificationMatchError(
|
||||
'Could automatically match telegram specification. Make sure the data'
|
||||
'is not corrupt. Alternatively manually specify one.'
|
||||
)
|
||||
|
||||
|
||||
class DSMRObjectParser(object):
|
||||
"""
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import unittest
|
||||
|
||||
from dsmr_parser.exceptions import TelegramSpecificationMatchError
|
||||
from dsmr_parser.parsers import match_telegram_specification
|
||||
from dsmr_parser import telegram_specifications
|
||||
from test import example_telegrams
|
||||
@@ -23,7 +22,3 @@ class MatchTelegramSpecificationTest(unittest.TestCase):
|
||||
def test_v5(self):
|
||||
assert match_telegram_specification(example_telegrams.TELEGRAM_V5) \
|
||||
== telegram_specifications.V5
|
||||
|
||||
def test_malformed_telegram(self):
|
||||
with self.assertRaises(TelegramSpecificationMatchError):
|
||||
match_telegram_specification(example_telegrams.TELEGRAM_V5[:-4])
|
||||
|
||||
@@ -12,15 +12,6 @@ from test.example_telegrams import TELEGRAM_V2_2
|
||||
class TelegramParserV2_2Test(unittest.TestCase):
|
||||
""" Test parsing of a DSMR v2.2 telegram. """
|
||||
|
||||
def test_telegram_specification_matching(self):
|
||||
parser = TelegramParser()
|
||||
parser.parse(TELEGRAM_V2_2)
|
||||
|
||||
self.assertEqual(
|
||||
parser.telegram_specification,
|
||||
telegram_specifications.V2_2
|
||||
)
|
||||
|
||||
def test_parse(self):
|
||||
parser = TelegramParser(telegram_specifications.V2_2)
|
||||
result = parser.parse(TELEGRAM_V2_2)
|
||||
|
||||
@@ -12,15 +12,6 @@ from test.example_telegrams import TELEGRAM_V3
|
||||
class TelegramParserV3Test(unittest.TestCase):
|
||||
""" Test parsing of a DSMR v3 telegram. """
|
||||
|
||||
def test_telegram_specification_matching(self):
|
||||
parser = TelegramParser()
|
||||
parser.parse(TELEGRAM_V3)
|
||||
|
||||
self.assertEqual(
|
||||
parser.telegram_specification,
|
||||
telegram_specifications.V3
|
||||
)
|
||||
|
||||
def test_parse(self):
|
||||
parser = TelegramParser(telegram_specifications.V3)
|
||||
result = parser.parse(TELEGRAM_V3)
|
||||
|
||||
@@ -15,15 +15,6 @@ from test.example_telegrams import TELEGRAM_V4_2
|
||||
class TelegramParserV4_2Test(unittest.TestCase):
|
||||
""" Test parsing of a DSMR v4.2 telegram. """
|
||||
|
||||
def test_telegram_specification_matching(self):
|
||||
parser = TelegramParser()
|
||||
parser.parse(TELEGRAM_V4_2)
|
||||
|
||||
self.assertEqual(
|
||||
parser.telegram_specification,
|
||||
telegram_specifications.V4
|
||||
)
|
||||
|
||||
def test_parse(self):
|
||||
parser = TelegramParser(telegram_specifications.V4)
|
||||
result = parser.parse(TELEGRAM_V4_2)
|
||||
|
||||
@@ -16,15 +16,6 @@ from test.example_telegrams import TELEGRAM_V5
|
||||
class TelegramParserV5Test(unittest.TestCase):
|
||||
""" Test parsing of a DSMR v5.x telegram. """
|
||||
|
||||
def test_telegram_specification_matching(self):
|
||||
parser = TelegramParser()
|
||||
parser.parse(TELEGRAM_V5)
|
||||
|
||||
self.assertEqual(
|
||||
parser.telegram_specification,
|
||||
telegram_specifications.V5
|
||||
)
|
||||
|
||||
def test_parse(self):
|
||||
parser = TelegramParser(telegram_specifications.V5)
|
||||
result = parser.parse(TELEGRAM_V5)
|
||||
|
||||
Reference in New Issue
Block a user