From d6e28db116d4394cd80a70cec15ad2e532af0ae9 Mon Sep 17 00:00:00 2001
From: Nigel Dokter <nigeldokter@gmail.com>
Date: Mon, 5 Jun 2017 21:02:59 +0200
Subject: [PATCH] log checksum errors as warning; dont force full telegram
 signatures; removed unused code for automatic telegram version detection;

---
 CHANGELOG.rst                             |  6 +++++
 dsmr_parser/clients/protocol.py           |  2 ++
 dsmr_parser/clients/serial_.py            |  2 ++
 dsmr_parser/parsers.py                    | 32 +++--------------------
 setup.py                                  |  2 +-
 test/test_match_telegram_specification.py | 24 -----------------
 6 files changed, 15 insertions(+), 53 deletions(-)
 delete mode 100644 test/test_match_telegram_specification.py

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 3617fb4..0da194d 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,6 +1,12 @@
 Change Log
 ----------
 
+**0.10** (2017-06-05)
+
+- bugix: don't force full telegram signatures (`pull request #25 <https://github.com/ndokter/dsmr_parser/pull/25>`_)
+- removed unused code for automatic telegram detection as this needs reworking after the fix mentioned above
+- InvalidChecksumError's are logged as warning instead of error
+
 **0.9** (2017-05-12)
 
 - added DSMR v5 serial settings
diff --git a/dsmr_parser/clients/protocol.py b/dsmr_parser/clients/protocol.py
index d63a3fc..68f2434 100644
--- a/dsmr_parser/clients/protocol.py
+++ b/dsmr_parser/clients/protocol.py
@@ -101,6 +101,8 @@ class DSMRProtocol(asyncio.Protocol):
 
         try:
             parsed_telegram = self.telegram_parser.parse(telegram)
+        except InvalidChecksumError as e:
+            self.log.warning(str(e))
         except ParseError:
             self.log.exception("failed to parse telegram")
         else:
diff --git a/dsmr_parser/clients/serial_.py b/dsmr_parser/clients/serial_.py
index d69cac3..ddc0a14 100644
--- a/dsmr_parser/clients/serial_.py
+++ b/dsmr_parser/clients/serial_.py
@@ -36,6 +36,8 @@ class SerialReader(object):
                 for telegram in self.telegram_buffer.get_all():
                     try:
                         yield self.telegram_parser.parse(telegram)
+                    except InvalidChecksumError as e:
+                        logger.warning(str(e))
                     except ParseError as e:
                         logger.error('Failed to parse telegram: %s', e)
 
diff --git a/dsmr_parser/parsers.py b/dsmr_parser/parsers.py
index c38dcf0..087d9e0 100644
--- a/dsmr_parser/parsers.py
+++ b/dsmr_parser/parsers.py
@@ -92,31 +92,6 @@ class TelegramParser(object):
             )
 
 
-def match_telegram_specification(telegram_data):
-    """
-    Find telegram specification that matches the telegram data by trying all
-    specifications.
-
-    Could be further optimized to check the actual 0.2.8 OBIS reference which
-    is available for DSMR version 4 and up.
-
-    :param str telegram_data: full telegram from start ('/') to checksum
-            ('!ABCD') including line endings in between the telegram's lines
-    :return: telegram specification
-    :rtype: dict
-    """
-    # Prevent circular import
-    from dsmr_parser import telegram_specifications
-
-    for specification in telegram_specifications.ALL:
-        try:
-            TelegramParser(specification).parse(telegram_data)
-        except ParseError:
-            pass
-        else:
-            return specification
-
-
 class DSMRObjectParser(object):
     """
     Parses an object (can also be see as a 'line') from a telegram.
@@ -174,10 +149,11 @@ class CosemParser(DSMRObjectParser):
     1  23  45
 
     1) OBIS Reduced ID-code
-    2) Separator “(“, ASCII 28h
+    2) Separator "(", ASCII 28h
     3) COSEM object attribute value
-    4) Unit of measurement values (Unit of capture objects attribute) – only if applicable
-    5) Separator “)”, ASCII 29h
+    4) Unit of measurement values (Unit of capture objects attribute) - only if
+       applicable
+    5) Separator ")", ASCII 29h
     """
 
     def parse(self, line):
diff --git a/setup.py b/setup.py
index b8dc651..176233c 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@ setup(
     author='Nigel Dokter',
     author_email='nigeldokter@gmail.com',
     url='https://github.com/ndokter/dsmr_parser',
-    version='0.9',
+    version='0.10',
     packages=find_packages(),
     install_requires=[
         'pyserial>=3,<4',
diff --git a/test/test_match_telegram_specification.py b/test/test_match_telegram_specification.py
deleted file mode 100644
index 357495a..0000000
--- a/test/test_match_telegram_specification.py
+++ /dev/null
@@ -1,24 +0,0 @@
-import unittest
-
-from dsmr_parser.parsers import match_telegram_specification
-from dsmr_parser import telegram_specifications
-from test import example_telegrams
-
-
-class MatchTelegramSpecificationTest(unittest.TestCase):
-
-    def test_v2_2(self):
-        assert match_telegram_specification(example_telegrams.TELEGRAM_V2_2) \
-           == telegram_specifications.V2_2
-
-    def test_v3(self):
-        assert match_telegram_specification(example_telegrams.TELEGRAM_V3) \
-           == telegram_specifications.V3
-
-    def test_v4_2(self):
-        assert match_telegram_specification(example_telegrams.TELEGRAM_V4_2) \
-           == telegram_specifications.V4
-
-    def test_v5(self):
-        assert match_telegram_specification(example_telegrams.TELEGRAM_V5) \
-           == telegram_specifications.V5