Fix extract_tariff/extract_serial: generic OBIS decoding instead of hardcoded manufacturer strings - #1
Open
blesk89 wants to merge 4 commits into
Open
Fix extract_tariff/extract_serial: generic OBIS decoding instead of hardcoded manufacturer strings#1blesk89 wants to merge 4 commits into
blesk89 wants to merge 4 commits into
Conversation
…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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
extract_tariff()only matched uppercaseb"T1"..b"T4", but at least onemeter model sends lowercase tariff codes (observed
"t3"on a live frame) —so the tariff was silently never extracted.
extract_serial()hardcodes the Sagemcom prefixb"SAG", which only worksfor 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.0for tariff,96.1.0for serial number), independent of manufacturer or letter case.Structure verified empirically against a live captured frame:
Both
extract_tariff()andextract_serial()now try the generic OBIS pathfirst, 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 returnedNone.🤖 Generated with Claude Code