Skip to content

Commit

Permalink
Updated dsmr_parser (mostly) with latest version in favor of #1794/#1764
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jan 23, 2023
1 parent 9cc561e commit ba721ee
Show file tree
Hide file tree
Showing 11 changed files with 549 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
select = B,C,E,F,I,S,W
ignore = B902,B903,E501,B950,E203,S311,W503
exclude = .venv/*,docs/*,*/migrations/*,*/tests/*,dsmrreader/*,dsmr_plugins/modules/*
exclude = .venv/*,docs/*,*/migrations/*,*/tests/*,dsmrreader/*,dsmr_plugins/modules/*,dsmr_parser/*
max-complexity = 10
max-line-length = 120
1 change: 1 addition & 0 deletions docs/reference/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ v5.10.0 - January 2023

- ``Changed`` [`#1725 <https://github.com/dsmrreader/dsmr-reader/issues/1725>`_] The value of ``DSMRREADER_REMOTE_DATALOGGER_INPUT_METHOD`` is now restricted to: ``DEBUG``, ``WARNING`` or ``ERROR``
- ``Changed`` [`#1725 <https://github.com/dsmrreader/dsmr-reader/issues/1725>`_] The value of ``DSMRREADER_LOGLEVEL`` is now restricted to: ``serial`` or ``ipv4``
- ``Changed`` [`#1794 <https://github.com/dsmrreader/dsmr-reader/issues/1794>`_] [`#1764 <https://github.com/dsmrreader/dsmr-reader/issues/1764>`_] Updated dsmr_parser (mostly) with latest version


v5.9.0 - November 2022
Expand Down
6 changes: 3 additions & 3 deletions dsmr_datalogger/services/datalogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,15 @@ def _get_dsmrreader_mapping(version: int) -> Dict:
if version == DataloggerSettings.DSMR_BELGIUM_FLUVIUS:
mapping.update(
{
obis_references.BELGIUM_HOURLY_GAS_METER_READING: SPLIT_GAS_FIELD,
obis_references.BELGIUM_MBUS_WILDCARD_METER_READING2: SPLIT_GAS_FIELD,
}
)

if version == DataloggerSettings.DSMR_LUXEMBOURG_SMARTY:
mapping.update(
{
obis_references.LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL: "electricity_delivered_1",
obis_references.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL: "electricity_returned_1",
obis_references.ELECTRICITY_IMPORTED_TOTAL: "electricity_delivered_1",
obis_references.ELECTRICITY_EXPORTED_TOTAL: "electricity_returned_1",
}
)

Expand Down
33 changes: 28 additions & 5 deletions dsmr_parser/obis_name_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
obis.ELECTRICITY_IMPORTED_TOTAL: "ELECTRICITY_IMPORTED_TOTAL",
obis.ELECTRICITY_USED_TARIFF_1: "ELECTRICITY_USED_TARIFF_1",
obis.ELECTRICITY_USED_TARIFF_2: "ELECTRICITY_USED_TARIFF_2",
obis.ELECTRICITY_EXPORTED_TOTAL: "ELECTRICITY_EXPORTED_TOTAL",
obis.ELECTRICITY_DELIVERED_TARIFF_1: "ELECTRICITY_DELIVERED_TARIFF_1",
obis.ELECTRICITY_DELIVERED_TARIFF_2: "ELECTRICITY_DELIVERED_TARIFF_2",
obis.ELECTRICITY_ACTIVE_TARIFF: "ELECTRICITY_ACTIVE_TARIFF",
Expand Down Expand Up @@ -49,12 +50,34 @@
obis.ACTUAL_TRESHOLD_ELECTRICITY: "ACTUAL_TRESHOLD_ELECTRICITY",
obis.ACTUAL_SWITCH_POSITION: "ACTUAL_SWITCH_POSITION",
obis.VALVE_POSITION_GAS: "VALVE_POSITION_GAS",
obis.BELGIUM_HOURLY_GAS_METER_READING: "BELGIUM_HOURLY_GAS_METER_READING",
obis.BELGIUM_VERSION_INFORMATION: "BELGIUM_VERSION_INFORMATION",
obis.BELGIUM_EQUIPMENT_IDENTIFIER: "BELGIUM_EQUIPMENT_IDENTIFIER",
obis.BELGIUM_CURRENT_AVERAGE_DEMAND: "BELGIUM_CURRENT_AVERAGE_DEMAND",
obis.BELGIUM_MAXIMUM_DEMAND_MONTH: "BELGIUM_MAXIMUM_DEMAND_MONTH",
obis.BELGIUM_MAXIMUM_DEMAND_13_MONTHS: "BELGIUM_MAXIMUM_DEMAND_13_MONTHS",
obis.BELGIUM_MAX_POWER_PER_PHASE: "BELGIUM_MAX_POWER_PER_PHASE",
obis.BELGIUM_MAX_CURRENT_PER_PHASE: "BELGIUM_MAX_CURRENT_PER_PHASE",
obis.BELGIUM_MBUS1_DEVICE_TYPE: "BELGIUM_MBUS1_DEVICE_TYPE",
obis.BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER: "BELGIUM_MBUS1_EQUIPMENT_IDENTIFIER",
obis.BELGIUM_MBUS1_VALVE_POSITION: "BELGIUM_MBUS1_VALVE_POSITION",
obis.BELGIUM_MBUS1_METER_READING1: "BELGIUM_MBUS1_METER_READING1",
obis.BELGIUM_MBUS1_METER_READING2: "BELGIUM_MBUS1_METER_READING2",
obis.BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER: "BELGIUM_MBUS2_EQUIPMENT_IDENTIFIER",
obis.BELGIUM_MBUS2_VALVE_POSITION: "BELGIUM_MBUS2_VALVE_POSITION",
obis.BELGIUM_MBUS2_METER_READING1: "BELGIUM_MBUS2_METER_READING1",
obis.BELGIUM_MBUS2_METER_READING2: "BELGIUM_MBUS2_METER_READING2",
obis.BELGIUM_MBUS3_EQUIPMENT_IDENTIFIER: "BELGIUM_MBUS3_EQUIPMENT_IDENTIFIER",
obis.BELGIUM_MBUS3_VALVE_POSITION: "BELGIUM_MBUS3_VALVE_POSITION",
obis.BELGIUM_MBUS3_METER_READING1: "BELGIUM_MBUS3_METER_READING1",
obis.BELGIUM_MBUS3_METER_READING2: "BELGIUM_MBUS3_METER_READING2",
obis.BELGIUM_MBUS4_EQUIPMENT_IDENTIFIER: "BELGIUM_MBUS4_EQUIPMENT_IDENTIFIER",
obis.BELGIUM_MBUS4_VALVE_POSITION: "BELGIUM_MBUS4_VALVE_POSITION",
obis.BELGIUM_MBUS4_METER_READING1: "BELGIUM_MBUS4_METER_READING1",
obis.BELGIUM_MBUS4_METER_READING2: "BELGIUM_MBUS4_METER_READING2",
obis.LUXEMBOURG_EQUIPMENT_IDENTIFIER: "LUXEMBOURG_EQUIPMENT_IDENTIFIER",
obis.LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL: "LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL",
obis.LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL: "LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL",
obis.SWEDEN_ELECTRICITY_USED_TARIFF_GLOBAL: "SWEDEN_ELECTRICITY_USED_TARIFF_GLOBAL",
obis.SWEDEN_ELECTRICITY_DELIVERED_TARIFF_GLOBAL: "SWEDEN_ELECTRICITY_DELIVERED_TARIFF_GLOBAL",
obis.Q3D_EQUIPMENT_IDENTIFIER: "Q3D_EQUIPMENT_IDENTIFIER",
obis.Q3D_EQUIPMENT_STATE: "Q3D_EQUIPMENT_STATE",
obis.Q3D_EQUIPMENT_SERIALNUMBER: "Q3D_EQUIPMENT_SERIALNUMBER",
}

REVERSE_EN = dict([(v, k) for k, v in EN.items()])
77 changes: 65 additions & 12 deletions dsmr_parser/obis_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
"""
P1_MESSAGE_HEADER = r"\d-\d:0\.2\.8.+?\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_2 = r"\d-\d:1\.8\.2.+?\r\n"
ELECTRICITY_DELIVERED_TARIFF_1 = r"\d-\d:2\.8\.1.+?\r\n"
ELECTRICITY_DELIVERED_TARIFF_2 = r"\d-\d:2\.8\.2.+?\r\n"
CURRENT_REACTIVE_EXPORTED = r"\d-\d:3\.7\.0.+?\r\n"
ELECTRICITY_REACTIVE_IMPORTED_TOTAL = r"\d-\d:3\.8\.0.+?\r\n"
ELECTRICITY_REACTIVE_IMPORTED_TARIFF_1 = r"\d-\d:3\.8\.1.+?\r\n"
ELECTRICITY_REACTIVE_IMPORTED_TARIFF_2 = r"\d-\d:3\.8\.2.+?\r\n"
CURRENT_REACTIVE_IMPORTED = r"\d-\d:4\.7\.0.+?\r\n"
ELECTRICITY_REACTIVE_EXPORTED_TOTAL = r"\d-\d:4\.8\.0.+?\r\n"
ELECTRICITY_REACTIVE_EXPORTED_TARIFF_1 = r"\d-\d:4\.8\.1.+?\r\n"
ELECTRICITY_REACTIVE_EXPORTED_TARIFF_2 = r"\d-\d:4\.8\.2.+?\r\n"
ELECTRICITY_ACTIVE_TARIFF = r"\d-\d:96\.14\.0.+?\r\n"
EQUIPMENT_IDENTIFIER = r"\d-\d:96\.1\.1.+?\r\n"
CURRENT_ELECTRICITY_USAGE = r"\d-\d:1\.7\.0.+?\r\n"
Expand Down Expand Up @@ -58,20 +65,66 @@
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_EQUIPMENT_IDENTIFIER = r"\d-\d:42\.0\.0.+?\r\n" # Logical device name
LUXEMBOURG_ELECTRICITY_USED_TARIFF_GLOBAL = (
# International generalized additions
ELECTRICITY_IMPORTED_TOTAL = (
r"\d-\d:1\.8\.0.+?\r\n" # Total imported energy register (P+)
)
LUXEMBOURG_ELECTRICITY_DELIVERED_TARIFF_GLOBAL = (
ELECTRICITY_EXPORTED_TOTAL = (
r"\d-\d:2\.8\.0.+?\r\n" # Total exported energy register (P-)
)
SWEDEN_ELECTRICITY_USED_TARIFF_GLOBAL = (
r"\d-\d:1\.8\.0.+?\r\n" # Total imported energy register (P+)

# International non generalized additions (country specific) / risk for necessary refactoring
BELGIUM_VERSION_INFORMATION = r"\d-\d:96\.1\.4.+?\r\n"
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
)
SWEDEN_ELECTRICITY_DELIVERED_TARIFF_GLOBAL = (
r"\d-\d:2\.8\.0.+?\r\n" # Total exported energy register (P-)
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"

# DSMR-reader legacy. Should eventually be dropped or selected automatically in a future release.
BELGIUM_MBUS_WILDCARD_DEVICE_TYPE = r"\d-\d:24\.1\.0.+?\r\n"
BELGIUM_MBUS_WILDCARD_EQUIPMENT_IDENTIFIER = r"\d-\d:96\.1\.1.+?\r\n"
BELGIUM_MBUS_WILDCARD_VALVE_POSITION = r"\d-\d:24\.4\.0.+?\r\n"
BELGIUM_MBUS_WILDCARD_METER_READING1 = r"\d-\d:24\.2\.1.+?\r\n"
BELGIUM_MBUS_WILDCARD_METER_READING2 = r"\d-\d:24\.2\.3.+?\r\n"


LUXEMBOURG_EQUIPMENT_IDENTIFIER = r"\d-\d:42\.0\.0.+?\r\n" # Logical device name

Q3D_EQUIPMENT_IDENTIFIER = r"\d-\d:0\.0\.0.+?\r\n" # Logical device name
Q3D_EQUIPMENT_STATE = r"\d-\d:96\.5\.5.+?\r\n" # Device state (hexadecimal)
Q3D_EQUIPMENT_SERIALNUMBER = r"\d-\d:96\.1\.255.+?\r\n" # Device Serialnumber
47 changes: 47 additions & 0 deletions dsmr_parser/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,53 @@ def to_json(self):
return json.dumps(output)


class MBusObjectPeak(DSMRObject):
@property
def datetime(self):
return self.values[0]["value"]

@property
def occurred(self):
return self.values[1]["value"]

@property
def value(self):
return self.values[2]["value"]

@property
def unit(self):
return self.values[2]["unit"]

def __str__(self):
output = "{}\t[{}] at {} occurred {}".format(
str(self.value),
str(self.unit),
str(self.datetime.astimezone().isoformat()),
str(self.occurred.astimezone().isoformat()),
)
return output

def to_json(self):
timestamp = self.datetime
if isinstance(self.datetime, datetime.datetime):
timestamp = self.datetime.astimezone().isoformat()
timestamp_occurred = self.occurred
if isinstance(self.occurred, datetime.datetime):
timestamp_occurred = self.occurred.astimezone().isoformat()
value = self.value
if isinstance(self.value, datetime.datetime):
value = self.value.astimezone().isoformat()
if isinstance(self.value, Decimal):
value = float(self.value)
output = {
"datetime": timestamp,
"occurred": timestamp_occurred,
"value": value,
"unit": self.unit,
}
return json.dumps(output)


class CosemObject(DSMRObject):
@property
def value(self):
Expand Down
Loading

0 comments on commit ba721ee

Please sign in to comment.