Skip to content

fix(models): accept integer ErrorCode/WarningCode in ApplianceStatus - #127

Merged
KRoperUK merged 1 commit into
KRoperUK:mainfrom
Mista-P:fix/appliance-status-int-codes
Oct 17, 2026
Merged

KRoperUK merged 1 commit into
KRoperUK:mainfrom
Mista-P:fix/appliance-status-int-codes

Conversation

@Mista-P

@Mista-P Mista-P commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Summary

GetApplianceOverview returns ErrorCode and WarningCode as integers (0 when the appliance is healthy), but ApplianceStatus types them as str. In pydantic v2 that fails strict string validation, so get_appliance_overview() raises for any hub whose appliances report a numeric code:

2 validation errors for ApplianceStatus
ErrorCode
  Input should be a valid string [type=string_type, input_value=0, input_type=int]
WarningCode
  Input should be a valid string [type=string_type, input_value=0, input_type=int]

In the Home Assistant integration this surfaces as "Failed setup, will retry: Unexpected error fetching status", and the integration never finishes loading.

This adds a mode="before" validator that turns int into str for those two fields (and leaves bool alone), so the public type stays str | None and existing callers are unaffected.

Testing

  • New test_appliance_status_accepts_integer_error_and_warning_codes (fails on main, passes here).
  • ruff check, ruff format --check, mypy and pytest pass locally. The one exception is test_repo_scripts.py::test_check_md_alerts_passes, which also fails on main under macOS's bash 3.2 (mapfile: command not found).
  • Against a live hub: the same coercion, applied from the Home Assistant integration, fixed setup, and a powered appliance reports status.

🤖 Generated with Claude Code

GetApplianceOverview returns ErrorCode and WarningCode as integers (0 when
the appliance is healthy), but ApplianceStatus types them as str, so
model_validate raised a ValidationError for every status poll. Coerce ints
to str in a before-validator so the public type is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants