cleaned up based on pylama complaints / pinpointed to coverage version 4.5.4 as next version is incompatible
This commit is contained in:
parent
fee3f696c4
commit
b6537678a7
@ -9,6 +9,7 @@ from dsmr_parser.parsers import TelegramParser
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FileReader(object):
|
class FileReader(object):
|
||||||
"""
|
"""
|
||||||
Filereader to read and parse raw telegram strings from a file and instantiate Telegram objects
|
Filereader to read and parse raw telegram strings from a file and instantiate Telegram objects
|
||||||
@ -60,7 +61,7 @@ class FileReader(object):
|
|||||||
Read complete DSMR telegram's from a file and return a Telegram object.
|
Read complete DSMR telegram's from a file and return a Telegram object.
|
||||||
:rtype: generator
|
:rtype: generator
|
||||||
"""
|
"""
|
||||||
with open(self._file,"rb") as file_handle:
|
with open(self._file, "rb") as file_handle:
|
||||||
while True:
|
while True:
|
||||||
data = file_handle.readline()
|
data = file_handle.readline()
|
||||||
str = data.decode()
|
str = data.decode()
|
||||||
@ -74,6 +75,7 @@ class FileReader(object):
|
|||||||
except ParseError as e:
|
except ParseError as e:
|
||||||
logger.error('Failed to parse telegram: %s', e)
|
logger.error('Failed to parse telegram: %s', e)
|
||||||
|
|
||||||
|
|
||||||
class FileInputReader(object):
|
class FileInputReader(object):
|
||||||
"""
|
"""
|
||||||
Filereader to read and parse raw telegram strings from stdin or files specified at the commandline
|
Filereader to read and parse raw telegram strings from stdin or files specified at the commandline
|
||||||
@ -155,7 +157,7 @@ class FileTailReader(object):
|
|||||||
Read complete DSMR telegram's from a files tail and return a Telegram object.
|
Read complete DSMR telegram's from a files tail and return a Telegram object.
|
||||||
:rtype: generator
|
:rtype: generator
|
||||||
"""
|
"""
|
||||||
with open(self._file,"rb") as file_handle:
|
with open(self._file, "rb") as file_handle:
|
||||||
for data in tailer.follow(file_handle):
|
for data in tailer.follow(file_handle):
|
||||||
str = data.decode()
|
str = data.decode()
|
||||||
self.telegram_buffer.append(str)
|
self.telegram_buffer.append(str)
|
||||||
@ -163,8 +165,7 @@ class FileTailReader(object):
|
|||||||
for telegram in self.telegram_buffer.get_all():
|
for telegram in self.telegram_buffer.get_all():
|
||||||
try:
|
try:
|
||||||
yield Telegram(telegram, self.telegram_parser, self.telegram_specification)
|
yield Telegram(telegram, self.telegram_parser, self.telegram_specification)
|
||||||
except dsmr_parser.exceptions.InvalidChecksumError as e:
|
except InvalidChecksumError as e:
|
||||||
logger.warning(str(e))
|
logger.warning(str(e))
|
||||||
except dsmr_parser.exceptions.ParseError as e:
|
except ParseError as e:
|
||||||
logger.error('Failed to parse telegram: %s', e)
|
logger.error('Failed to parse telegram: %s', e)
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ def create_tcp_dsmr_reader(host, port, dsmr_version,
|
|||||||
conn = loop.create_connection(protocol, host, port)
|
conn = loop.create_connection(protocol, host, port)
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
|
|
||||||
class DSMRProtocol(asyncio.Protocol):
|
class DSMRProtocol(asyncio.Protocol):
|
||||||
"""Assemble and handle incoming data into complete DSM telegrams."""
|
"""Assemble and handle incoming data into complete DSM telegrams."""
|
||||||
|
|
||||||
|
@ -10,45 +10,45 @@ This module contains a mapping of obis references to names.
|
|||||||
EN = {
|
EN = {
|
||||||
obis.P1_MESSAGE_HEADER: 'P1_MESSAGE_HEADER',
|
obis.P1_MESSAGE_HEADER: 'P1_MESSAGE_HEADER',
|
||||||
obis.P1_MESSAGE_TIMESTAMP: 'P1_MESSAGE_TIMESTAMP',
|
obis.P1_MESSAGE_TIMESTAMP: 'P1_MESSAGE_TIMESTAMP',
|
||||||
obis.ELECTRICITY_IMPORTED_TOTAL : 'ELECTRICITY_IMPORTED_TOTAL',
|
obis.ELECTRICITY_IMPORTED_TOTAL: 'ELECTRICITY_IMPORTED_TOTAL',
|
||||||
obis.ELECTRICITY_USED_TARIFF_1 : 'ELECTRICITY_USED_TARIFF_1',
|
obis.ELECTRICITY_USED_TARIFF_1: 'ELECTRICITY_USED_TARIFF_1',
|
||||||
obis.ELECTRICITY_USED_TARIFF_2 : 'ELECTRICITY_USED_TARIFF_2',
|
obis.ELECTRICITY_USED_TARIFF_2: 'ELECTRICITY_USED_TARIFF_2',
|
||||||
obis.ELECTRICITY_DELIVERED_TARIFF_1 : 'ELECTRICITY_DELIVERED_TARIFF_1',
|
obis.ELECTRICITY_DELIVERED_TARIFF_1: 'ELECTRICITY_DELIVERED_TARIFF_1',
|
||||||
obis.ELECTRICITY_DELIVERED_TARIFF_2 : 'ELECTRICITY_DELIVERED_TARIFF_2',
|
obis.ELECTRICITY_DELIVERED_TARIFF_2: 'ELECTRICITY_DELIVERED_TARIFF_2',
|
||||||
obis.ELECTRICITY_ACTIVE_TARIFF : 'ELECTRICITY_ACTIVE_TARIFF',
|
obis.ELECTRICITY_ACTIVE_TARIFF: 'ELECTRICITY_ACTIVE_TARIFF',
|
||||||
obis.EQUIPMENT_IDENTIFIER : 'EQUIPMENT_IDENTIFIER',
|
obis.EQUIPMENT_IDENTIFIER: 'EQUIPMENT_IDENTIFIER',
|
||||||
obis.CURRENT_ELECTRICITY_USAGE : 'CURRENT_ELECTRICITY_USAGE',
|
obis.CURRENT_ELECTRICITY_USAGE: 'CURRENT_ELECTRICITY_USAGE',
|
||||||
obis.CURRENT_ELECTRICITY_DELIVERY : 'CURRENT_ELECTRICITY_DELIVERY',
|
obis.CURRENT_ELECTRICITY_DELIVERY: 'CURRENT_ELECTRICITY_DELIVERY',
|
||||||
obis.LONG_POWER_FAILURE_COUNT : 'LONG_POWER_FAILURE_COUNT',
|
obis.LONG_POWER_FAILURE_COUNT: 'LONG_POWER_FAILURE_COUNT',
|
||||||
obis.SHORT_POWER_FAILURE_COUNT : 'SHORT_POWER_FAILURE_COUNT',
|
obis.SHORT_POWER_FAILURE_COUNT: 'SHORT_POWER_FAILURE_COUNT',
|
||||||
obis.POWER_EVENT_FAILURE_LOG : 'POWER_EVENT_FAILURE_LOG',
|
obis.POWER_EVENT_FAILURE_LOG: 'POWER_EVENT_FAILURE_LOG',
|
||||||
obis.VOLTAGE_SAG_L1_COUNT : 'VOLTAGE_SAG_L1_COUNT',
|
obis.VOLTAGE_SAG_L1_COUNT: 'VOLTAGE_SAG_L1_COUNT',
|
||||||
obis.VOLTAGE_SAG_L2_COUNT : 'VOLTAGE_SAG_L2_COUNT',
|
obis.VOLTAGE_SAG_L2_COUNT: 'VOLTAGE_SAG_L2_COUNT',
|
||||||
obis.VOLTAGE_SAG_L3_COUNT : 'VOLTAGE_SAG_L3_COUNT',
|
obis.VOLTAGE_SAG_L3_COUNT: 'VOLTAGE_SAG_L3_COUNT',
|
||||||
obis.VOLTAGE_SWELL_L1_COUNT : 'VOLTAGE_SWELL_L1_COUNT',
|
obis.VOLTAGE_SWELL_L1_COUNT: 'VOLTAGE_SWELL_L1_COUNT',
|
||||||
obis.VOLTAGE_SWELL_L2_COUNT : 'VOLTAGE_SWELL_L2_COUNT',
|
obis.VOLTAGE_SWELL_L2_COUNT: 'VOLTAGE_SWELL_L2_COUNT',
|
||||||
obis.VOLTAGE_SWELL_L3_COUNT : 'VOLTAGE_SWELL_L3_COUNT',
|
obis.VOLTAGE_SWELL_L3_COUNT: 'VOLTAGE_SWELL_L3_COUNT',
|
||||||
obis.INSTANTANEOUS_VOLTAGE_L1 : 'INSTANTANEOUS_VOLTAGE_L1',
|
obis.INSTANTANEOUS_VOLTAGE_L1: 'INSTANTANEOUS_VOLTAGE_L1',
|
||||||
obis.INSTANTANEOUS_VOLTAGE_L2 : 'INSTANTANEOUS_VOLTAGE_L2',
|
obis.INSTANTANEOUS_VOLTAGE_L2: 'INSTANTANEOUS_VOLTAGE_L2',
|
||||||
obis.INSTANTANEOUS_VOLTAGE_L3 : 'INSTANTANEOUS_VOLTAGE_L3',
|
obis.INSTANTANEOUS_VOLTAGE_L3: 'INSTANTANEOUS_VOLTAGE_L3',
|
||||||
obis.INSTANTANEOUS_CURRENT_L1 : 'INSTANTANEOUS_CURRENT_L1',
|
obis.INSTANTANEOUS_CURRENT_L1: 'INSTANTANEOUS_CURRENT_L1',
|
||||||
obis.INSTANTANEOUS_CURRENT_L2 : 'INSTANTANEOUS_CURRENT_L2',
|
obis.INSTANTANEOUS_CURRENT_L2: 'INSTANTANEOUS_CURRENT_L2',
|
||||||
obis.INSTANTANEOUS_CURRENT_L3 : 'INSTANTANEOUS_CURRENT_L3',
|
obis.INSTANTANEOUS_CURRENT_L3: 'INSTANTANEOUS_CURRENT_L3',
|
||||||
obis.TEXT_MESSAGE_CODE : 'TEXT_MESSAGE_CODE',
|
obis.TEXT_MESSAGE_CODE: 'TEXT_MESSAGE_CODE',
|
||||||
obis.TEXT_MESSAGE : 'TEXT_MESSAGE',
|
obis.TEXT_MESSAGE: 'TEXT_MESSAGE',
|
||||||
obis.DEVICE_TYPE : 'DEVICE_TYPE',
|
obis.DEVICE_TYPE: 'DEVICE_TYPE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE : 'INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: 'INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE : 'INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: 'INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE : 'INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: 'INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE : 'INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: 'INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE : 'INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: 'INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE',
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE : 'INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE',
|
obis.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: 'INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE',
|
||||||
obis.EQUIPMENT_IDENTIFIER_GAS : 'EQUIPMENT_IDENTIFIER_GAS',
|
obis.EQUIPMENT_IDENTIFIER_GAS: 'EQUIPMENT_IDENTIFIER_GAS',
|
||||||
obis.HOURLY_GAS_METER_READING : 'HOURLY_GAS_METER_READING',
|
obis.HOURLY_GAS_METER_READING: 'HOURLY_GAS_METER_READING',
|
||||||
obis.GAS_METER_READING : 'GAS_METER_READING',
|
obis.GAS_METER_READING: 'GAS_METER_READING',
|
||||||
obis.ACTUAL_TRESHOLD_ELECTRICITY : 'ACTUAL_TRESHOLD_ELECTRICITY',
|
obis.ACTUAL_TRESHOLD_ELECTRICITY: 'ACTUAL_TRESHOLD_ELECTRICITY',
|
||||||
obis.ACTUAL_SWITCH_POSITION : 'ACTUAL_SWITCH_POSITION',
|
obis.ACTUAL_SWITCH_POSITION: 'ACTUAL_SWITCH_POSITION',
|
||||||
obis.VALVE_POSITION_GAS : 'VALVE_POSITION_GAS'
|
obis.VALVE_POSITION_GAS: 'VALVE_POSITION_GAS'
|
||||||
}
|
}
|
||||||
|
|
||||||
REVERSE_EN = dict([ (v,k) for k,v in EN.items()])
|
REVERSE_EN = dict([(v, k) for k, v in EN.items()])
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import dsmr_parser.obis_name_mapping
|
import dsmr_parser.obis_name_mapping
|
||||||
|
|
||||||
|
|
||||||
class Telegram(object):
|
class Telegram(object):
|
||||||
"""
|
"""
|
||||||
Container for raw and parsed telegram data.
|
Container for raw and parsed telegram data.
|
||||||
@ -47,7 +48,7 @@ class Telegram(object):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
output = ""
|
output = ""
|
||||||
for attr, value in self:
|
for attr, value in self:
|
||||||
output += "{}: \t {} \t[{}]\n".format(attr,str(value.value),str(value.unit))
|
output += "{}: \t {} \t[{}]\n".format(attr, str(value.value), str(value.unit))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import re
|
|||||||
|
|
||||||
from ctypes import c_ushort
|
from ctypes import c_ushort
|
||||||
|
|
||||||
from dsmr_parser.objects import MBusObject, CosemObject, Telegram
|
from dsmr_parser.objects import MBusObject, CosemObject
|
||||||
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
from decimal import Decimal
|
|
||||||
import datetime
|
|
||||||
import unittest
|
|
||||||
import pytz
|
|
||||||
from dsmr_parser import obis_references as obis
|
|
||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.exceptions import InvalidChecksumError, ParseError
|
from dsmr_parser.objects import Telegram
|
||||||
from dsmr_parser.objects import CosemObject, MBusObject, Telegram
|
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
from example_telegrams import TELEGRAM_V4_2
|
from example_telegrams import TELEGRAM_V4_2
|
||||||
parser = TelegramParser(telegram_specifications.V4)
|
parser = TelegramParser(telegram_specifications.V4)
|
||||||
telegram = Telegram(TELEGRAM_V4_2, parser, telegram_specifications.V4)
|
telegram = Telegram(TELEGRAM_V4_2, parser, telegram_specifications.V4)
|
||||||
|
|
||||||
print(telegram)
|
print(telegram)
|
||||||
|
@ -1,30 +1,21 @@
|
|||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
import datetime
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pytz
|
|
||||||
|
|
||||||
from dsmr_parser import obis_references as obis
|
|
||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.exceptions import InvalidChecksumError, ParseError
|
from dsmr_parser.objects import CosemObject
|
||||||
from dsmr_parser.objects import CosemObject, MBusObject, Telegram
|
from dsmr_parser.objects import Telegram
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
from test.example_telegrams import TELEGRAM_V4_2
|
from test.example_telegrams import TELEGRAM_V4_2
|
||||||
|
|
||||||
|
|
||||||
class TelegramTest(unittest.TestCase):
|
class TelegramTest(unittest.TestCase):
|
||||||
""" Test instantiation of Telegram object """
|
""" Test instantiation of Telegram object """
|
||||||
|
|
||||||
def test_instantiate(self):
|
def test_instantiate(self):
|
||||||
parser = TelegramParser(telegram_specifications.V4)
|
parser = TelegramParser(telegram_specifications.V4)
|
||||||
#result = parser.parse(TELEGRAM_V4_2)
|
|
||||||
telegram = Telegram(TELEGRAM_V4_2, parser, telegram_specifications.V4)
|
telegram = Telegram(TELEGRAM_V4_2, parser, telegram_specifications.V4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# P1_MESSAGE_HEADER (1-3:0.2.8)
|
# P1_MESSAGE_HEADER (1-3:0.2.8)
|
||||||
#assert isinstance(result[obis.P1_MESSAGE_HEADER], CosemObject)
|
testitem = telegram.P1_MESSAGE_HEADER
|
||||||
#assert result[obis.P1_MESSAGE_HEADER].unit is None
|
assert isinstance(testitem, CosemObject)
|
||||||
#assert isinstance(result[obis.P1_MESSAGE_HEADER].value, str)
|
assert testitem.unit is None
|
||||||
#assert result[obis.P1_MESSAGE_HEADER].value == '50'
|
assert testitem.value == '42'
|
||||||
|
12
tox.ini
12
tox.ini
@ -1,5 +1,6 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py34,py35,p36
|
envlist = py34,py35,py36,py37
|
||||||
|
requires = coverage<=4.5.4
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
deps=
|
deps=
|
||||||
@ -14,10 +15,13 @@ commands=
|
|||||||
pylama dsmr_parser test
|
pylama dsmr_parser test
|
||||||
|
|
||||||
[pylama:dsmr_parser/clients/__init__.py]
|
[pylama:dsmr_parser/clients/__init__.py]
|
||||||
ignore = W0611,W0605
|
ignore = W0611
|
||||||
|
|
||||||
|
[pylama:dsmr_parser/parsers.py]
|
||||||
|
ignore = W605
|
||||||
|
|
||||||
[pylama:pylint]
|
[pylama:pylint]
|
||||||
max_line_length = 100
|
max_line_length = 120
|
||||||
|
|
||||||
[pylama:pycodestyle]
|
[pylama:pycodestyle]
|
||||||
max_line_length = 100
|
max_line_length = 120
|
||||||
|
Loading…
Reference in New Issue
Block a user