diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5fac8e7..babab7c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,14 @@ Change Log ---------- +**0.16** (2019-12-21) + +- Add support for Belgian and Smarty meters (`pull request #44 `_). + +**0.15** (2019-12-12) + +- Fixed asyncio loop issue (`pull request #43 `_). + **0.14** (2019-10-08) - Changed serial reading to reduce CPU usage (`pull request #37 `_). diff --git a/dsmr_parser/clients/protocol.py b/dsmr_parser/clients/protocol.py index 141a389..7e8e260 100644 --- a/dsmr_parser/clients/protocol.py +++ b/dsmr_parser/clients/protocol.py @@ -26,6 +26,9 @@ def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None): elif dsmr_version == '5': specification = telegram_specifications.V5 serial_settings = SERIAL_SETTINGS_V5 + elif dsmr_version == '5B': + specification = telegram_specifications.BELGIUM_FLUVIUS + serial_settings = SERIAL_SETTINGS_V5 else: raise NotImplementedError("No telegram parser found for version: %s", dsmr_version) @@ -49,12 +52,13 @@ def create_dsmr_reader(port, dsmr_version, telegram_callback, loop=None): def create_tcp_dsmr_reader(host, port, dsmr_version, telegram_callback, loop=None): """Creates a DSMR asyncio protocol coroutine using TCP connection.""" + if not loop: + loop = asyncio.get_event_loop() protocol, _ = create_dsmr_protocol( - dsmr_version, telegram_callback, loop=None) + dsmr_version, telegram_callback, loop=loop) conn = loop.create_connection(protocol, host, port) return conn - class DSMRProtocol(asyncio.Protocol): """Assemble and handle incoming data into complete DSM telegrams.""" diff --git a/dsmr_parser/obis_references.py b/dsmr_parser/obis_references.py index 5050f43..cb7b158 100644 --- a/dsmr_parser/obis_references.py +++ b/dsmr_parser/obis_references.py @@ -60,3 +60,8 @@ ELECTRICITY_DELIVERED_TARIFF_ALL = ( ELECTRICITY_DELIVERED_TARIFF_1, ELECTRICITY_DELIVERED_TARIFF_2 ) + +# Alternate codes for foreign countries. +BELGIUM_HOURLY_GAS_METER_READING = r'\d-\d:24\.2\.3.+?\r\n' # Different code, same format. +LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL = r'\d-\d:1\.8\.0.+?\r\n' # Total imported energy register (P+) +LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL = r'\d-\d:2\.8\.0.+?\r\n' # Total exported energy register (P-) diff --git a/dsmr_parser/telegram_specifications.py b/dsmr_parser/telegram_specifications.py index e2c0bf5..a42806f 100644 --- a/dsmr_parser/telegram_specifications.py +++ b/dsmr_parser/telegram_specifications.py @@ -1,4 +1,5 @@ from decimal import Decimal +from copy import deepcopy from dsmr_parser import obis_references as obis from dsmr_parser.parsers import CosemParser, ValueParser, MBusParser @@ -128,3 +129,18 @@ V5 = { } ALL = (V2_2, V3, V4, V5) + + +BELGIUM_FLUVIUS = deepcopy(V5) +BELGIUM_FLUVIUS['objects'].update({ + obis.BELGIUM_HOURLY_GAS_METER_READING: MBusParser( + ValueParser(timestamp), + ValueParser(Decimal) + ) +}) + +LUXEMBOURG_SMARTY = deepcopy(V5) +LUXEMBOURG_SMARTY['objects'].update({ + obis.LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL: CosemParser(ValueParser(Decimal)), + obis.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL: CosemParser(ValueParser(Decimal)), +}) diff --git a/setup.py b/setup.py index 673267f..e1f0139 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( author='Nigel Dokter', author_email='nigel@nldr.net', url='https://github.com/ndokter/dsmr_parser', - version='0.15', + version='0.17', packages=find_packages(), install_requires=[ 'pyserial>=3,<4',