Skip to content

fix: an unknown enum value in telemetry no longer fails the whole parse - #161

Open
paulleventis wants to merge 2 commits into
cryptk:mainfrom
paulleventis:fix/tolerate-unknown-telemetry-enum-values
Open

paulleventis wants to merge 2 commits into
cryptk:mainfrom
paulleventis:fix/tolerate-unknown-telemetry-enum-values

Conversation

@paulleventis

Copy link
Copy Markdown

A single value the enums don't list makes Telemetry validation 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 (valveActuatorState 5), and FilterWhyOn already has MAX_VALUE, UNKNOWN_1 and UNKNOWN_2 for the same reason (#101). My controller (OmniPL, R0502000) reports whyFilterIsOn="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" or filterState="13". Telemetry.load_xml raises OmniParsingError for the whole document.

The change: a TolerantIntEnum mixin in util.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.
  • Its _missing_ turns an unknown integer into a pseudo-member named UNKNOWN_<n> (so str() 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.
  • It logs a warning the first time each unknown value is seen, asking for a report, so new values still get found.
  • Values that aren't integers are still rejected.

Left out on purpose: the light show, speed, brightness and special-effect enums. show is 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.py injects unknown values into the issue-60 fixture 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 on main (13 of 17) and pass with the change. The full suite passes (146 tests). Ruff is clean apart from the two RUF100 warnings already on main, and mypy reports the same 94 errors as main

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>
@paulleventis

Copy link
Copy Markdown
Author

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>
@sonarqubecloud

Copy link
Copy Markdown

@paulleventis

Copy link
Copy Markdown
Author

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:

  • Telemetry.unknown_enum_values() lists each one as an UnknownEnumValue(equipment, system_id, field, enum, value). It's empty when everything is known.
  • Telemetry.load_xml(xml, strict_enums=True) brings back the old fail-on-unknown behaviour for a caller that wants it. I haven't plumbed it through async_get_telemetry; happy to if you'd like.

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 options list comes from the enum's members and would reject a pseudo-member.

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:

  • 20 (currently MAX_VALUE): 49 episodes, in three situations:
    • the spa filter Off until its next schedule started (11 times, 10–24 h each);
    • the pool filter in Waiting To Turn Off / Waiting To Turn Off Manual for 3–7 h between schedules, with the pump still running at 60% (Oct 30 – Nov 5);
    • since freeze protection started cycling (Nov 12), the body that isn't being circulated, Suspended or Off, usually for the ~30 min until its next freeze-protect run.
  • 22 (currently UNKNOWN_2): twice, both while a filter sat idle between runs: spa Off for 50 min until a countdown timer started it (Nov 26 20:16), pool Suspended for 30 min before its next freeze-protect run (Nov 27 01:51).
  • 21: not seen.

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.

@paulleventis
paulleventis marked this pull request as ready for review November 27, 2026 13:34

This branch has not been deployed

No deployments
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