diff --git a/dsmr_parser/__main__.py b/dsmr_parser/__main__.py index 8813731..03c9f1d 100644 --- a/dsmr_parser/__main__.py +++ b/dsmr_parser/__main__.py @@ -3,7 +3,7 @@ import asyncio import logging from functools import partial -from .protocol import create_dsmr_reader, create_tcp_dsmr_reader +from dsmr_parser.protocol import create_dsmr_reader, create_tcp_dsmr_reader def console(): diff --git a/dsmr_parser/parsers.py b/dsmr_parser/parsers.py index a215a98..d36cdb6 100644 --- a/dsmr_parser/parsers.py +++ b/dsmr_parser/parsers.py @@ -3,9 +3,9 @@ import re from PyCRC.CRC16 import CRC16 -from .objects import MBusObject, MBusObjectV2_2, CosemObject -from .exceptions import ParseError, InvalidChecksumError -from .obis_references import GAS_METER_READING +from dsmr_parser.objects import MBusObject, MBusObjectV2_2, CosemObject +from dsmr_parser.exceptions import ParseError, InvalidChecksumError +from dsmr_parser.obis_references import GAS_METER_READING logger = logging.getLogger(__name__) diff --git a/dsmr_parser/protocol.py b/dsmr_parser/protocol.py index f31748f..08a8732 100644 --- a/dsmr_parser/protocol.py +++ b/dsmr_parser/protocol.py @@ -6,10 +6,11 @@ from functools import partial from serial_asyncio import create_serial_connection -from . import telegram_specifications -from .exceptions import ParseError -from .parsers import TelegramParserV2_2, TelegramParserV4 -from .serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, TelegramBuffer) +from dsmr_parser import telegram_specifications +from dsmr_parser.exceptions import ParseError +from dsmr_parser.parsers import TelegramParserV2_2, TelegramParserV4 +from dsmr_parser.serial import (SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, + TelegramBuffer) def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None): @@ -79,7 +80,7 @@ class DSMRProtocol(asyncio.Protocol): """Add incoming data to buffer.""" data = data.decode('ascii') self.log.debug('received data: %s', data) - self.telegram_buffer.put(data) + self.telegram_buffer.append(data) for telegram in self.telegram_buffer.get_all(): self.handle_telegram(telegram) diff --git a/dsmr_parser/serial.py b/dsmr_parser/serial.py index 1d92ba8..93e31b9 100644 --- a/dsmr_parser/serial.py +++ b/dsmr_parser/serial.py @@ -59,7 +59,7 @@ class SerialReader(object): with serial.Serial(**self.serial_settings) as serial_handle: while True: data = serial_handle.readline() - self.telegram_buffer.put(data.decode('ascii')) + self.telegram_buffer.append(data.decode('ascii')) for telegram in self.telegram_buffer.get_all(): try: @@ -92,7 +92,7 @@ class AsyncSerialReader(SerialReader): # Read line if available or give control back to loop until new # data has arrived. data = yield from reader.readline() - self.telegram_buffer.put(data.decode('ascii')) + self.telegram_buffer.append(data.decode('ascii')) for telegram in self.telegram_buffer.get_all(): try: @@ -122,7 +122,7 @@ class TelegramBuffer(object): self._remove(telegram) yield telegram - def put(self, data): + def append(self, data): """ Add telegram data to buffer. :param str data: chars, lines or full telegram strings of telegram data diff --git a/dsmr_parser/telegram_specifications.py b/dsmr_parser/telegram_specifications.py index 958153b..adc5e62 100644 --- a/dsmr_parser/telegram_specifications.py +++ b/dsmr_parser/telegram_specifications.py @@ -1,8 +1,8 @@ from decimal import Decimal -from . import obis_references as obis -from .parsers import CosemParser, ValueParser, MBusParser -from .value_types import timestamp +from dsmr_parser import obis_references as obis +from dsmr_parser.parsers import CosemParser, ValueParser, MBusParser +from dsmr_parser.value_types import timestamp """ diff --git a/test/test_telegram_buffer.py b/test/test_telegram_buffer.py index 8bbdcd5..7ad28ee 100644 --- a/test/test_telegram_buffer.py +++ b/test/test_telegram_buffer.py @@ -10,7 +10,7 @@ class TelegramBufferTest(unittest.TestCase): self.telegram_buffer = TelegramBuffer() def test_v22_telegram(self): - self.telegram_buffer.put(TELEGRAM_V2_2) + self.telegram_buffer.append(TELEGRAM_V2_2) telegram = next(self.telegram_buffer.get_all()) @@ -18,7 +18,7 @@ class TelegramBufferTest(unittest.TestCase): self.assertEqual(self.telegram_buffer._buffer, '') def test_v42_telegram(self): - self.telegram_buffer.put(TELEGRAM_V4_2) + self.telegram_buffer.append(TELEGRAM_V4_2) telegram = next(self.telegram_buffer.get_all()) @@ -26,7 +26,7 @@ class TelegramBufferTest(unittest.TestCase): self.assertEqual(self.telegram_buffer._buffer, '') def test_multiple_mixed_telegrams(self): - self.telegram_buffer.put( + self.telegram_buffer.append( ''.join((TELEGRAM_V2_2, TELEGRAM_V4_2, TELEGRAM_V2_2)) ) @@ -47,7 +47,7 @@ class TelegramBufferTest(unittest.TestCase): # There are unclosed telegrams at the start of the buffer. incomplete_telegram = TELEGRAM_V4_2[:-1] - self.telegram_buffer.put(incomplete_telegram + TELEGRAM_V4_2) + self.telegram_buffer.append(incomplete_telegram + TELEGRAM_V4_2) telegram = next(self.telegram_buffer.get_all()) @@ -59,7 +59,7 @@ class TelegramBufferTest(unittest.TestCase): # the buffer was being filled while the telegram was outputted halfway. incomplete_telegram = TELEGRAM_V4_2[1:] - self.telegram_buffer.put(incomplete_telegram + TELEGRAM_V4_2) + self.telegram_buffer.append(incomplete_telegram + TELEGRAM_V4_2) telegram = next(self.telegram_buffer.get_all()) @@ -69,7 +69,7 @@ class TelegramBufferTest(unittest.TestCase): def test_v42_telegram_trailed_by_unclosed_telegram(self): incomplete_telegram = TELEGRAM_V4_2[:-1] - self.telegram_buffer.put(TELEGRAM_V4_2 + incomplete_telegram) + self.telegram_buffer.append(TELEGRAM_V4_2 + incomplete_telegram) telegram = next(self.telegram_buffer.get_all()) @@ -79,7 +79,7 @@ class TelegramBufferTest(unittest.TestCase): def test_v42_telegram_trailed_by_unopened_telegram(self): incomplete_telegram = TELEGRAM_V4_2[1:] - self.telegram_buffer.put(TELEGRAM_V4_2 + incomplete_telegram) + self.telegram_buffer.append(TELEGRAM_V4_2 + incomplete_telegram) telegram = next(self.telegram_buffer.get_all()) @@ -88,7 +88,7 @@ class TelegramBufferTest(unittest.TestCase): def test_v42_telegram_adding_line_by_line(self): for line in TELEGRAM_V4_2.splitlines(keepends=True): - self.telegram_buffer.put(line) + self.telegram_buffer.append(line) telegram = next(self.telegram_buffer.get_all()) @@ -97,7 +97,7 @@ class TelegramBufferTest(unittest.TestCase): def test_v42_telegram_adding_char_by_char(self): for char in TELEGRAM_V4_2: - self.telegram_buffer.put(char) + self.telegram_buffer.append(char) telegram = next(self.telegram_buffer.get_all())