diff --git a/.gitignore b/.gitignore index c10666e..a66f5e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea *.pyc +.tox +.cache diff --git a/dsmr_parser/__main__.py b/dsmr_parser/__main__.py index b3e127c..92c0dce 100644 --- a/dsmr_parser/__main__.py +++ b/dsmr_parser/__main__.py @@ -1,7 +1,7 @@ import argparse from dsmr_parser.serial import SERIAL_SETTINGS_V2_2, SERIAL_SETTINGS_V4, SerialReader from dsmr_parser import telegram_specifications -from dsmr_parser.obis_references import P1_MESSAGE_TIMESTAMP + def console(): """Output DSMR data to console.""" @@ -14,8 +14,6 @@ def console(): args = parser.parse_args() - version = 'V' + args.version.replace('.', '_') - settings = { '2.2': (SERIAL_SETTINGS_V2_2, telegram_specifications.V2_2), '4': (SERIAL_SETTINGS_V4, telegram_specifications.V4), @@ -32,4 +30,3 @@ def console(): if obj: print(obj.value, obj.unit) print() - diff --git a/dsmr_parser/serial.py b/dsmr_parser/serial.py index a4726c6..faa6d94 100644 --- a/dsmr_parser/serial.py +++ b/dsmr_parser/serial.py @@ -62,4 +62,3 @@ class SerialReader(object): if is_end_of_telegram(line): yield self.telegram_parser.parse(telegram) telegram = [] - diff --git a/dsmr_parser/telegram_specifications.py b/dsmr_parser/telegram_specifications.py index b6f5071..958153b 100644 --- a/dsmr_parser/telegram_specifications.py +++ b/dsmr_parser/telegram_specifications.py @@ -1,6 +1,6 @@ from decimal import Decimal -from .obis_references import * +from . import obis_references as obis from .parsers import CosemParser, ValueParser, MBusParser from .value_types import timestamp @@ -14,53 +14,60 @@ how the telegram lines are parsed. """ V2_2 = { - EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), - ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)), - ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)), - ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)), - ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)), - ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)), - CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)), - CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)), - ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)), - ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)), - TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)), - TEXT_MESSAGE: CosemParser(ValueParser(str)), - EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)), - DEVICE_TYPE: CosemParser(ValueParser(str)), - VALVE_POSITION_GAS: CosemParser(ValueParser(str)), + obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), + obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)), + obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)), + obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)), + obis.ACTUAL_TRESHOLD_ELECTRICITY: CosemParser(ValueParser(Decimal)), + obis.ACTUAL_SWITCH_POSITION: CosemParser(ValueParser(str)), + obis.TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)), + obis.TEXT_MESSAGE: CosemParser(ValueParser(str)), + obis.EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)), + obis.DEVICE_TYPE: CosemParser(ValueParser(str)), + obis.VALVE_POSITION_GAS: CosemParser(ValueParser(str)), + obis.GAS_METER_READING: MBusParser( + ValueParser(timestamp), + ValueParser(int), + ValueParser(int), + ValueParser(int), + ValueParser(str), + ValueParser(Decimal), + ), } V4 = { - P1_MESSAGE_HEADER: CosemParser(ValueParser(str)), - P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)), - ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)), - ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)), - ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)), - ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)), - ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)), - EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), - CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)), - CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)), - LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)), + obis.P1_MESSAGE_HEADER: CosemParser(ValueParser(str)), + obis.P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)), + obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_DELIVERED_TARIFF_2: CosemParser(ValueParser(Decimal)), + obis.ELECTRICITY_ACTIVE_TARIFF: CosemParser(ValueParser(str)), + obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)), + obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)), + obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)), + obis.LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)), # POWER_EVENT_FAILURE_LOG: ProfileGenericParser(), TODO - VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)), - VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)), - VOLTAGE_SAG_L3_COUNT: CosemParser(ValueParser(int)), - VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)), - VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)), - VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)), - TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)), - TEXT_MESSAGE: CosemParser(ValueParser(str)), - DEVICE_TYPE: CosemParser(ValueParser(int)), - INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)), - INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: CosemParser(ValueParser(Decimal)), - INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: CosemParser(ValueParser(Decimal)), - INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: CosemParser(ValueParser(Decimal)), - INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: CosemParser(ValueParser(Decimal)), - INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: CosemParser(ValueParser(Decimal)), - EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)), - HOURLY_GAS_METER_READING: MBusParser(ValueParser(timestamp), - ValueParser(Decimal)) + obis.VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)), + obis.VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)), + obis.VOLTAGE_SAG_L3_COUNT: CosemParser(ValueParser(int)), + obis.VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)), + obis.VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)), + obis.VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)), + obis.TEXT_MESSAGE_CODE: CosemParser(ValueParser(int)), + obis.TEXT_MESSAGE: CosemParser(ValueParser(str)), + obis.DEVICE_TYPE: CosemParser(ValueParser(int)), + obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: CosemParser(ValueParser(Decimal)), + obis.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: CosemParser(ValueParser(Decimal)), + obis.EQUIPMENT_IDENTIFIER_GAS: CosemParser(ValueParser(str)), + obis.HOURLY_GAS_METER_READING: MBusParser(ValueParser(timestamp), + ValueParser(Decimal)) } - diff --git a/setup.py b/setup.py index c0f2d76..8f55bfd 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ setup( version='0.1', packages=find_packages(), install_requires=[ - 'pyserial==3.0.1', - 'pytz==2016.3' + 'pyserial>=3.2.1', + 'pytz' ], entry_points={ 'console_scripts': ['dsmr_console=dsmr_parser.__main__:console'] diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..eb471d4 --- /dev/null +++ b/tox.ini @@ -0,0 +1,16 @@ +[tox] +envlist = py35 + +[testenv] +deps= + pytest + pylama +commands= + py.test test {posargs} + pylama dsmr_parser test + +[pylama:pylint] +max_line_length = 100 + +[pylama:pycodestyle] +max_line_length = 100