ndokter / dsmr_parser

Library to parse Dutch Smart Meter Requirements (DSMR) telegrams.
MIT License
110 stars 64 forks source link

issue#60 resolved issue with x-x:24.3.0 where it contains non-integer… #61

Closed lowdef closed 3 years ago

lowdef commented 3 years ago

… characters, parse 2nd value as string instead of integer

codecov-io commented 3 years ago

Codecov Report

Merging #61 into master will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #61   +/-   ##
=======================================
  Coverage   59.19%   59.19%           
=======================================
  Files          15       15           
  Lines         549      549           
  Branches       63       63           
=======================================
  Hits          325      325           
  Misses        221      221           
  Partials        3        3           
Impacted Files Coverage Δ
dsmr_parser/telegram_specifications.py 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 0427ace...700cf6a. Read the comment docs.

lowdef commented 3 years ago

This resolves issue https://github.com/ndokter/dsmr_parser/issues/60.

Note that in

0-1:24.3.0(201022100000)(2C)(60)(1)(0-1:24.2.0)(m3)
(03575.334)

I could not find any specification of what the values (2C)(60)(1) are actually used for. Also while the parser parses them, the values are normally basically ignored as far as I could see. So changes the parsing type seems to be harmless.

Tox tests run 100%. I did not add a test for this particular case.

Following code:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun May  3 12:27:42 2020

@author: lowdef
"""

from dsmr_parser import telegram_specifications
from dsmr_parser.objects import Telegram
from dsmr_parser.parsers import TelegramParser
from dsmr_parser.parsers import MBusParser
from dsmr_parser.parsers import ValueParser
from dsmr_parser import obis_references
from dsmr_parser.value_types import timestamp
from decimal import Decimal

telegram_issue60  = r"""-0:96.1.1(31333637343139322020202020202020)
1-0:1.8.1(15237.388*kWh)
1-0:1.8.2(18759.401*kWh)
1-0:2.8.1(00000.000*kWh)
1-0:2.8.2(00000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(0002.94*kW)
1-0:2.7.0(0000.00*kW)
0-0:96.13.1()
0-0:96.13.0()
0-1:96.1.0(3238303131303038333032323537303133)
0-1:24.1.0(03)
0-1:24.3.0(201022100000)(2C)(60)(1)(0-1:24.2.0)(m3)
(03575.334)
!
"""

sample = telegram_issue60.replace('\n', '\r\n')

telegram_specification = telegram_specifications.V2_2
telegram_specification['checksum_support']=False

parser = TelegramParser(telegram_specification)
telegram = Telegram(sample, parser, telegram_specification)

print(telegram)

Demonstrates that the code works:

>>> runfile('/home/.../projects/donderstraal/develop/issue60.py', wdir='/home/.../projects/donderstraal/develop')
ELECTRICITY_USED_TARIFF_1:   15237.388  [kWh]
ELECTRICITY_USED_TARIFF_2:   18759.401  [kWh]
ELECTRICITY_DELIVERED_TARIFF_1:      0.000  [kWh]
ELECTRICITY_DELIVERED_TARIFF_2:      0.000  [kWh]
ELECTRICITY_ACTIVE_TARIFF:   0002   [None]
CURRENT_ELECTRICITY_USAGE:   2.94   [kW]
CURRENT_ELECTRICITY_DELIVERY:    0.00   [kW]
TEXT_MESSAGE_CODE:   None   [None]
TEXT_MESSAGE:    None   [None]
EQUIPMENT_IDENTIFIER_GAS:    3238303131303038333032323537303133 [None]
DEVICE_TYPE:     03 [None]
GAS_METER_READING:   3575.334   [m3] at 2020-10-22T10:00:00+02:00
Process finished with exit code 0