Compare commits

..
Author SHA1 Message Date
Nigel 98652418cc Merged master into autodetecttelegram 2024-08-25 15:26:54 +02:00
Nigel 99ad21c896 added a bit of documentation on how to run tests (#165)
* added a bit of documentation on how to run tests

* formatting

* formatting

* formatting

* formatting

* formatting

* formatting
2024-08-25 14:55:22 +02:00
Nigel 94189b6b63 Preparing release 1.4.2 2024-07-14 14:21:13 +02:00
Dennis Siemensma 8829260b15 Bump Github Actions to latest versions in favor of Node deprecations (#159) 2024-06-15 11:33:15 +02:00
Ido Szargel 55ac551a2a Add socket timeout (#155)
* Add socket timeout
2024-06-10 16:19:01 +02:00
J. Nick Koston fc65326370 Swap pyserial-asyncio for pyserial-asyncio-fast (#158)
* Swap pyserial-asyncio for pyserial-asyncio-fast

fixes #154

* actually commit the import change
2024-06-07 16:08:35 +02:00
Nigel 059c0802ad Fix changelog 2024-06-04 16:06:38 +02:00
Nigel d7f30b5069 Release 1.4.1 2024-06-04 15:59:32 +02:00
Joakim Plate b42ceb6555 Avoid loading timezone at runtime (#157)
* Avoid loading timezone at runtime

Pytz will load timezone info from files in
a lazy fashion on first access. This triggers warnings in HA due to it blocking the event loop.

Pre-load the needed timezone info at module import instead, which will run in
executor in HA.

* Update value_types.py
2024-06-04 15:51:03 +02:00
gigatexel 3cf627eedc Change checksum log level (#151)
* Update filereader.py

* Update socket_.py

* Update serial_.py

* Update protocol.py

* Update socket_.py
2024-03-28 12:40:17 +01:00
Nigel d680d44683 Update CHANGELOG.rst 2024-03-12 13:26:04 +01:00
Nigel 6387cc4440 CHANGELOG formatting 2024-03-12 12:56:13 +01:00
Nigel 61985c5c89 Changelog formatting 2024-03-12 12:54:28 +01:00
Nigel 88aaa2d30f Release 1.4.0 2024-03-12 12:50:36 +01:00
dupondje 1ce0925b61 Copy head_parsers list on construct. (#150)
We need to create a copy of the head_parsers.
Otherwise the self.value_formats contains just a reference to
head_parsers.
But the self.value_formats is modified in the _parse_values, causing
invalid values in the head_parsers list.
2024-03-12 11:14:43 +01:00
dupondje bc35a051f2 Change DSMR 5 and 5B to use DSMR devices (#142)
At least the BE and the NL DSMR devices use MBUS.
Therefore we make the MBUS obis reference generic, and convert the V5
telegram to use MBUS values.

Finally set self.maxDiff = None to have a full test output on some
tests.
2024-03-07 11:21:23 +01:00
Gunnar Klauberg fcbcbb30e0 Q3D add CURRENT_ELECTRICITY_DELIVERY (#149)
add CURRENT_ELECTRICITY_DELIVERY sensor for Q3D
2024-02-19 14:31:09 +01:00
Nigel be61d4aaf9 Prepare release 1.3.2 2024-01-29 14:29:02 +01:00
Nigel 1680cacf49 fix protocol unit test for python3.12 (#148)
* fix protocol unit test for python3.12

* add workflow test for python 3.12
2024-01-29 14:25:39 +01:00
dupondje 739419e3ee Remove BELGIUM_MAX_POWER_PER_PHASE (#144)
This commit removes BELGIUM_MAX_POWER_PER_PHASE and uses
ACTUAL_TRESHOLD_ELECTRICITY as this has same regex. So useless to keep
the BELIUM variant.
2023-11-07 12:10:42 +01:00
Jean-Louis Dupond d2ff6f4bb9 Fix tests after FUSE_TRESHOLD rename 2023-11-06 15:10:36 +01:00
Jean-Louis Dupond a316d93082 Adjust the naming of the MAX_POWER and MAX_CURRENT obis values 2023-11-06 15:10:36 +01:00
Nigel Dokter d216996fe6 updated changelog in preparation of v0.9 2017-03-02 19:15:19 +01:00
Nigel Dokter aef37837c5 Merge branch 'issue_22' into development 2017-03-02 19:08:17 +01:00
Nigel Dokter 6305d3d37f finished match_telegram_specification 2017-03-02 19:05:17 +01:00
26 changed files with 453 additions and 398 deletions
+5 -4
View File
@@ -17,18 +17,19 @@ jobs:
- '3.9'
- '3.10'
- '3.11'
- '3.12'
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cached PIP dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/pip
@@ -43,4 +44,4 @@ jobs:
run: tox
- name: Code coverage upload
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
+27 -7
View File
@@ -1,19 +1,39 @@
Change Log
----------
**1.5.0** (2024-08-25)
- Allow the telegram specification to optionally be autodetected (`PR #87 <https://github.com/ndokter/dsmr_parser/pull/87>`_ by `clonerswords <https://github.com/clonerswords>`_)
**1.4.2** (2024-07-14)
- Bump Github Actions to latest versions in favor of Node deprecations (`PR #159 <https://github.com/ndokter/dsmr_parser/pull/159>`_ by `dennissiemensma <https://github.com/dennissiemensma>`_)
- Swap pyserial-asyncio for pyserial-asyncio-fast (`PR #158 <https://github.com/ndokter/dsmr_parser/pull/158>`_ by `bdraco <https://github.com/bdraco>`_)
**1.4.1** (2024-06-04)
- Avoid loading timezone at runtime (`PR #157 <https://github.com/ndokter/dsmr_parser/pull/157>`_ by `elupus <https://github.com/elupus>`_)
**1.4.0** (2024-03-12)
- Mbus alt (`PR #142 <https://github.com/ndokter/dsmr_parser/pull/142>`_ by `dupondje <https://github.com/dupondje>`_)
- Q3D add CURRENT_ELECTRICITY_DELIVERY (`PR #149 <https://github.com/ndokter/dsmr_parser/pull/149>`_ by `Aeroid <https://github.com/Aeroid>`_)
- Copy head_parsers list on construct. (`PR #150 <https://github.com/ndokter/dsmr_parser/pull/150>`_ by `dupondje <https://github.com/dupondje>`_)
**1.3.2** (2024-01-29)
- Fix unit test for pyton 3.12 (`PR #148 <https://github.com/ndokter/dsmr_parser/pull/148>`_ by `ndokter <https://github.com/ndokter>`_)
**1.3.1** (2023-11-06)
- Fix parsing peak usage with invalid timestamps
(`PR #143 <https://github.com/ndokter/dsmr_parser/pull/143>`_ by `dupondje <https://github.com/dupondje>`_)
- Fix parsing peak usage with invalid timestamps (`PR #143 <https://github.com/ndokter/dsmr_parser/pull/143>`_ by `dupondje <https://github.com/dupondje>`_)
**1.3.0** (2023-08-01)
- added E.ON Hungary; refactored DSMR specifications to fix obis reference conflicts
(`PR #137 <https://github.com/ndokter/dsmr_parser/pull/137>`_ by `balazs92117 <https://github.com/balazs92117>`_)
- added E.ON Hungary; refactored DSMR specifications to fix obis reference conflicts (`PR #137 <https://github.com/ndokter/dsmr_parser/pull/137>`_ by `balazs92117 <https://github.com/balazs92117>`_)
**1.2.4** (2023-07-11)
- EQUIPMENT IDENTIFIER is wrong for Fluvius meters when other mbus devices are present
(`PR #133 <https://github.com/ndokter/dsmr_parser/pull/133>`_ by `ejpalacios <https://github.com/ejpalacios>`_)
- EQUIPMENT IDENTIFIER is wrong for Fluvius meters when other mbus devices are present (`PR #133 <https://github.com/ndokter/dsmr_parser/pull/133>`_ by `ejpalacios <https://github.com/ejpalacios>`_)
**1.2.3** (2023-04-18)
@@ -150,7 +170,7 @@ Remove deprecated asyncio coroutine decorator (`PR #76 <https://github.com/ndokt
**0.12** (2018-09-23)
- Add serial settings for DSMR v5.0 (`PR #31 <https://github.com/ndokter/dsmr_parser/pull/31>`_).
- Lux-creos-obis-1.8.0 (`PR #32 <https://github.com/ndokter/dsmr_parser/pull/32>`_).
- Lux-creos-obis-1.8.0 (`PR #32 <https://github.com/ndokter/dsmr_parser/pull/32>`_).
**0.11** (2017-09-18)
+30
View File
@@ -293,6 +293,36 @@ To install DSMR Parser:
$ pip install dsmr-parser
Development
-----------
Create a virtualenv and activate it followed by the installation of the dsmr-parser:
.. code-block:: bash
python3 -m venv venv
source venv/bin/activate
pip install -e .
Install tox and run it:
.. code-block:: bash
pip install tox
tox
You should see that the tests have succeeded:
.. code-block:: text
======================================================================================================== 59 passed in 0.91s ========================================================================================================
py: commands[1]> pylama dsmr_parser test
py: OK (11.55=setup[9.73]+cmd[1.29,0.53] seconds)
congratulations :) (11.69 seconds)
Now you can make changes by editing the code and rerunning tox to verify your changes.
Known issues
------------
+1 -1
View File
@@ -73,7 +73,7 @@ class FileReader(object):
try:
yield self.telegram_parser.parse(telegram)
except InvalidChecksumError as e:
logger.warning(str(e))
logger.info(str(e))
except ParseError as e:
logger.error('Failed to parse telegram: %s', e)
+2 -2
View File
@@ -4,7 +4,7 @@ from functools import partial
import asyncio
import logging
from serial_asyncio import create_serial_connection
from serial_asyncio_fast import create_serial_connection
from dsmr_parser import telegram_specifications
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
@@ -158,7 +158,7 @@ class DSMRProtocol(asyncio.Protocol):
try:
parsed_telegram = self.telegram_parser.parse(telegram)
except InvalidChecksumError as e:
self.log.warning(str(e))
self.log.info(str(e))
except ParseError:
self.log.exception("failed to parse telegram")
else:
+1 -1
View File
@@ -2,7 +2,7 @@
import asyncio
from serial_asyncio import create_serial_connection
from serial_asyncio_fast import create_serial_connection
from .protocol import DSMRProtocol, _create_dsmr_protocol
+4 -4
View File
@@ -1,6 +1,6 @@
import logging
import serial
import serial_asyncio
import serial_asyncio_fast
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
@@ -37,7 +37,7 @@ class SerialReader(object):
try:
yield self.telegram_parser.parse(telegram)
except InvalidChecksumError as e:
logger.warning(str(e))
logger.info(str(e))
except ParseError as e:
logger.error('Failed to parse telegram: %s', e)
@@ -77,7 +77,7 @@ class AsyncSerialReader(SerialReader):
:rtype: None
"""
# create Serial StreamReader
conn = serial_asyncio.open_serial_connection(**self.serial_settings)
conn = serial_asyncio_fast.open_serial_connection(**self.serial_settings)
reader, _ = await conn
while True:
@@ -107,7 +107,7 @@ class AsyncSerialReader(SerialReader):
"""
# create Serial StreamReader
conn = serial_asyncio.open_serial_connection(**self.serial_settings)
conn = serial_asyncio_fast.open_serial_connection(**self.serial_settings)
reader, _ = await conn
while True:
+7 -3
View File
@@ -31,11 +31,15 @@ class SocketReader(object):
buffer = b""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as socket_handle:
socket_handle.settimeout(60)
socket_handle.connect((self.host, self.port))
while True:
buffer += socket_handle.recv(self.BUFFER_SIZE)
try:
buffer += socket_handle.recv(self.BUFFER_SIZE)
except socket.timeout:
logger.error("Socket timeout occurred, exiting")
break
lines = buffer.splitlines(keepends=True)
@@ -54,7 +58,7 @@ class SocketReader(object):
try:
yield self.telegram_parser.parse(telegram)
except InvalidChecksumError as e:
logger.warning(str(e))
logger.info(str(e))
except ParseError as e:
logger.error('Failed to parse telegram: %s', e)
+4
View File
@@ -4,3 +4,7 @@ class ParseError(Exception):
class InvalidChecksumError(ParseError):
pass
class TelegramSpecificationMatchError(ParseError):
pass
+21 -35
View File
@@ -43,6 +43,9 @@ INSTANTANEOUS_VOLTAGE_L3 = r'^\d-\d:72\.7\.0.+?\r\n'
INSTANTANEOUS_CURRENT_L1 = r'^\d-\d:31\.7\.0.+?\r\n'
INSTANTANEOUS_CURRENT_L2 = r'^\d-\d:51\.7\.0.+?\r\n'
INSTANTANEOUS_CURRENT_L3 = r'^\d-\d:71\.7\.0.+?\r\n'
FUSE_THRESHOLD_L1 = r'^\d-\d:31\.4\.0.+?\r\n' # Applicable when current limitation is active
FUSE_THRESHOLD_L2 = r'^\d-\d:51\.4\.0.+?\r\n' # Applicable when current limitation is active
FUSE_THRESHOLD_L3 = r'^\d-\d:71\.4\.0.+?\r\n' # Applicable when current limitation is active
TEXT_MESSAGE_CODE = r'^\d-\d:96\.13\.1.+?\r\n'
TEXT_MESSAGE = r'^\d-\d:96\.13\.0.+?\r\n'
DEVICE_TYPE = r'^\d-\d:24\.1\.0.+?\r\n'
@@ -66,8 +69,25 @@ ACTUAL_TRESHOLD_ELECTRICITY = r'^\d-\d:17\.0\.0.+?\r\n'
ACTUAL_SWITCH_POSITION = r'^\d-\d:96\.3\.10.+?\r\n'
VALVE_POSITION_GAS = r'^\d-\d:24\.4\.0.+?\r\n'
# Multiple 'slaves' can be linked to the main device.
# The type is reported on 24.1.0
# Specifications are in EN 13757-3
# For example: Water mater = 7, Gas meter = 3
# Identifier is on 96.1.0 (in NL for ex) or
# on 96.1.1 (in BE for ex)
# The values are reported on 24.2.1
# With an exception in Belgium for the GAS meter
# Be aware that for the gas volume, another OBIS-code is published
# than the one listed in section 7 of DSMR P1.
# This is due to the fact that in Belgium the not-temperature
# corrected gas volume is used while in the Netherlands,
# the temperature corrected gas volume is used.
MBUS_DEVICE_TYPE = r'^\d-[1-9]:24\.1\.0.+?\r\n'
MBUS_EQUIPMENT_IDENTIFIER = r'^\d-[1-9]:96\.1\.[01].+?\r\n'
MBUS_VALVE_POSITION = r'^\d-[1-9]:24\.4\.0.+?\r\n'
MBUS_METER_READING = r'^\d-[1-9]:24\.2\.[13].+?\r\n'
# TODO 17.0.0
# TODO 96.3.10
ELECTRICITY_USED_TARIFF_ALL = (
ELECTRICITY_USED_TARIFF_1,
@@ -88,38 +108,6 @@ BELGIUM_EQUIPMENT_IDENTIFIER = r'^\d-0:96\.1\.1.+?\r\n'
BELGIUM_CURRENT_AVERAGE_DEMAND = r'^\d-\d:1\.4\.0.+?\r\n'
BELGIUM_MAXIMUM_DEMAND_MONTH = r'^\d-\d:1\.6\.0.+?\r\n'
BELGIUM_MAXIMUM_DEMAND_13_MONTHS = r'^\d-\d:98\.1\.0.+?\r\n'
BELGIUM_MAX_POWER_PER_PHASE = r'^\d-\d:17\.0\.0.+?\r\n' # Applicable when power limitation is active
BELGIUM_MAX_CURRENT_PER_PHASE = r'^\d-\d:31\.4\.0.+?\r\n' # Applicable when current limitation is active
# Multiple 'slaves' can be linked to the main device.
# Mostly MBUS1 = GAS METER with values on 24.2.3
# While WATER METER reports it's values on 24.2.1
# The GAS METER also reports its valve state on 24.4.0
# Dev type for gas = 7 and water = 8
BELGIUM_MBUS1_DEVICE_TYPE = r'^\d-1:24\.1\.0.+?\r\n'
BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER = r'^\d-1:96\.1\.1.+?\r\n'
BELGIUM_MBUS1_VALVE_POSITION = r'^\d-1:24\.4\.0.+?\r\n'
BELGIUM_MBUS1_METER_READING1 = r'^\d-1:24\.2\.1.+?\r\n'
BELGIUM_MBUS1_METER_READING2 = r'^\d-1:24\.2\.3.+?\r\n'
BELGIUM_MBUS2_DEVICE_TYPE = r'^\d-2:24\.1\.0.+?\r\n'
BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER = r'^\d-2:96\.1\.1.+?\r\n'
BELGIUM_MBUS2_VALVE_POSITION = r'^\d-2:24\.4\.0.+?\r\n'
BELGIUM_MBUS2_METER_READING1 = r'^\d-2:24\.2\.1.+?\r\n'
BELGIUM_MBUS2_METER_READING2 = r'^\d-2:24\.2\.3.+?\r\n'
BELGIUM_MBUS3_DEVICE_TYPE = r'^\d-3:24\.1\.0.+?\r\n'
BELGIUM_MBUS3_EQUIPMENT_IDENTIFIER = r'^\d-3:96\.1\.1.+?\r\n'
BELGIUM_MBUS3_VALVE_POSITION = r'^\d-3:24\.4\.0.+?\r\n'
BELGIUM_MBUS3_METER_READING1 = r'^\d-3:24\.2\.1.+?\r\n'
BELGIUM_MBUS3_METER_READING2 = r'^\d-3:24\.2\.3.+?\r\n'
BELGIUM_MBUS4_DEVICE_TYPE = r'^\d-4:24\.1\.0.+?\r\n'
BELGIUM_MBUS4_EQUIPMENT_IDENTIFIER = r'^\d-4:96\.1\.1.+?\r\n'
BELGIUM_MBUS4_VALVE_POSITION = r'^\d-4:24\.4\.0.+?\r\n'
BELGIUM_MBUS4_METER_READING1 = r'^\d-4:24\.2\.1.+?\r\n'
BELGIUM_MBUS4_METER_READING2 = r'^\d-4:24\.2\.3.+?\r\n'
LUXEMBOURG_EQUIPMENT_IDENTIFIER = r'^\d-\d:42\.0\.0.+?\r\n' # Logical device name
@@ -142,5 +130,3 @@ EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q1 = r'^\d-\d:5\.7\.0.+?\r\n'
EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q2 = r'^\d-\d:6\.7\.0.+?\r\n'
EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q3 = r'^\d-\d:7\.7\.0.+?\r\n'
EON_HU_INSTANTANEOUS_REACTIVE_POWER_Q4 = r'^\d-\d:8\.7\.0.+?\r\n'
EON_HU_MAX_POWER_ON_L2 = r'^\d-\d:51\.4\.0.+?\r\n'
EON_HU_MAX_POWER_ON_L3 = r'^\d-\d:71\.4\.0.+?\r\n'
+2 -2
View File
@@ -28,12 +28,12 @@ class Telegram(dict):
def add(self, obis_reference, dsmr_object, obis_name):
# Update name mapping used to get value by attribute. Example: telegram.P1_MESSAGE_HEADER
setattr(self, obis_name, dsmr_object)
if obis_name not in self._item_names: # TODO repeating obis references
self._item_names.append(obis_name)
# TODO isinstance check: MaxDemandParser (BELGIUM_MAXIMUM_DEMAND_13_MONTHS) returns a list
if isinstance(dsmr_object, DSMRObject) and dsmr_object.is_mbus_reading:
self._add_mbus(obis_reference, dsmr_object, obis_name)
elif obis_name not in self._item_names: # TODO repeating obis references
self._item_names.append(obis_name)
# Fill dict which is only used for backwards compatibility
if obis_reference not in self:
+47 -10
View File
@@ -9,7 +9,7 @@ from dlms_cosem.connection import XDlmsApduFactory
from dlms_cosem.protocol.xdlms import GeneralGlobalCipher
from dsmr_parser.objects import MBusObject, MBusObjectPeak, CosemObject, ProfileGenericObject, Telegram
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
from dsmr_parser.exceptions import ParseError, InvalidChecksumError, TelegramSpecificationMatchError
from dsmr_parser.value_types import timestamp
logger = logging.getLogger(__name__)
@@ -18,20 +18,17 @@ logger = logging.getLogger(__name__)
class TelegramParser(object):
crc16_tab = []
def __init__(self, telegram_specification, apply_checksum_validation=True):
def __init__(self, telegram_specification=None, apply_checksum_validation=True):
"""
:param telegram_specification: determines how the telegram is parsed
:param telegram_specification: determines how the telegram is parsed.
Will attempt to autodetect if omitted.
:param apply_checksum_validation: validate checksum if applicable for
telegram DSMR version (v4 and up).
:type telegram_specification: dict
"""
self.apply_checksum_validation = apply_checksum_validation
self.telegram_specification = telegram_specification
# Regexes are compiled once to improve performance
self.telegram_specification_regexes = {
object["obis_reference"]: re.compile(object["obis_reference"], re.DOTALL | re.MULTILINE)
for object in self.telegram_specification['objects']
}
self._telegram_specification_regex = None
def parse(self, telegram_data, encryption_key="", authentication_key="", throw_ex=False): # noqa: C901
"""
@@ -46,6 +43,15 @@ class TelegramParser(object):
:raises ParseError:
:raises InvalidChecksumError:
"""
if not self.telegram_specification:
self.telegram_specification = \
match_telegram_specification(telegram_data)
if not self._telegram_specification_regex:
# Regexes are compiled once to improve performance
self._telegram_specification_regexes = {
object["obis_reference"]: re.compile(object["obis_reference"], re.DOTALL | re.MULTILINE)
for object in self.telegram_specification['objects']
}
if "general_global_cipher" in self.telegram_specification:
if self.telegram_specification["general_global_cipher"]:
@@ -85,7 +91,7 @@ class TelegramParser(object):
telegram = Telegram()
for object in self.telegram_specification['objects']:
pattern = self.telegram_specification_regexes[object["obis_reference"]]
pattern = self._telegram_specification_regexes[object["obis_reference"]]
matches = pattern.findall(telegram_data)
# Some signatures are optional and may not be present,
@@ -173,6 +179,37 @@ class TelegramParser(object):
return crcValue
def match_telegram_specification(telegram_data):
"""
Find telegram specification that matches the telegram data by trying all
specifications.
Could be further optimized to check the actual 0.2.8 OBIS reference which
is available for DSMR version 4 and up.
:param str telegram_data: full telegram from start ('/') to checksum
('!ABCD') including line endings in between the telegram's lines
:return: telegram specification
:rtype: dict
"""
# Prevent circular import
from dsmr_parser import telegram_specifications
for specification in telegram_specifications.ALL:
try:
TelegramParser(specification).parse(telegram_data)
except ParseError:
pass
else:
return specification
raise TelegramSpecificationMatchError(
'Could automatically match telegram specification. Make sure the data'
'is not corrupt. Alternatively manually specify one.'
)
class DSMRObjectParser(object):
"""
Parses an object (can also be see as a 'line') from a telegram.
@@ -335,7 +372,7 @@ class ProfileGenericParser(DSMRObjectParser):
"""
def __init__(self, buffer_types, head_parsers, parsers_for_unidentified):
self.value_formats = head_parsers
self.value_formats = head_parsers.copy()
self.buffer_types = buffer_types
self.parsers_for_unidentified = parsers_for_unidentified
+52 -136
View File
@@ -430,11 +430,6 @@ V5 = {
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'TEXT_MESSAGE'
},
{
'obis_reference': obis.DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'DEVICE_TYPE'
},
{
'obis_reference': obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE,
'value_parser': CosemParser(ValueParser(Decimal)),
@@ -466,23 +461,31 @@ V5 = {
'value_name': 'INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE'
},
{
'obis_reference': obis.EQUIPMENT_IDENTIFIER_GAS,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'EQUIPMENT_IDENTIFIER_GAS'
'obis_reference': obis.MBUS_DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'MBUS_DEVICE_TYPE'
},
{
'obis_reference': obis.HOURLY_GAS_METER_READING,
'value_parser': MBusParser(
'obis_reference': obis.MBUS_EQUIPMENT_IDENTIFIER,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'MBUS_EQUIPMENT_IDENTIFIER'
},
{
'obis_reference': obis.MBUS_VALVE_POSITION,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'MBUS_VALVE_POSITION'
},
{
'obis_reference': obis.MBUS_METER_READING,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'HOURLY_GAS_METER_READING'
'value_name': 'MBUS_METER_READING'
},
]
}
ALL = (V2_2, V3, V4, V5)
BELGIUM_FLUVIUS = {
'checksum_support': True,
'objects': [
@@ -625,14 +628,9 @@ BELGIUM_FLUVIUS = {
'value_name': 'ACTUAL_TRESHOLD_ELECTRICITY'
},
{
'obis_reference': obis.BELGIUM_MAX_POWER_PER_PHASE,
'obis_reference': obis.FUSE_THRESHOLD_L1,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'BELGIUM_MAX_POWER_PER_PHASE'
},
{
'obis_reference': obis.BELGIUM_MAX_CURRENT_PER_PHASE,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'BELGIUM_MAX_CURRENT_PER_PHASE'
'value_name': 'FUSE_THRESHOLD_L1'
},
{
'obis_reference': obis.TEXT_MESSAGE,
@@ -640,128 +638,27 @@ BELGIUM_FLUVIUS = {
'value_name': 'TEXT_MESSAGE'
},
{
'obis_reference': obis.BELGIUM_MBUS1_DEVICE_TYPE,
'obis_reference': obis.MBUS_DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS1_DEVICE_TYPE'
'value_name': 'MBUS_DEVICE_TYPE'
},
{
'obis_reference': obis.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER,
'obis_reference': obis.MBUS_EQUIPMENT_IDENTIFIER,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER'
'value_name': 'MBUS_EQUIPMENT_IDENTIFIER'
},
{
'obis_reference': obis.BELGIUM_MBUS1_VALVE_POSITION,
'obis_reference': obis.MBUS_VALVE_POSITION,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS1_VALVE_POSITION'
'value_name': 'MBUS_VALVE_POSITION'
},
{
'obis_reference': obis.BELGIUM_MBUS1_METER_READING1,
'obis_reference': obis.MBUS_METER_READING,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS1_METER_READING1'
},
{
'obis_reference': obis.BELGIUM_MBUS1_METER_READING2,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS1_METER_READING2'
},
{
'obis_reference': obis.BELGIUM_MBUS2_DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS2_DEVICE_TYPE'
},
{
'obis_reference': obis.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER'
},
{
'obis_reference': obis.BELGIUM_MBUS2_VALVE_POSITION,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS2_VALVE_POSITION'
},
{
'obis_reference': obis.BELGIUM_MBUS2_METER_READING1,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS2_METER_READING1'
},
{
'obis_reference': obis.BELGIUM_MBUS2_METER_READING2,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS2_METER_READING2'
},
{
'obis_reference': obis.BELGIUM_MBUS3_DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS3_DEVICE_TYPE'
},
{
'obis_reference': obis.BELGIUM_MBUS3_EQUIPMENT_IDENTIFIER,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'BELGIUM_MBUS3_EQUIPMENT_IDENTIFIER'
},
{
'obis_reference': obis.BELGIUM_MBUS3_VALVE_POSITION,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS3_VALVE_POSITION'
},
{
'obis_reference': obis.BELGIUM_MBUS3_METER_READING1,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS3_METER_READING1'
},
{
'obis_reference': obis.BELGIUM_MBUS3_METER_READING2,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS3_METER_READING2'
},
{
'obis_reference': obis.BELGIUM_MBUS4_DEVICE_TYPE,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS4_DEVICE_TYPE'
},
{
'obis_reference': obis.BELGIUM_MBUS4_EQUIPMENT_IDENTIFIER,
'value_parser': CosemParser(ValueParser(str)),
'value_name': 'BELGIUM_MBUS4_EQUIPMENT_IDENTIFIER'
},
{
'obis_reference': obis.BELGIUM_MBUS4_VALVE_POSITION,
'value_parser': CosemParser(ValueParser(int)),
'value_name': 'BELGIUM_MBUS4_VALVE_POSITION'
},
{
'obis_reference': obis.BELGIUM_MBUS4_METER_READING1,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS4_METER_READING1'
},
{
'obis_reference': obis.BELGIUM_MBUS4_METER_READING2,
'value_parser': MBusParser(
ValueParser(timestamp),
ValueParser(Decimal)
),
'value_name': 'BELGIUM_MBUS4_METER_READING2'
'value_name': 'MBUS_METER_READING'
},
]
}
@@ -962,6 +859,11 @@ Q3D = {
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'CURRENT_ELECTRICITY_USAGE'
},
{
'obis_reference': obis.CURRENT_ELECTRICITY_DELIVERY,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'CURRENT_ELECTRICITY_DELIVERY'
},
{
'obis_reference': obis.Q3D_EQUIPMENT_STATE,
'value_parser': CosemParser(ValueParser(str)),
@@ -1233,7 +1135,7 @@ EON_HUNGARY = {
# This seems to be wrong in documentation, it's not 0-0:96.50.68, but 0-0:96.3.10
},
{
'obis_reference': obis.BELGIUM_MAX_POWER_PER_PHASE,
'obis_reference': obis.ACTUAL_TRESHOLD_ELECTRICITY,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'ACTUAL_TRESHOLD_ELECTRICITY'
},
@@ -1414,20 +1316,20 @@ EON_HUNGARY = {
'value_name': 'INSTANTANEOUS_REACTIVE_POWER_Q4'
},
{
'obis_reference': obis.BELGIUM_MAX_CURRENT_PER_PHASE,
'obis_reference': obis.FUSE_THRESHOLD_L1,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'MAX_POWER_ON_L1'
'value_name': 'FUSE_THRESHOLD_L1'
},
{
'obis_reference': obis.EON_HU_MAX_POWER_ON_L2,
'obis_reference': obis.FUSE_THRESHOLD_L2,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'MAX_POWER_ON_L2'
'value_name': 'FUSE_THRESHOLD_L2'
# Only with 3 phase meters
},
{
'obis_reference': obis.EON_HU_MAX_POWER_ON_L3,
'obis_reference': obis.FUSE_THRESHOLD_L3,
'value_parser': CosemParser(ValueParser(Decimal)),
'value_name': 'MAX_POWER_ON_L3'
'value_name': 'FUSE_THRESHOLD_L3'
# Only with 3 phase meters
},
# I'm not sure which datas does this line containes. It should be the data of last minute of last month.
@@ -1464,3 +1366,17 @@ EON_HUNGARY = {
}
]
}
ALL = (
V2_2,
V3,
V4,
V5,
BELGIUM_FLUVIUS,
LUXEMBOURG_SMARTY,
SWEDEN,
SAGEMCOM_T210_D_R,
AUSTRIA_ENERGIENETZE_STEIERMARK,
ISKRA_IE,
EON_HUNGARY
)
+4 -2
View File
@@ -2,6 +2,10 @@ import datetime
import pytz
# TODO : Use system timezone
# Preload timezone to avoid loading in event loop later
local_tz = pytz.timezone('Europe/Amsterdam')
def timestamp(value):
try:
@@ -20,8 +24,6 @@ def timestamp(value):
else:
is_dst = False
# TODO : Use system timezone
local_tz = pytz.timezone('Europe/Amsterdam')
localized_datetime = local_tz.localize(naive_datetime, is_dst=is_dst)
return localized_datetime.astimezone(pytz.utc)
+2 -2
View File
@@ -7,11 +7,11 @@ setup(
author_email='mail@nldr.net',
license='MIT',
url='https://github.com/ndokter/dsmr_parser',
version='1.3.1',
version='1.5.0',
packages=find_packages(exclude=('test', 'test.*')),
install_requires=[
'pyserial>=3,<4',
'pyserial-asyncio<1',
'pyserial-asyncio-fast>=0.11',
'pytz',
'Tailer==0.4.1',
'dlms_cosem==21.3.2'
+21 -21
View File
@@ -15,59 +15,59 @@ class MbusDeviceTest(unittest.TestCase):
device_type_parser = [
object["value_parser"]
for object in v5_objects
if object["obis_reference"] == obis_references.DEVICE_TYPE
if object["obis_reference"] == obis_references.MBUS_DEVICE_TYPE
][0]
device_type = device_type_parser.parse('0-2:24.1.0(003)\r\n')
equipment_parser = [
object["value_parser"]
for object in v5_objects
if object["obis_reference"] == obis_references.EQUIPMENT_IDENTIFIER_GAS
if object["obis_reference"] == obis_references.MBUS_EQUIPMENT_IDENTIFIER
][0]
equipment = equipment_parser.parse('0-2:96.1.0(4730303339303031393336393930363139)\r\n')
gas_reading_parser = [
object["value_parser"]
for object in v5_objects
if object["obis_reference"] == obis_references.HOURLY_GAS_METER_READING
if object["obis_reference"] == obis_references.MBUS_METER_READING
][0]
gas_reading = gas_reading_parser.parse('0-2:24.2.1(200426223001S)(00246.138*m3)\r\n')
mbus_device = MbusDevice(channel_id=1)
mbus_device.add(obis_references.DEVICE_TYPE, device_type, "DEVICE_TYPE")
mbus_device.add(obis_references.EQUIPMENT_IDENTIFIER_GAS, equipment, "EQUIPMENT_IDENTIFIER_GAS")
mbus_device.add(obis_references.HOURLY_GAS_METER_READING, gas_reading, "HOURLY_GAS_METER_READING")
mbus_device = MbusDevice(channel_id=2)
mbus_device.add(obis_references.MBUS_DEVICE_TYPE, device_type, "MBUS_DEVICE_TYPE")
mbus_device.add(obis_references.MBUS_EQUIPMENT_IDENTIFIER, equipment, "MBUS_EQUIPMENT_IDENTIFIER")
mbus_device.add(obis_references.MBUS_METER_READING, gas_reading, "MBUS_METER_READING")
self.mbus_device = mbus_device
def test_attributes(self):
self.assertEqual(self.mbus_device.DEVICE_TYPE.value, 3)
self.assertEqual(self.mbus_device.DEVICE_TYPE.unit, None)
self.assertEqual(self.mbus_device.MBUS_DEVICE_TYPE.value, 3)
self.assertEqual(self.mbus_device.MBUS_DEVICE_TYPE.unit, None)
self.assertEqual(self.mbus_device.EQUIPMENT_IDENTIFIER_GAS.value,
self.assertEqual(self.mbus_device.MBUS_EQUIPMENT_IDENTIFIER.value,
'4730303339303031393336393930363139')
self.assertEqual(self.mbus_device.EQUIPMENT_IDENTIFIER_GAS.unit, None)
self.assertEqual(self.mbus_device.MBUS_EQUIPMENT_IDENTIFIER.unit, None)
self.assertEqual(self.mbus_device.HOURLY_GAS_METER_READING.value, Decimal('246.138'))
self.assertEqual(self.mbus_device.HOURLY_GAS_METER_READING.unit, 'm3')
self.assertEqual(self.mbus_device.MBUS_METER_READING.value, Decimal('246.138'))
self.assertEqual(self.mbus_device.MBUS_METER_READING.unit, 'm3')
def test_to_json(self):
self.assertEqual(
json.loads(self.mbus_device.to_json()),
{
'CHANNEL_ID': 1,
'DEVICE_TYPE': {'value': 3, 'unit': None},
'EQUIPMENT_IDENTIFIER_GAS': {'value': '4730303339303031393336393930363139', 'unit': None},
'HOURLY_GAS_METER_READING': {'datetime': '2020-04-26T20:30:01+00:00', 'value': 246.138, 'unit': 'm3'}}
'CHANNEL_ID': 2,
'MBUS_DEVICE_TYPE': {'value': 3, 'unit': None},
'MBUS_EQUIPMENT_IDENTIFIER': {'value': '4730303339303031393336393930363139', 'unit': None},
'MBUS_METER_READING': {'datetime': '2020-04-26T20:30:01+00:00', 'value': 246.138, 'unit': 'm3'}}
)
def test_str(self):
self.assertEqual(
str(self.mbus_device),
(
'MBUS DEVICE (channel 1)\n'
'\tDEVICE_TYPE: 3 [None]\n'
'\tEQUIPMENT_IDENTIFIER_GAS: 4730303339303031393336393930363139 [None]\n'
'\tHOURLY_GAS_METER_READING: 246.138 [m3] at 2020-04-26T20:30:01+00:00\n'
'MBUS DEVICE (channel 2)\n'
'\tMBUS_DEVICE_TYPE: 3 [None]\n'
'\tMBUS_EQUIPMENT_IDENTIFIER: 4730303339303031393336393930363139 [None]\n'
'\tMBUS_METER_READING: 246.138 [m3] at 2020-04-26T20:30:01+00:00\n'
)
)
+41 -44
View File
@@ -216,14 +216,6 @@ class TelegramTest(unittest.TestCase):
value_type=Decimal,
value_val=Decimal('2'))
# DEVICE_TYPE (0-x:24.1.0)
self.verify_telegram_item(telegram,
'DEVICE_TYPE',
object_type=CosemObject,
unit_val=None,
value_type=int,
value_val=3)
# INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE (1-0:21.7.0)
self.verify_telegram_item(telegram,
'INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE',
@@ -272,7 +264,15 @@ class TelegramTest(unittest.TestCase):
value_type=Decimal,
value_val=Decimal('0'))
# EQUIPMENT_IDENTIFIER_GAS (0-x:96.1.0)
# DEVICE_TYPE (0-1:24.1.0)
self.verify_telegram_item(telegram,
'DEVICE_TYPE',
object_type=CosemObject,
unit_val=None,
value_type=int,
value_val=3)
# EQUIPMENT_IDENTIFIER_GAS (0-1:96.1.0)
self.verify_telegram_item(telegram,
'EQUIPMENT_IDENTIFIER_GAS',
object_type=CosemObject,
@@ -340,28 +340,28 @@ class TelegramTest(unittest.TestCase):
self.assertEqual(len(mbus_devices), 2)
mbus_device_1 = mbus_devices[0]
self.assertEqual(mbus_device_1.DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_1.EQUIPMENT_IDENTIFIER_GAS.value, None)
self.assertEqual(mbus_device_1.HOURLY_GAS_METER_READING.value, Decimal('0'))
self.assertEqual(mbus_device_1.MBUS_DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_1.MBUS_EQUIPMENT_IDENTIFIER.value, None)
self.assertEqual(mbus_device_1.MBUS_METER_READING.value, Decimal('0'))
mbus_device_2 = mbus_devices[1]
self.assertEqual(mbus_device_2.DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_2.EQUIPMENT_IDENTIFIER_GAS.value, '4730303339303031393336393930363139')
self.assertEqual(mbus_device_2.HOURLY_GAS_METER_READING.value, Decimal('246.138'))
self.assertEqual(mbus_device_2.MBUS_DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_2.MBUS_EQUIPMENT_IDENTIFIER.value, '4730303339303031393336393930363139')
self.assertEqual(mbus_device_2.MBUS_METER_READING.value, Decimal('246.138'))
def test_get_mbus_device_by_channel(self):
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(TELEGRAM_V5_TWO_MBUS)
mbus_device_1 = telegram.get_mbus_device_by_channel(1)
self.assertEqual(mbus_device_1.DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_1.EQUIPMENT_IDENTIFIER_GAS.value, None)
self.assertEqual(mbus_device_1.HOURLY_GAS_METER_READING.value, Decimal('0'))
self.assertEqual(mbus_device_1.MBUS_DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_1.MBUS_EQUIPMENT_IDENTIFIER.value, None)
self.assertEqual(mbus_device_1.MBUS_METER_READING.value, Decimal('0'))
mbus_device_2 = telegram.get_mbus_device_by_channel(2)
self.assertEqual(mbus_device_2.DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_2.EQUIPMENT_IDENTIFIER_GAS.value, '4730303339303031393336393930363139')
self.assertEqual(mbus_device_2.HOURLY_GAS_METER_READING.value, Decimal('246.138'))
self.assertEqual(mbus_device_2.MBUS_DEVICE_TYPE.value, 3)
self.assertEqual(mbus_device_2.MBUS_EQUIPMENT_IDENTIFIER.value, '4730303339303031393336393930363139')
self.assertEqual(mbus_device_2.MBUS_METER_READING.value, Decimal('246.138'))
def test_without_mbus_devices(self):
parser = TelegramParser(telegram_specifications.V5, apply_checksum_validation=False)
@@ -375,11 +375,12 @@ class TelegramTest(unittest.TestCase):
telegram = parser.parse(TELEGRAM_V5)
json_data = json.loads(telegram.to_json())
self.maxDiff = None
self.assertEqual(
json_data,
{'CURRENT_ELECTRICITY_DELIVERY': {'unit': 'kW', 'value': 0.0},
'CURRENT_ELECTRICITY_USAGE': {'unit': 'kW', 'value': 0.244},
'DEVICE_TYPE': {'unit': None, 'value': 3},
'ELECTRICITY_ACTIVE_TARIFF': {'unit': None, 'value': '0002'},
'ELECTRICITY_DELIVERED_TARIFF_1': {'unit': 'kWh', 'value': 2.444},
'ELECTRICITY_DELIVERED_TARIFF_2': {'unit': 'kWh', 'value': 0.0},
@@ -387,10 +388,6 @@ class TelegramTest(unittest.TestCase):
'ELECTRICITY_USED_TARIFF_2': {'unit': 'kWh', 'value': 2.399},
'EQUIPMENT_IDENTIFIER': {'unit': None,
'value': '4B384547303034303436333935353037'},
'EQUIPMENT_IDENTIFIER_GAS': {'unit': None, 'value': None},
'HOURLY_GAS_METER_READING': {'datetime': '2017-01-02T15:10:05+00:00',
'unit': 'm3',
'value': 0.107},
'INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE': {'unit': 'kW', 'value': 0.0},
'INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE': {'unit': 'kW', 'value': 0.07},
'INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE': {'unit': 'kW', 'value': 0.0},
@@ -405,15 +402,16 @@ class TelegramTest(unittest.TestCase):
'INSTANTANEOUS_VOLTAGE_L3': {'unit': 'V', 'value': 229.0},
'LONG_POWER_FAILURE_COUNT': {'unit': None, 'value': 0},
'MBUS_DEVICES': [{'CHANNEL_ID': 1,
'DEVICE_TYPE': {'unit': None, 'value': 3},
'EQUIPMENT_IDENTIFIER_GAS': {'unit': None,
'value': '3232323241424344313233343536373839'},
'HOURLY_GAS_METER_READING': {'datetime': '2017-01-02T15:10:05+00:00',
'unit': 'm3',
'value': 0.107}},
'MBUS_DEVICE_TYPE': {'unit': None, 'value': 3},
'MBUS_EQUIPMENT_IDENTIFIER': {'unit': None,
'value': '3232323241424344313233343536373839'},
'MBUS_METER_READING': {'datetime': '2017-01-02T15:10:05+00:00',
'unit': 'm3',
'value': 0.107}},
{'CHANNEL_ID': 2,
'DEVICE_TYPE': {'unit': None, 'value': 3},
'EQUIPMENT_IDENTIFIER_GAS': {'unit': None, 'value': None}}],
'MBUS_DEVICE_TYPE': {'unit': None, 'value': 3},
'MBUS_EQUIPMENT_IDENTIFIER': {'unit': None,
'value': None}}],
'P1_MESSAGE_HEADER': {'unit': None, 'value': '50'},
'P1_MESSAGE_TIMESTAMP': {'unit': None, 'value': '2017-01-02T18:20:02+00:00'},
'POWER_EVENT_FAILURE_LOG': {'buffer': [],
@@ -433,6 +431,8 @@ class TelegramTest(unittest.TestCase):
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(TELEGRAM_V5)
self.maxDiff = None
self.assertEqual(
str(telegram),
(
@@ -463,22 +463,19 @@ class TelegramTest(unittest.TestCase):
'INSTANTANEOUS_CURRENT_L2: 0.44 [A]\n'
'INSTANTANEOUS_CURRENT_L3: 0.86 [A]\n'
'TEXT_MESSAGE: None [None]\n'
'DEVICE_TYPE: 3 [None]\n'
'MBUS DEVICE (channel 1)\n'
' DEVICE_TYPE: 3 [None]\n'
' EQUIPMENT_IDENTIFIER_GAS: 3232323241424344313233343536373839 [None]\n'
' HOURLY_GAS_METER_READING: 0.107 [m3] at 2017-01-02T15:10:05+00:00\n'
'MBUS DEVICE (channel 2)\n'
' DEVICE_TYPE: 3 [None]\n'
' EQUIPMENT_IDENTIFIER_GAS: None [None]\n'
'INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: 0.070 [kW]\n'
'INSTANTANEOUS_ACTIVE_POWER_L2_POSITIVE: 0.032 [kW]\n'
'INSTANTANEOUS_ACTIVE_POWER_L3_POSITIVE: 0.142 [kW]\n'
'INSTANTANEOUS_ACTIVE_POWER_L1_NEGATIVE: 0.000 [kW]\n'
'INSTANTANEOUS_ACTIVE_POWER_L2_NEGATIVE: 0.000 [kW]\n'
'INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE: 0.000 [kW]\n'
'EQUIPMENT_IDENTIFIER_GAS: None [None]\n'
'HOURLY_GAS_METER_READING: 0.107 [m3] at 2017-01-02T15:10:05+00:00\n'
'MBUS DEVICE (channel 1)\n'
' MBUS_DEVICE_TYPE: 3 [None]\n'
' MBUS_EQUIPMENT_IDENTIFIER: 3232323241424344313233343536373839 [None]\n'
' MBUS_METER_READING: 0.107 [m3] at 2017-01-02T15:10:05+00:00\n'
'MBUS DEVICE (channel 2)\n'
' MBUS_DEVICE_TYPE: 3 [None]\n'
' MBUS_EQUIPMENT_IDENTIFIER: None [None]\n'
)
)
+29
View File
@@ -0,0 +1,29 @@
import unittest
from dsmr_parser.exceptions import TelegramSpecificationMatchError
from dsmr_parser.parsers import match_telegram_specification
from dsmr_parser import telegram_specifications
from test import example_telegrams
class MatchTelegramSpecificationTest(unittest.TestCase):
def test_v2_2(self):
assert match_telegram_specification(example_telegrams.TELEGRAM_V2_2) \
== telegram_specifications.V2_2
def test_v3(self):
assert match_telegram_specification(example_telegrams.TELEGRAM_V3) \
== telegram_specifications.V3
def test_v4_2(self):
assert match_telegram_specification(example_telegrams.TELEGRAM_V4_2) \
== telegram_specifications.V4
def test_v5(self):
assert match_telegram_specification(example_telegrams.TELEGRAM_V5) \
== telegram_specifications.V5
def test_malformed_telegram(self):
with self.assertRaises(TelegramSpecificationMatchError):
match_telegram_specification(example_telegrams.TELEGRAM_V5[:-4])
+72 -80
View File
@@ -211,64 +211,70 @@ class TelegramParserFluviusTest(unittest.TestCase):
assert isinstance(result.ACTUAL_SWITCH_POSITION.value, int)
assert result.ACTUAL_SWITCH_POSITION.value == 1
# BELGIUM_MAX_POWER_PER_PHASE (0-0:17.0.0)
assert isinstance(result.BELGIUM_MAX_POWER_PER_PHASE, CosemObject)
assert result.BELGIUM_MAX_POWER_PER_PHASE.unit == 'kW'
assert isinstance(result.BELGIUM_MAX_POWER_PER_PHASE.value, Decimal)
assert result.BELGIUM_MAX_POWER_PER_PHASE.value == Decimal('999.9')
# ACTUAL_TRESHOLD_ELECTRICITY (0-0:17.0.0)
assert isinstance(result.ACTUAL_TRESHOLD_ELECTRICITY, CosemObject)
assert result.ACTUAL_TRESHOLD_ELECTRICITY.unit == 'kW'
assert isinstance(result.ACTUAL_TRESHOLD_ELECTRICITY.value, Decimal)
assert result.ACTUAL_TRESHOLD_ELECTRICITY.value == Decimal('999.9')
# BELGIUM_MAX_POWER_PER_PHASE (1-0:31.4.0)
assert isinstance(result.BELGIUM_MAX_CURRENT_PER_PHASE, CosemObject)
assert result.BELGIUM_MAX_CURRENT_PER_PHASE.unit == 'A'
assert isinstance(result.BELGIUM_MAX_CURRENT_PER_PHASE.value, Decimal)
assert result.BELGIUM_MAX_CURRENT_PER_PHASE.value == Decimal('999')
# FUSE_THRESHOLD_L1 (1-0:31.4.0)
assert isinstance(result.FUSE_THRESHOLD_L1, CosemObject)
assert result.FUSE_THRESHOLD_L1.unit == 'A'
assert isinstance(result.FUSE_THRESHOLD_L1.value, Decimal)
assert result.FUSE_THRESHOLD_L1.value == Decimal('999')
# TEXT_MESSAGE (0-0:96.13.0)
assert isinstance(result.TEXT_MESSAGE, CosemObject)
assert result.TEXT_MESSAGE.unit is None
assert result.TEXT_MESSAGE.value is None
# BELGIUM_MBUS1_DEVICE_TYPE (0-1:24.1.0)
assert isinstance(result.BELGIUM_MBUS1_DEVICE_TYPE, CosemObject)
assert result.BELGIUM_MBUS1_DEVICE_TYPE.unit is None
assert isinstance(result.BELGIUM_MBUS1_DEVICE_TYPE.value, int)
assert result.BELGIUM_MBUS1_DEVICE_TYPE.value == 3
# MBUS DEVICE 1
mbus1 = result.get_mbus_device_by_channel(1)
# BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER (0-1:96.1.1)
assert isinstance(result.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER, CosemObject)
assert result.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER.unit is None
assert isinstance(result.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER.value, str)
assert result.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER.value == '37464C4F32313139303333373333'
# MBUS_DEVICE_TYPE (0-1:24.1.0)
assert isinstance(mbus1.MBUS_DEVICE_TYPE, CosemObject)
assert mbus1.MBUS_DEVICE_TYPE.unit is None
assert isinstance(mbus1.MBUS_DEVICE_TYPE.value, int)
assert mbus1.MBUS_DEVICE_TYPE.value == 3
# BELGIUM_MBUS1_VALVE_POSITION (0-1:24.4.0)
assert isinstance(result.BELGIUM_MBUS1_VALVE_POSITION, CosemObject)
assert result.BELGIUM_MBUS1_VALVE_POSITION.unit is None
assert isinstance(result.BELGIUM_MBUS1_VALVE_POSITION.value, int)
assert result.BELGIUM_MBUS1_VALVE_POSITION.value == 1
# MBUS_EQUIPMENT_IDENTIFIER (0-1:96.1.1)
assert isinstance(mbus1.MBUS_EQUIPMENT_IDENTIFIER, CosemObject)
assert mbus1.MBUS_EQUIPMENT_IDENTIFIER.unit is None
assert isinstance(mbus1.MBUS_EQUIPMENT_IDENTIFIER.value, str)
assert mbus1.MBUS_EQUIPMENT_IDENTIFIER.value == '37464C4F32313139303333373333'
# BELGIUM_MBUS1_METER_READING2 (0-1:24.2.3)
assert isinstance(result.BELGIUM_MBUS1_METER_READING2, MBusObject)
assert result.BELGIUM_MBUS1_METER_READING2.unit == 'm3'
assert isinstance(result.BELGIUM_MBUS1_METER_READING2.value, Decimal)
assert result.BELGIUM_MBUS1_METER_READING2.value == Decimal('112.384')
# MBUS_VALVE_POSITION (0-1:24.4.0)
assert isinstance(result.MBUS_VALVE_POSITION, CosemObject)
assert result.MBUS_VALVE_POSITION.unit is None
assert isinstance(result.MBUS_VALVE_POSITION.value, int)
assert result.MBUS_VALVE_POSITION.value == 1
# BELGIUM_MBUS2_DEVICE_TYPE (0-2:24.1.0)
assert isinstance(result.BELGIUM_MBUS2_DEVICE_TYPE, CosemObject)
assert result.BELGIUM_MBUS2_DEVICE_TYPE.unit is None
assert isinstance(result.BELGIUM_MBUS2_DEVICE_TYPE.value, int)
assert result.BELGIUM_MBUS2_DEVICE_TYPE.value == 7
# MBUS_METER_READING (0-1:24.2.3)
assert isinstance(mbus1.MBUS_METER_READING, MBusObject)
assert mbus1.MBUS_METER_READING.unit == 'm3'
assert isinstance(mbus1.MBUS_METER_READING.value, Decimal)
assert mbus1.MBUS_METER_READING.value == Decimal('112.384')
# BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER (0-2:96.1.1)
assert isinstance(result.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER, CosemObject)
assert result.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER.unit is None
assert isinstance(result.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER.value, str)
assert result.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER.value == '3853414731323334353637383930'
# MBUS DEVICE 2
mbus2 = result.get_mbus_device_by_channel(2)
# BELGIUM_MBUS2_METER_READING1 (0-1:24.2.1)
assert isinstance(result.BELGIUM_MBUS2_METER_READING1, MBusObject)
assert result.BELGIUM_MBUS2_METER_READING1.unit == 'm3'
assert isinstance(result.BELGIUM_MBUS2_METER_READING1.value, Decimal)
assert result.BELGIUM_MBUS2_METER_READING1.value == Decimal('872.234')
# MBUS_DEVICE_TYPE (0-2:24.1.0)
assert isinstance(mbus2.MBUS_DEVICE_TYPE, CosemObject)
assert mbus2.MBUS_DEVICE_TYPE.unit is None
assert isinstance(mbus2.MBUS_DEVICE_TYPE.value, int)
assert mbus2.MBUS_DEVICE_TYPE.value == 7
# MBUS_EQUIPMENT_IDENTIFIER (0-2:96.1.1)
assert isinstance(mbus2.MBUS_EQUIPMENT_IDENTIFIER, CosemObject)
assert mbus2.MBUS_EQUIPMENT_IDENTIFIER.unit is None
assert isinstance(mbus2.MBUS_EQUIPMENT_IDENTIFIER.value, str)
assert mbus2.MBUS_EQUIPMENT_IDENTIFIER.value == '3853414731323334353637383930'
# MBUS_METER_READING (0-1:24.2.1)
assert isinstance(mbus2.MBUS_METER_READING, MBusObject)
assert mbus2.MBUS_METER_READING.unit == 'm3'
assert isinstance(mbus2.MBUS_METER_READING.value, Decimal)
assert mbus2.MBUS_METER_READING.value == Decimal('872.234')
def test_checksum_valid(self):
# No exception is raised.
@@ -296,6 +302,8 @@ class TelegramParserFluviusTest(unittest.TestCase):
telegram = parser.parse(TELEGRAM_FLUVIUS_V171_ALT)
json_data = json.loads(telegram.to_json())
self.maxDiff = None
self.assertEqual(
json_data,
{'BELGIUM_VERSION_INFORMATION': {'value': '50217', 'unit': None},
@@ -336,29 +344,21 @@ class TelegramParserFluviusTest(unittest.TestCase):
'INSTANTANEOUS_CURRENT_L3': {'value': 0.52, 'unit': 'A'},
'ACTUAL_SWITCH_POSITION': {'value': 1, 'unit': None},
'ACTUAL_TRESHOLD_ELECTRICITY': {'value': 999.9, 'unit': 'kW'},
'BELGIUM_MAX_POWER_PER_PHASE': {'value': 999.9, 'unit': 'kW'},
'BELGIUM_MAX_CURRENT_PER_PHASE': {'value': 999.0, 'unit': 'A'},
'FUSE_THRESHOLD_L1': {'value': 999.0, 'unit': 'A'},
'TEXT_MESSAGE': {'value': None, 'unit': None},
'BELGIUM_MBUS1_DEVICE_TYPE': {'value': 3, 'unit': None},
'MBUS_DEVICES': [{'BELGIUM_MBUS1_DEVICE_TYPE': {'value': 3, 'unit': None},
'BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER': {'value': '37464C4F32313233303838303237',
'MBUS_DEVICES': [{'MBUS_DEVICE_TYPE': {'value': 3, 'unit': None},
'MBUS_EQUIPMENT_IDENTIFIER': {'value': '37464C4F32313233303838303237',
'unit': None},
'BELGIUM_MBUS1_VALVE_POSITION': {'value': 1, 'unit': None},
'BELGIUM_MBUS1_METER_READING2': {'datetime': '2023-11-02T11:10:02+00:00',
'value': 92.287, 'unit': 'm3'},
'MBUS_VALVE_POSITION': {'value': 1, 'unit': None},
'MBUS_METER_READING': {'datetime': '2023-11-02T11:10:02+00:00',
'value': 92.287, 'unit': 'm3'},
'CHANNEL_ID': 1},
{'BELGIUM_MBUS2_DEVICE_TYPE': {'value': 7, 'unit': None},
'BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER': {'value': '3853455430303030393631313733',
{'MBUS_DEVICE_TYPE': {'value': 7, 'unit': None},
'MBUS_EQUIPMENT_IDENTIFIER': {'value': '3853455430303030393631313733',
'unit': None},
'BELGIUM_MBUS2_METER_READING1': {'datetime': '2023-11-02T11:15:32+00:00',
'value': 8.579, 'unit': 'm3'},
'CHANNEL_ID': 2}],
'BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER': {'value': '37464C4F32313233303838303237', 'unit': None},
'BELGIUM_MBUS1_VALVE_POSITION': {'value': 1, 'unit': None},
'BELGIUM_MBUS1_METER_READING2': {'datetime': '2023-11-02T11:10:02+00:00', 'value': 92.287, 'unit': 'm3'},
'BELGIUM_MBUS2_DEVICE_TYPE': {'value': 7, 'unit': None},
'BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER': {'value': '3853455430303030393631313733', 'unit': None},
'BELGIUM_MBUS2_METER_READING1': {'datetime': '2023-11-02T11:15:32+00:00', 'value': 8.579, 'unit': 'm3'}}
'MBUS_METER_READING': {'datetime': '2023-11-02T11:15:32+00:00',
'value': 8.579, 'unit': 'm3'},
'CHANNEL_ID': 2}]}
)
def test_to_str(self):
@@ -398,24 +398,16 @@ class TelegramParserFluviusTest(unittest.TestCase):
'INSTANTANEOUS_CURRENT_L3: 0.52 [A]\n'
'ACTUAL_SWITCH_POSITION: 1 [None]\n'
'ACTUAL_TRESHOLD_ELECTRICITY: 999.9 [kW]\n'
'BELGIUM_MAX_POWER_PER_PHASE: 999.9 [kW]\n'
'BELGIUM_MAX_CURRENT_PER_PHASE: 999 [A]\n'
'FUSE_THRESHOLD_L1: 999 [A]\n'
'TEXT_MESSAGE: None [None]\n'
'BELGIUM_MBUS1_DEVICE_TYPE: 3 [None]\n'
'MBUS DEVICE (channel 1)\n'
' BELGIUM_MBUS1_DEVICE_TYPE: 3 [None]\n'
' BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER: 37464C4F32313233303838303237 [None]\n'
' BELGIUM_MBUS1_VALVE_POSITION: 1 [None]\n'
' BELGIUM_MBUS1_METER_READING2: 92.287 [m3] at 2023-11-02T11:10:02+00:00\n'
' MBUS_DEVICE_TYPE: 3 [None]\n'
' MBUS_EQUIPMENT_IDENTIFIER: 37464C4F32313233303838303237 [None]\n'
' MBUS_VALVE_POSITION: 1 [None]\n'
' MBUS_METER_READING: 92.287 [m3] at 2023-11-02T11:10:02+00:00\n'
'MBUS DEVICE (channel 2)\n'
' BELGIUM_MBUS2_DEVICE_TYPE: 7 [None]\n'
' BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER: 3853455430303030393631313733 [None]\n'
' BELGIUM_MBUS2_METER_READING1: 8.579 [m3] at 2023-11-02T11:15:32+00:00\n'
'BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER: 37464C4F32313233303838303237 [None]\n'
'BELGIUM_MBUS1_VALVE_POSITION: 1 [None]\n'
'BELGIUM_MBUS1_METER_READING2: 92.287 [m3] at 2023-11-02T11:10:02+00:00\n'
'BELGIUM_MBUS2_DEVICE_TYPE: 7 [None]\n'
'BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER: 3853455430303030393631313733 [None]\n'
'BELGIUM_MBUS2_METER_READING1: 8.579 [m3] at 2023-11-02T11:15:32+00:00\n'
' MBUS_DEVICE_TYPE: 7 [None]\n'
' MBUS_EQUIPMENT_IDENTIFIER: 3853455430303030393631313733 [None]\n'
' MBUS_METER_READING: 8.579 [m3] at 2023-11-02T11:15:32+00:00\n'
)
)
+9
View File
@@ -12,6 +12,15 @@ from test.example_telegrams import TELEGRAM_V2_2
class TelegramParserV2_2Test(unittest.TestCase):
""" Test parsing of a DSMR v2.2 telegram. """
def test_telegram_specification_matching(self):
parser = TelegramParser()
parser.parse(TELEGRAM_V2_2)
self.assertEqual(
parser.telegram_specification,
telegram_specifications.V2_2
)
def test_parse(self):
parser = TelegramParser(telegram_specifications.V2_2)
try:
+9
View File
@@ -12,6 +12,15 @@ from test.example_telegrams import TELEGRAM_V3
class TelegramParserV3Test(unittest.TestCase):
""" Test parsing of a DSMR v3 telegram. """
def test_telegram_specification_matching(self):
parser = TelegramParser()
parser.parse(TELEGRAM_V3)
self.assertEqual(
parser.telegram_specification,
telegram_specifications.V3
)
def test_parse(self):
parser = TelegramParser(telegram_specifications.V3)
try:
+9
View File
@@ -15,6 +15,15 @@ from test.example_telegrams import TELEGRAM_V4_2
class TelegramParserV4_2Test(unittest.TestCase):
""" Test parsing of a DSMR v4.2 telegram. """
def test_telegram_specification_matching(self):
parser = TelegramParser()
parser.parse(TELEGRAM_V4_2)
self.assertEqual(
parser.telegram_specification,
telegram_specifications.V4
)
def test_parse(self):
parser = TelegramParser(telegram_specifications.V4)
try:
+33 -27
View File
@@ -15,6 +15,15 @@ from test.example_telegrams import TELEGRAM_V5
class TelegramParserV5Test(unittest.TestCase):
""" Test parsing of a DSMR v5.x telegram. """
def test_telegram_specification_matching(self):
parser = TelegramParser()
parser.parse(TELEGRAM_V5)
self.assertEqual(
parser.telegram_specification,
telegram_specifications.V5
)
def test_parse(self):
parser = TelegramParser(telegram_specifications.V5)
try:
@@ -172,12 +181,6 @@ class TelegramParserV5Test(unittest.TestCase):
assert telegram.TEXT_MESSAGE.unit is None
assert telegram.TEXT_MESSAGE.value is None
# DEVICE_TYPE (0-x:24.1.0)
assert isinstance(telegram.DEVICE_TYPE, CosemObject)
assert telegram.DEVICE_TYPE.unit is None
assert isinstance(telegram.DEVICE_TYPE.value, int)
assert telegram.DEVICE_TYPE.value == 3
# INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE (1-0:21.7.0)
assert isinstance(telegram.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE, CosemObject)
assert telegram.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE.unit == 'kW'
@@ -215,27 +218,27 @@ class TelegramParserV5Test(unittest.TestCase):
assert telegram.INSTANTANEOUS_ACTIVE_POWER_L3_NEGATIVE.value == Decimal('0')
# There's only one Mbus device (gas meter) in this case. Alternatively
# use get_mbget_mbus_device_by_channel
# use get_mbus_device_by_channel
gas_meter_devices = telegram.MBUS_DEVICES
gas_meter_device = gas_meter_devices[0]
# EQUIPMENT_IDENTIFIER_GAS (0-x:96.1.0)
assert isinstance(gas_meter_device.DEVICE_TYPE, CosemObject)
assert gas_meter_device.DEVICE_TYPE.unit is None
assert isinstance(gas_meter_device.DEVICE_TYPE.value, int)
assert gas_meter_device.DEVICE_TYPE.value == 3
# MBUS_DEVICE_TYPE (0-1:96.1.0)
assert isinstance(gas_meter_device.MBUS_DEVICE_TYPE, CosemObject)
assert gas_meter_device.MBUS_DEVICE_TYPE.unit is None
assert isinstance(gas_meter_device.MBUS_DEVICE_TYPE.value, int)
assert gas_meter_device.MBUS_DEVICE_TYPE.value == 3
# EQUIPMENT_IDENTIFIER_GAS (0-x:96.1.0)
assert isinstance(gas_meter_device.EQUIPMENT_IDENTIFIER_GAS, CosemObject)
assert gas_meter_device.EQUIPMENT_IDENTIFIER_GAS.unit is None
assert isinstance(gas_meter_device.EQUIPMENT_IDENTIFIER_GAS.value, str)
assert gas_meter_device.EQUIPMENT_IDENTIFIER_GAS.value == '3232323241424344313233343536373839'
# MBUS_EQUIPMENT_IDENTIFIER (0-1:96.1.0)
assert isinstance(gas_meter_device.MBUS_EQUIPMENT_IDENTIFIER, CosemObject)
assert gas_meter_device.MBUS_EQUIPMENT_IDENTIFIER.unit is None
assert isinstance(gas_meter_device.MBUS_EQUIPMENT_IDENTIFIER.value, str)
assert gas_meter_device.MBUS_EQUIPMENT_IDENTIFIER.value == '3232323241424344313233343536373839'
# HOURLY_GAS_METER_READING (0-1:24.2.1)
assert isinstance(gas_meter_device.HOURLY_GAS_METER_READING, MBusObject)
assert gas_meter_device.HOURLY_GAS_METER_READING.unit == 'm3'
assert isinstance(telegram.HOURLY_GAS_METER_READING.value, Decimal)
assert gas_meter_device.HOURLY_GAS_METER_READING.value == Decimal('0.107')
# MBUS_METER_READING (0-1:24.2.1)
assert isinstance(gas_meter_device.MBUS_METER_READING, MBusObject)
assert gas_meter_device.MBUS_METER_READING.unit == 'm3'
assert isinstance(telegram.MBUS_METER_READING.value, Decimal)
assert gas_meter_device.MBUS_METER_READING.value == Decimal('0.107')
def test_checksum_valid(self):
# No exception is raised.
@@ -270,8 +273,11 @@ class TelegramParserV5Test(unittest.TestCase):
parser = TelegramParser(telegram_specifications.V5)
telegram = parser.parse(invalid_date_telegram)
# HOURLY_GAS_METER_READING (0-1:24.2.1)
assert isinstance(telegram.HOURLY_GAS_METER_READING, MBusObject)
assert telegram.HOURLY_GAS_METER_READING.unit is None
assert isinstance(telegram.HOURLY_GAS_METER_READING.value, Decimal)
assert telegram.HOURLY_GAS_METER_READING.value == Decimal('0.000')
# MBUS DEVICE 1
mbus1 = telegram.get_mbus_device_by_channel(1)
# MBUS_METER_READING (0-1:24.2.1)
assert isinstance(mbus1.MBUS_METER_READING, MBusObject)
assert mbus1.MBUS_METER_READING.unit is None
assert isinstance(mbus1.MBUS_METER_READING.value, Decimal)
assert mbus1.MBUS_METER_READING.value == Decimal('0.000')
+15 -15
View File
@@ -263,23 +263,23 @@ class TelegramParserV5EONHUTest(unittest.TestCase):
assert isinstance(telegram.INSTANTANEOUS_REACTIVE_POWER_Q4.value, Decimal)
assert telegram.INSTANTANEOUS_REACTIVE_POWER_Q4.value == Decimal('00.000')
# EON_HU_MAX_POWER_ON_L1 (1-0:31.4.0)
assert isinstance(telegram.MAX_POWER_ON_L1, CosemObject)
assert telegram.MAX_POWER_ON_L1.unit == 'A'
assert isinstance(telegram.MAX_POWER_ON_L1.value, Decimal)
assert telegram.MAX_POWER_ON_L1.value == Decimal('200.00')
# FUSE_THRESHOLD_L1 (1-0:31.4.0)
assert isinstance(telegram.FUSE_THRESHOLD_L1, CosemObject)
assert telegram.FUSE_THRESHOLD_L1.unit == 'A'
assert isinstance(telegram.FUSE_THRESHOLD_L1.value, Decimal)
assert telegram.FUSE_THRESHOLD_L1.value == Decimal('200.00')
# EON_HU_MAX_POWER_ON_L2 (1-0:31.4.0)
assert isinstance(telegram.MAX_POWER_ON_L2, CosemObject)
assert telegram.MAX_POWER_ON_L2.unit == 'A'
assert isinstance(telegram.MAX_POWER_ON_L2.value, Decimal)
assert telegram.MAX_POWER_ON_L2.value == Decimal('200.00')
# FUSE_THRESHOLD_L2 (1-0:31.4.0)
assert isinstance(telegram.FUSE_THRESHOLD_L2, CosemObject)
assert telegram.FUSE_THRESHOLD_L2.unit == 'A'
assert isinstance(telegram.FUSE_THRESHOLD_L2.value, Decimal)
assert telegram.FUSE_THRESHOLD_L2.value == Decimal('200.00')
# EON_HU_MAX_POWER_ON_L3 (1-0:31.4.0)
assert isinstance(telegram.MAX_POWER_ON_L3, CosemObject)
assert telegram.MAX_POWER_ON_L3.unit == 'A'
assert isinstance(telegram.MAX_POWER_ON_L3.value, Decimal)
assert telegram.MAX_POWER_ON_L3.value == Decimal('200.00')
# FUSE_THRESHOLD_L3 (1-0:31.4.0)
assert isinstance(telegram.FUSE_THRESHOLD_L3, CosemObject)
assert telegram.FUSE_THRESHOLD_L3.unit == 'A'
assert isinstance(telegram.FUSE_THRESHOLD_L3.value, Decimal)
assert telegram.FUSE_THRESHOLD_L3.value == Decimal('200.00')
# TEXT_MESSAGE (0-0:96.13.0)
assert isinstance(telegram.TEXT_MESSAGE, CosemObject)
+1 -1
View File
@@ -68,6 +68,6 @@ class ProtocolTest(unittest.TestCase):
# 2nd call of keep_alive should close the transport
self.protocol.keep_alive()
assert mock_transport.close.called_once()
mock_transport.close.assert_called_once()
self.protocol.connection_lost(None)
+5 -1
View File
@@ -6,6 +6,7 @@ deps=
pytest-asyncio
pytest-mock
dlms_cosem
setuptools
commands=
py.test --cov=dsmr_parser test {posargs}
pylama dsmr_parser test
@@ -13,6 +14,9 @@ commands=
[pylama:dsmr_parser/clients/__init__.py]
ignore = W0611
[pylama:dsmr_parser/clients/socket_.py]
ignore = C901
[pylama:dsmr_parser/parsers.py]
ignore = W605
@@ -23,4 +27,4 @@ ignore = E501
max_line_length = 120
[pylama:pycodestyle]
max_line_length = 120
max_line_length = 120