Skip to content

Fix extract_tariff/extract_serial: generic OBIS decoding instead of hardcoded manufacturer strings - #1

Open
blesk89 wants to merge 4 commits into
lhubac:masterfrom
blesk89:master
Open

Fix extract_tariff/extract_serial: generic OBIS decoding instead of hardcoded manufacturer strings#1
blesk89 wants to merge 4 commits into
lhubac:masterfrom
blesk89:master

Conversation

@blesk89

@blesk89 blesk89 commented Aug 22, 2026

Copy link
Copy Markdown

Problem

extract_tariff() only matched uppercase b"T1"..b"T4", but at least one
meter model sends lowercase tariff codes (observed "t3" on a live frame) —
so the tariff was silently never extracted.

extract_serial() hardcodes the Sagemcom prefix b"SAG", which only works
for that specific manufacturer.

Fix

Added a generic _find_data_string() helper that decodes class-1 (Data)
octet-string COSEM objects directly by OBIS code (96.14.0 for tariff,
96.1.0 for serial number), independent of manufacturer or letter case.
Structure verified empirically against a live captured frame:

02 02 [class_id=00 01] [obis:6] [attribute:1] [axdr_type:1]=0x09 [length:1] [value:length bytes]

Both extract_tariff() and extract_serial() now try the generic OBIS path
first, falling back to the original hardcoded string search for backward
compatibility with whatever meter model the original heuristics were tuned
for.

Tested against a live captured frame from a non-Sagemcom EG.D meter —
extract_tariff() now correctly returns "t3" where it previously returned
None.

🤖 Generated with Claude Code

blesk89 and others added 4 commits August 22, 2026 12:17
…tvrdo zadaného textu

extract_tariff hledal jen velká písmena b"T1"..b"T4", ale meter posílá
malá písmena (pozorováno "t3") -> nikdy nenašlo shodu.
extract_serial hledal natvrdo Sagemcom prefix b"SAG" -> nefunguje pro
jiné výrobce meterů.

Oprava: nová obecná metoda _find_data_string() dekóduje class-1 (Data)
octet-string objekty přímo podle OBIS kódu (96.14.0 pro tarif, 96.1.0
pro sériové číslo), nezávisle na výrobci/velikosti písmen. Ověřeno na
živém rámci ze skutečného měřiče (tariff='t3' správně dekódováno).
Zachován fallback na původní textové hledání pro zpětnou kompatibilitu.
Skutečná struktura rámců od tohohle meteru (ověřeno na zachycených rámcích)
nemá čtyřbajtovou hlavičku "02 02 00 03" před OBIS kódem, jak předpokládal
starší heuristický parser (proto na živých datech skoro nikdy nic nenašel).
Class_id je raw 2 bajty přímo před OBIS kódem. Navíc přidána kontrola
rozumnosti hodnoty podle device_class z obis.yaml (RS485/USB spojení občas
dodá bitově poškozený rámec, typicky po USB re-enumeraci FT232 adaptéru
po reboot Proxmox hostu) — místo publikace nesmyslných hodnot v řádu
milionů/miliard wattů se taková hodnota teď zahodí a pole zůstane na
poslední známé hodnotě.
…le = nedostupne misto navzdy zaseknute hodnoty
… unavailable kazdy cyklus (garbage uz filtruje parser)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant