changed relative imports to absolute; renamed TelegramBuffer.put to TelegramBuffer.append;

This commit is contained in:
Nigel Dokter 2017-01-09 20:15:55 +01:00
parent 11672d0512
commit 21334e5a0a
6 changed files with 25 additions and 24 deletions

View File

@ -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():

View File

@ -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__)

View File

@ -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)

View File

@ -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

View File

@ -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
"""

View File

@ -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())