Repository navigation
fix: an unknown enum value in telemetry no longer fails the whole parse - #161
paulleventis wants to merge 2 commits into
Conversation
Controllers report values the enums don't list: new firmware, undocumented states (cryptk#155; FilterWhyOn 20-22 were added for the same reason). One such value made pydantic reject its field, which failed Telemetry validation, so every piece of equipment disappeared until a library release. Add a TolerantIntEnum mixin to the enums parsed from telemetry (states, why-on reasons, modes, statuses, valve position). An unknown integer becomes an UNKNOWN_<n> pseudo-member, reused for the same value and left out of iteration, and a warning is logged once per value. Non-integers are still rejected. Light show, speed, brightness and special-effect enums are left as they are: the show is a union of enums that pydantic picks between. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
I'm not super happy with this CC authored fix. Unknown values now basically cause the HA integration to silently run, and the unknown value could be meaningfully important / breaks the assumptions in the user's HA use case. I'm iterating with CC on better a better fix, at minimum make the fact the omnilogic integration is in a degraded state more prominant to the HA user. |
Telemetry.unknown_enum_values() returns each value its enum doesn't list (equipment, system id, field, enum, value), so a consumer can tell the user and ask for a report instead of relying on a log warning. Telemetry.load_xml(xml, strict_enums=True) raises OmniParsingError on any such value, for callers that prefer the old behaviour. util.is_unknown_member() tells pseudo-members from real placeholder members such as FilterWhyOn.UNKNOWN_1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
|
Two additions, and some data on the values that prompted this. Making unknown values visible (pushed to this branch). Tolerating an unknown value shouldn't mean hiding it, and a log warning is easy to miss, so:
With the accessor, the Home Assistant integration can raise a Repairs issue ("the controller reported filter why-on 22; please report it") and show just the affected entity as unknown instead of carrying on silently. I'll follow up with that integration PR if this lands. It also needs to handle the CSAD mode sensor, whose What 20 and 22 look like on my controller (OmniPL, R0502000, one variable-speed pump shared by pool and spa through valves; history Oct 9 – Nov 27). #101 had no context for these, so in case it helps name them:
So 20 isn't an end-of-enum sentinel here: the controller sends it as a real reason while a filter is idle or waiting to restart. I'll compare it with the app's status text the next time it shows up and report back. |



A single value the enums don't list makes
Telemetryvalidation fail, and then the library returns nothing at all: in Home Assistant every OmniLogic entity goes unavailable until a library release adds the value. #155 was one case (valveActuatorState5), andFilterWhyOnalready hasMAX_VALUE,UNKNOWN_1andUNKNOWN_2for the same reason (#101). My controller (OmniPL, R0502000) reportswhyFilterIsOn="20"for hours at a time, so new values do turn up.Reproduce: take any fixture's telemetry and set one enum attribute to a value that isn't listed, e.g.
whyFilterIsOn="23"orfilterState="13".Telemetry.load_xmlraisesOmniParsingErrorfor the whole document.The change: a
TolerantIntEnummixin inutil.py, added to the enums the telemetry models parse:BackyardState,ChlorinatorOperatingState,ChlorinatorOperatingMode,CSADStatus,CSADMode,ColorLogicPowerState,FilterState,FilterValvePosition,FilterWhyOn,GroupState,HeaterState,HeaterMode,HeaterWhyOn,PumpState,PumpWhyOn,RelayState,RelayWhyOn._missing_turns an unknown integer into a pseudo-member namedUNKNOWN_<n>(sostr()gives "Unknown 23"). The pseudo-member compares equal to the int, the same value always gives the same object, and iterating the enum still lists only the real members.Left out on purpose: the light show, speed, brightness and special-effect enums.
showis typed as a union of six show enums, and pydantic chooses between them by trying each one; if any of them accepted every integer, it would win for values that belong to another model. Those could be handled separately if you want.One trade-off: these enums now accept any integer when called directly, e.g.
HeaterMode(9). As far as I can see they're only built from controller data (telemetry and the CLI's display code), not from user input, but tell me if you'd rather restrict the tolerance to the pydantic fields instead.Tested:
tests/test_unknown_enum_values.pyinjects unknown values into theissue-60fixture for ten attributes across the backyard, relay, filter, heater, virtual heater and light, and checks the pseudo-member, reuse, iteration, the one-time warning and that non-integers still fail. The new tests fail onmain(13 of 17) and pass with the change. The full suite passes (146 tests). Ruff is clean apart from the twoRUF100warnings already onmain, and mypy reports the same 94 errors asmain