Compare commits
31
Commits
development
...
v0.15
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12aa003799 | ||
|
|
86690ef44b | ||
|
|
7c9c59308e | ||
|
|
b31bcd61fc | ||
|
|
50a5cb9203 | ||
|
|
8388624721 | ||
|
|
c04b0a5add | ||
|
|
ed2290a597 | ||
|
|
85c67464a1 | ||
|
|
48783acc00 | ||
|
|
41f6a7ac16 | ||
|
|
59811dbf9f | ||
|
|
9b09969763 | ||
|
|
64f5dc2e87 | ||
|
|
887dd3a2aa | ||
|
|
ad6ab304f5 | ||
|
|
8582395017 | ||
|
|
3327c78c0e | ||
|
|
472c54968e | ||
|
|
d534b1d8b0 | ||
|
|
d94bc8de03 | ||
|
|
41381f1705 | ||
|
|
e3203a5334 | ||
|
|
c78ebe3e2d | ||
|
|
d6e28db116 | ||
|
|
5f1afeb1f8 | ||
|
|
dcb59fddb1 | ||
|
|
9b0a85e84b | ||
|
|
1dca6ab396 | ||
|
|
efc09df71f | ||
|
|
de5c884d8d |
@@ -1,6 +1,37 @@
|
|||||||
Change Log
|
Change Log
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
**0.15** (2019-12-12)
|
||||||
|
|
||||||
|
- Fixed asyncio loop issue (`pull request #37 <https://github.com/ndokter/dsmr_parser/pull/36>`_).
|
||||||
|
|
||||||
|
**0.14** (2019-10-08)
|
||||||
|
|
||||||
|
- Changed serial reading to reduce CPU usage (`pull request #37 <https://github.com/ndokter/dsmr_parser/pull/37>`_).
|
||||||
|
|
||||||
|
**0.13** (2019-03-04)
|
||||||
|
|
||||||
|
- Fix DSMR v5.0 serial settings which were not used (`pull request #33 <https://github.com/ndokter/dsmr_parser/pull/33>`_).
|
||||||
|
|
||||||
|
**0.12** (2018-09-23)
|
||||||
|
|
||||||
|
- Add serial settings for DSMR v5.0 (`pull request #31 <https://github.com/ndokter/dsmr_parser/pull/31>`_).
|
||||||
|
- Lux-creos-obis-1.8.0 (`pull request #32 <https://github.com/ndokter/dsmr_parser/pull/32>`_).
|
||||||
|
|
||||||
|
**0.11** (2017-09-18)
|
||||||
|
|
||||||
|
- NULL value fix in checksum (`pull request #26 <https://github.com/ndokter/dsmr_parser/pull/26>`_)
|
||||||
|
|
||||||
|
**0.10** (2017-06-05)
|
||||||
|
|
||||||
|
- bugix: don't force full telegram signatures (`pull request #25 <https://github.com/ndokter/dsmr_parser/pull/25>`_)
|
||||||
|
- removed unused code for automatic telegram detection as this needs reworking after the fix mentioned above
|
||||||
|
- InvalidChecksumError's are logged as warning instead of error
|
||||||
|
|
||||||
|
**0.9** (2017-05-12)
|
||||||
|
|
||||||
|
- added DSMR v5 serial settings
|
||||||
|
|
||||||
**0.8** (2017-01-26)
|
**0.8** (2017-01-26)
|
||||||
|
|
||||||
- added support for DSMR v3
|
- added support for DSMR v3
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ into a dictionary.
|
|||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
|
|
||||||
|
# String is formatted in separate lines for readability.
|
||||||
telegram_str = (
|
telegram_str = (
|
||||||
'/ISk5\2MT382-1000\r\n'
|
'/ISk5\2MT382-1000\r\n'
|
||||||
'\r\n'
|
'\r\n'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
||||||
SERIAL_SETTINGS_V4
|
SERIAL_SETTINGS_V4, SERIAL_SETTINGS_V5
|
||||||
from dsmr_parser.clients.serial_ import SerialReader, AsyncSerialReader
|
from dsmr_parser.clients.serial_ import SerialReader, AsyncSerialReader
|
||||||
from dsmr_parser.clients.protocol import create_dsmr_protocol, \
|
from dsmr_parser.clients.protocol import create_dsmr_protocol, \
|
||||||
create_dsmr_reader, create_tcp_dsmr_reader
|
create_dsmr_reader, create_tcp_dsmr_reader
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ from serial_asyncio import create_serial_connection
|
|||||||
|
|
||||||
from dsmr_parser import telegram_specifications
|
from dsmr_parser import telegram_specifications
|
||||||
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
||||||
from dsmr_parser.exceptions import ParseError
|
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
from dsmr_parser.clients.settings import SERIAL_SETTINGS_V2_2, \
|
||||||
SERIAL_SETTINGS_V4
|
SERIAL_SETTINGS_V4, SERIAL_SETTINGS_V5
|
||||||
|
|
||||||
|
|
||||||
def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
||||||
@@ -23,6 +23,9 @@ def create_dsmr_protocol(dsmr_version, telegram_callback, loop=None):
|
|||||||
elif dsmr_version == '4':
|
elif dsmr_version == '4':
|
||||||
specification = telegram_specifications.V4
|
specification = telegram_specifications.V4
|
||||||
serial_settings = SERIAL_SETTINGS_V4
|
serial_settings = SERIAL_SETTINGS_V4
|
||||||
|
elif dsmr_version == '5':
|
||||||
|
specification = telegram_specifications.V5
|
||||||
|
serial_settings = SERIAL_SETTINGS_V5
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("No telegram parser found for version: %s",
|
raise NotImplementedError("No telegram parser found for version: %s",
|
||||||
dsmr_version)
|
dsmr_version)
|
||||||
@@ -46,12 +49,13 @@ def create_dsmr_reader(port, dsmr_version, telegram_callback, loop=None):
|
|||||||
def create_tcp_dsmr_reader(host, port, dsmr_version,
|
def create_tcp_dsmr_reader(host, port, dsmr_version,
|
||||||
telegram_callback, loop=None):
|
telegram_callback, loop=None):
|
||||||
"""Creates a DSMR asyncio protocol coroutine using TCP connection."""
|
"""Creates a DSMR asyncio protocol coroutine using TCP connection."""
|
||||||
|
if not loop:
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
protocol, _ = create_dsmr_protocol(
|
protocol, _ = create_dsmr_protocol(
|
||||||
dsmr_version, telegram_callback, loop=None)
|
dsmr_version, telegram_callback, loop=loop)
|
||||||
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."""
|
||||||
|
|
||||||
@@ -98,6 +102,8 @@ class DSMRProtocol(asyncio.Protocol):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
parsed_telegram = self.telegram_parser.parse(telegram)
|
parsed_telegram = self.telegram_parser.parse(telegram)
|
||||||
|
except InvalidChecksumError as e:
|
||||||
|
self.log.warning(str(e))
|
||||||
except ParseError:
|
except ParseError:
|
||||||
self.log.exception("failed to parse telegram")
|
self.log.exception("failed to parse telegram")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import serial
|
|||||||
import serial_asyncio
|
import serial_asyncio
|
||||||
|
|
||||||
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
from dsmr_parser.clients.telegram_buffer import TelegramBuffer
|
||||||
from dsmr_parser.exceptions import ParseError
|
from dsmr_parser.exceptions import ParseError, InvalidChecksumError
|
||||||
from dsmr_parser.parsers import TelegramParser
|
from dsmr_parser.parsers import TelegramParser
|
||||||
|
|
||||||
|
|
||||||
@@ -30,12 +30,14 @@ class SerialReader(object):
|
|||||||
"""
|
"""
|
||||||
with serial.Serial(**self.serial_settings) as serial_handle:
|
with serial.Serial(**self.serial_settings) as serial_handle:
|
||||||
while True:
|
while True:
|
||||||
data = serial_handle.readline()
|
data = serial_handle.read(max(1, min(1024, serial_handle.in_waiting)))
|
||||||
self.telegram_buffer.append(data.decode('ascii'))
|
self.telegram_buffer.append(data.decode('ascii'))
|
||||||
|
|
||||||
for telegram in self.telegram_buffer.get_all():
|
for telegram in self.telegram_buffer.get_all():
|
||||||
try:
|
try:
|
||||||
yield self.telegram_parser.parse(telegram)
|
yield self.telegram_parser.parse(telegram)
|
||||||
|
except InvalidChecksumError as e:
|
||||||
|
logger.warning(str(e))
|
||||||
except ParseError as e:
|
except ParseError as e:
|
||||||
logger.error('Failed to parse telegram: %s', e)
|
logger.error('Failed to parse telegram: %s', e)
|
||||||
|
|
||||||
|
|||||||
@@ -20,3 +20,13 @@ SERIAL_SETTINGS_V4 = {
|
|||||||
'rtscts': 0,
|
'rtscts': 0,
|
||||||
'timeout': 20
|
'timeout': 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SERIAL_SETTINGS_V5 = {
|
||||||
|
'baudrate': 115200,
|
||||||
|
'bytesize': serial.EIGHTBITS,
|
||||||
|
'parity': serial.PARITY_NONE,
|
||||||
|
'stopbits': serial.STOPBITS_ONE,
|
||||||
|
'xonxoff': 0,
|
||||||
|
'rtscts': 0,
|
||||||
|
'timeout': 20
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class TelegramBuffer(object):
|
|||||||
# - The checksum is optional '{0,4}' because not all telegram versions
|
# - The checksum is optional '{0,4}' because not all telegram versions
|
||||||
# support it.
|
# support it.
|
||||||
return re.findall(
|
return re.findall(
|
||||||
r'\/[^\/]+?\![A-F0-9]{0,4}\r\n',
|
r'\/[^\/]+?\![A-F0-9]{0,4}\0?\r\n',
|
||||||
self._buffer,
|
self._buffer,
|
||||||
re.DOTALL
|
re.DOTALL
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ objects are introduced.
|
|||||||
"""
|
"""
|
||||||
P1_MESSAGE_HEADER = r'\d-\d:0\.2\.8.+?\r\n'
|
P1_MESSAGE_HEADER = r'\d-\d:0\.2\.8.+?\r\n'
|
||||||
P1_MESSAGE_TIMESTAMP = r'\d-\d:1\.0\.0.+?\r\n'
|
P1_MESSAGE_TIMESTAMP = r'\d-\d:1\.0\.0.+?\r\n'
|
||||||
|
ELECTRICITY_IMPORTED_TOTAL = r'\d-\d:1\.8\.0.+?\r\n'
|
||||||
ELECTRICITY_USED_TARIFF_1 = r'\d-\d:1\.8\.1.+?\r\n'
|
ELECTRICITY_USED_TARIFF_1 = r'\d-\d:1\.8\.1.+?\r\n'
|
||||||
ELECTRICITY_USED_TARIFF_2 = r'\d-\d:1\.8\.2.+?\r\n'
|
ELECTRICITY_USED_TARIFF_2 = r'\d-\d:1\.8\.2.+?\r\n'
|
||||||
ELECTRICITY_DELIVERED_TARIFF_1 = r'\d-\d:2\.8\.1.+?\r\n'
|
ELECTRICITY_DELIVERED_TARIFF_1 = r'\d-\d:2\.8\.1.+?\r\n'
|
||||||
@@ -17,6 +18,7 @@ EQUIPMENT_IDENTIFIER = r'\d-\d:96\.1\.1.+?\r\n'
|
|||||||
CURRENT_ELECTRICITY_USAGE = r'\d-\d:1\.7\.0.+?\r\n'
|
CURRENT_ELECTRICITY_USAGE = r'\d-\d:1\.7\.0.+?\r\n'
|
||||||
CURRENT_ELECTRICITY_DELIVERY = r'\d-\d:2\.7\.0.+?\r\n'
|
CURRENT_ELECTRICITY_DELIVERY = r'\d-\d:2\.7\.0.+?\r\n'
|
||||||
LONG_POWER_FAILURE_COUNT = r'96\.7\.9.+?\r\n'
|
LONG_POWER_FAILURE_COUNT = r'96\.7\.9.+?\r\n'
|
||||||
|
SHORT_POWER_FAILURE_COUNT = r'96\.7\.21.+?\r\n'
|
||||||
POWER_EVENT_FAILURE_LOG = r'99\.97\.0.+?\r\n'
|
POWER_EVENT_FAILURE_LOG = r'99\.97\.0.+?\r\n'
|
||||||
VOLTAGE_SAG_L1_COUNT = r'\d-\d:32\.32\.0.+?\r\n'
|
VOLTAGE_SAG_L1_COUNT = r'\d-\d:32\.32\.0.+?\r\n'
|
||||||
VOLTAGE_SAG_L2_COUNT = r'\d-\d:52\.32\.0.+?\r\n'
|
VOLTAGE_SAG_L2_COUNT = r'\d-\d:52\.32\.0.+?\r\n'
|
||||||
@@ -24,6 +26,12 @@ VOLTAGE_SAG_L3_COUNT = r'\d-\d:72\.32\.0.+?\r\n'
|
|||||||
VOLTAGE_SWELL_L1_COUNT = r'\d-\d:32\.36\.0.+?\r\n'
|
VOLTAGE_SWELL_L1_COUNT = r'\d-\d:32\.36\.0.+?\r\n'
|
||||||
VOLTAGE_SWELL_L2_COUNT = r'\d-\d:52\.36\.0.+?\r\n'
|
VOLTAGE_SWELL_L2_COUNT = r'\d-\d:52\.36\.0.+?\r\n'
|
||||||
VOLTAGE_SWELL_L3_COUNT = r'\d-\d:72\.36\.0.+?\r\n'
|
VOLTAGE_SWELL_L3_COUNT = r'\d-\d:72\.36\.0.+?\r\n'
|
||||||
|
INSTANTANEOUS_VOLTAGE_L1 = r'\d-\d:32\.7\.0.+?\r\n'
|
||||||
|
INSTANTANEOUS_VOLTAGE_L2 = r'\d-\d:52\.7\.0.+?\r\n'
|
||||||
|
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'
|
||||||
TEXT_MESSAGE_CODE = r'\d-\d:96\.13\.1.+?\r\n'
|
TEXT_MESSAGE_CODE = r'\d-\d:96\.13\.1.+?\r\n'
|
||||||
TEXT_MESSAGE = r'\d-\d:96\.13\.0.+?\r\n'
|
TEXT_MESSAGE = r'\d-\d:96\.13\.0.+?\r\n'
|
||||||
DEVICE_TYPE = r'\d-\d:24\.1\.0.+?\r\n'
|
DEVICE_TYPE = r'\d-\d:24\.1\.0.+?\r\n'
|
||||||
|
|||||||
+8
-34
@@ -51,12 +51,10 @@ class TelegramParser(object):
|
|||||||
for signature, parser in self.telegram_specification['objects'].items():
|
for signature, parser in self.telegram_specification['objects'].items():
|
||||||
match = re.search(signature, telegram_data, re.DOTALL)
|
match = re.search(signature, telegram_data, re.DOTALL)
|
||||||
|
|
||||||
# All telegram specification lines/signatures are expected to be
|
# Some signatures are optional and may not be present,
|
||||||
# present.
|
# so only parse lines that match
|
||||||
if not match:
|
if match:
|
||||||
raise ParseError('Telegram specification does not match '
|
telegram[signature] = parser.parse(match.group(0))
|
||||||
'telegram data')
|
|
||||||
telegram[signature] = parser.parse(match.group(0))
|
|
||||||
|
|
||||||
return telegram
|
return telegram
|
||||||
|
|
||||||
@@ -94,31 +92,6 @@ class TelegramParser(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class DSMRObjectParser(object):
|
class DSMRObjectParser(object):
|
||||||
"""
|
"""
|
||||||
Parses an object (can also be see as a 'line') from a telegram.
|
Parses an object (can also be see as a 'line') from a telegram.
|
||||||
@@ -176,10 +149,11 @@ class CosemParser(DSMRObjectParser):
|
|||||||
1 23 45
|
1 23 45
|
||||||
|
|
||||||
1) OBIS Reduced ID-code
|
1) OBIS Reduced ID-code
|
||||||
2) Separator “(“, ASCII 28h
|
2) Separator "(", ASCII 28h
|
||||||
3) COSEM object attribute value
|
3) COSEM object attribute value
|
||||||
4) Unit of measurement values (Unit of capture objects attribute) – only if applicable
|
4) Unit of measurement values (Unit of capture objects attribute) - only if
|
||||||
5) Separator “)”, ASCII 29h
|
applicable
|
||||||
|
5) Separator ")", ASCII 29h
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def parse(self, line):
|
def parse(self, line):
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ V5 = {
|
|||||||
obis.P1_MESSAGE_HEADER: CosemParser(ValueParser(str)),
|
obis.P1_MESSAGE_HEADER: CosemParser(ValueParser(str)),
|
||||||
obis.P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)),
|
obis.P1_MESSAGE_TIMESTAMP: CosemParser(ValueParser(timestamp)),
|
||||||
obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
|
obis.EQUIPMENT_IDENTIFIER: CosemParser(ValueParser(str)),
|
||||||
|
obis.ELECTRICITY_IMPORTED_TOTAL: CosemParser(ValueParser(Decimal)),
|
||||||
obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
obis.ELECTRICITY_USED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
||||||
obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
|
obis.ELECTRICITY_USED_TARIFF_2: CosemParser(ValueParser(Decimal)),
|
||||||
obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
obis.ELECTRICITY_DELIVERED_TARIFF_1: CosemParser(ValueParser(Decimal)),
|
||||||
@@ -96,6 +97,7 @@ V5 = {
|
|||||||
obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
|
obis.CURRENT_ELECTRICITY_USAGE: CosemParser(ValueParser(Decimal)),
|
||||||
obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
|
obis.CURRENT_ELECTRICITY_DELIVERY: CosemParser(ValueParser(Decimal)),
|
||||||
obis.LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
|
obis.LONG_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
|
||||||
|
obis.SHORT_POWER_FAILURE_COUNT: CosemParser(ValueParser(int)),
|
||||||
# POWER_EVENT_FAILURE_LOG: ProfileGenericParser(), TODO
|
# POWER_EVENT_FAILURE_LOG: ProfileGenericParser(), TODO
|
||||||
obis.VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)),
|
obis.VOLTAGE_SAG_L1_COUNT: CosemParser(ValueParser(int)),
|
||||||
obis.VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)),
|
obis.VOLTAGE_SAG_L2_COUNT: CosemParser(ValueParser(int)),
|
||||||
@@ -103,6 +105,12 @@ V5 = {
|
|||||||
obis.VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)),
|
obis.VOLTAGE_SWELL_L1_COUNT: CosemParser(ValueParser(int)),
|
||||||
obis.VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)),
|
obis.VOLTAGE_SWELL_L2_COUNT: CosemParser(ValueParser(int)),
|
||||||
obis.VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)),
|
obis.VOLTAGE_SWELL_L3_COUNT: CosemParser(ValueParser(int)),
|
||||||
|
obis.INSTANTANEOUS_VOLTAGE_L1: CosemParser(ValueParser(Decimal)),
|
||||||
|
obis.INSTANTANEOUS_VOLTAGE_L2: CosemParser(ValueParser(Decimal)),
|
||||||
|
obis.INSTANTANEOUS_VOLTAGE_L3: CosemParser(ValueParser(Decimal)),
|
||||||
|
obis.INSTANTANEOUS_CURRENT_L1: CosemParser(ValueParser(Decimal)),
|
||||||
|
obis.INSTANTANEOUS_CURRENT_L2: CosemParser(ValueParser(Decimal)),
|
||||||
|
obis.INSTANTANEOUS_CURRENT_L3: CosemParser(ValueParser(Decimal)),
|
||||||
obis.TEXT_MESSAGE: CosemParser(ValueParser(str)),
|
obis.TEXT_MESSAGE: CosemParser(ValueParser(str)),
|
||||||
obis.DEVICE_TYPE: CosemParser(ValueParser(int)),
|
obis.DEVICE_TYPE: CosemParser(ValueParser(int)),
|
||||||
obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)),
|
obis.INSTANTANEOUS_ACTIVE_POWER_L1_POSITIVE: CosemParser(ValueParser(Decimal)),
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ setup(
|
|||||||
name='dsmr-parser',
|
name='dsmr-parser',
|
||||||
description='Library to parse Dutch Smart Meter Requirements (DSMR)',
|
description='Library to parse Dutch Smart Meter Requirements (DSMR)',
|
||||||
author='Nigel Dokter',
|
author='Nigel Dokter',
|
||||||
author_email='nigeldokter@gmail.com',
|
author_email='nigel@nldr.net',
|
||||||
url='https://github.com/ndokter/dsmr_parser',
|
url='https://github.com/ndokter/dsmr_parser',
|
||||||
version='0.8',
|
version='0.15',
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'pyserial>=3,<4',
|
'pyserial>=3,<4',
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import unittest
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -87,6 +87,12 @@ class TelegramParserV5Test(unittest.TestCase):
|
|||||||
assert isinstance(result[obis.LONG_POWER_FAILURE_COUNT].value, int)
|
assert isinstance(result[obis.LONG_POWER_FAILURE_COUNT].value, int)
|
||||||
assert result[obis.LONG_POWER_FAILURE_COUNT].value == 0
|
assert result[obis.LONG_POWER_FAILURE_COUNT].value == 0
|
||||||
|
|
||||||
|
# SHORT_POWER_FAILURE_COUNT (1-0:96.7.21)
|
||||||
|
assert isinstance(result[obis.SHORT_POWER_FAILURE_COUNT], CosemObject)
|
||||||
|
assert result[obis.SHORT_POWER_FAILURE_COUNT].unit is None
|
||||||
|
assert isinstance(result[obis.SHORT_POWER_FAILURE_COUNT].value, int)
|
||||||
|
assert result[obis.SHORT_POWER_FAILURE_COUNT].value == 13
|
||||||
|
|
||||||
# VOLTAGE_SAG_L1_COUNT (1-0:32.32.0)
|
# VOLTAGE_SAG_L1_COUNT (1-0:32.32.0)
|
||||||
assert isinstance(result[obis.VOLTAGE_SAG_L1_COUNT], CosemObject)
|
assert isinstance(result[obis.VOLTAGE_SAG_L1_COUNT], CosemObject)
|
||||||
assert result[obis.VOLTAGE_SAG_L1_COUNT].unit is None
|
assert result[obis.VOLTAGE_SAG_L1_COUNT].unit is None
|
||||||
@@ -123,6 +129,42 @@ class TelegramParserV5Test(unittest.TestCase):
|
|||||||
assert isinstance(result[obis.VOLTAGE_SWELL_L3_COUNT].value, int)
|
assert isinstance(result[obis.VOLTAGE_SWELL_L3_COUNT].value, int)
|
||||||
assert result[obis.VOLTAGE_SWELL_L3_COUNT].value == 0
|
assert result[obis.VOLTAGE_SWELL_L3_COUNT].value == 0
|
||||||
|
|
||||||
|
# INSTANTANEOUS_VOLTAGE_L1 (1-0:32.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L1], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L1].unit == 'V'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L1].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L1].value == Decimal('230.0')
|
||||||
|
|
||||||
|
# INSTANTANEOUS_VOLTAGE_L2 (1-0:52.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L2], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L2].unit == 'V'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L2].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L2].value == Decimal('230.0')
|
||||||
|
|
||||||
|
# INSTANTANEOUS_VOLTAGE_L3 (1-0:72.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L3], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L3].unit == 'V'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_VOLTAGE_L3].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_VOLTAGE_L3].value == Decimal('229.0')
|
||||||
|
|
||||||
|
# INSTANTANEOUS_CURRENT_L1 (1-0:31.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L1], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L1].unit == 'A'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L1].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L1].value == Decimal('0.48')
|
||||||
|
|
||||||
|
# INSTANTANEOUS_CURRENT_L2 (1-0:51.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L2], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L2].unit == 'A'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L2].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L2].value == Decimal('0.44')
|
||||||
|
|
||||||
|
# INSTANTANEOUS_CURRENT_L3 (1-0:71.7.0)
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L3], CosemObject)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L3].unit == 'A'
|
||||||
|
assert isinstance(result[obis.INSTANTANEOUS_CURRENT_L3].value, Decimal)
|
||||||
|
assert result[obis.INSTANTANEOUS_CURRENT_L3].value == Decimal('0.86')
|
||||||
|
|
||||||
# TEXT_MESSAGE (0-0:96.13.0)
|
# TEXT_MESSAGE (0-0:96.13.0)
|
||||||
assert isinstance(result[obis.TEXT_MESSAGE], CosemObject)
|
assert isinstance(result[obis.TEXT_MESSAGE], CosemObject)
|
||||||
assert result[obis.TEXT_MESSAGE].unit is None
|
assert result[obis.TEXT_MESSAGE].unit is None
|
||||||
|
|||||||
Reference in New Issue
Block a user