Skip to content

refactor: replace internal API client with pyodio OdioHub - #57

Open
b0bbywan wants to merge 2 commits into
masterfrom
pyodio-refactor
Open

refactor: replace internal API client with pyodio OdioHub#57
b0bbywan wants to merge 2 commits into
masterfrom
pyodio-refactor

Conversation

@b0bbywan

Copy link
Copy Markdown
Owner

Delegate all REST/SSE protocol handling to the pyodio library (hub layer):

  • drop api_client.py, event_stream.py, exceptions.py, coordinator.py (~1900 lines) — the hub keeps live typed state via SSE with automatic reconnection and full resync on every reconnect
  • entities subscribe directly to hub namespace on_change callbacks (push model, no DataUpdateCoordinator); new OdioEntity base in entity.py handles availability (hub.connected) and subscriptions
  • backend re-detection: hub resyncs before reporting the connection, so on_connection_change compares hub.server.backends to the setup snapshot and schedules a reload when they differ
  • degraded startup: connect() failure falls back to cached StartupData (now built on pyodio ServerInfo/PowerCapabilities) + hub.start()
  • MPRIS: raw beacon position + position_updated_at (HA extrapolates); cover URLs and x-cache-updated-at pipeline now handled by pyodio
  • config flow validates through the low-level OdioClient; /services 404 tolerated; helpers operate on pyodio dataclasses
  • tests: conftest gains a make_hub factory (real OdioHub seeded through pyodio from_dict parsers, autospec'd client) + push_event/set_connected; low-level client/SSE/upgrade-semantics suites moved to pyodio
  • dev deps: pyodio pinned from git (ha-parity-rc3) until a PyPI release; manifest.json intentionally unchanged for now

Claude-Session: https://claude.ai/code/session_016r5tpRc96W4yR2df2MjdcJ

Delegate all REST/SSE protocol handling to the pyodio library (hub layer):

- drop api_client.py, event_stream.py, exceptions.py, coordinator.py
  (~1900 lines) — the hub keeps live typed state via SSE with automatic
  reconnection and full resync on every reconnect
- entities subscribe directly to hub namespace on_change callbacks (push
  model, no DataUpdateCoordinator); new OdioEntity base in entity.py
  handles availability (hub.connected) and subscriptions
- backend re-detection: hub resyncs before reporting the connection, so
  on_connection_change compares hub.server.backends to the setup
  snapshot and schedules a reload when they differ
- degraded startup: connect() failure falls back to cached StartupData
  (now built on pyodio ServerInfo/PowerCapabilities) + hub.start()
- MPRIS: raw beacon position + position_updated_at (HA extrapolates);
  cover URLs and x-cache-updated-at pipeline now handled by pyodio
- config flow validates through the low-level OdioClient; /services 404
  tolerated; helpers operate on pyodio dataclasses
- tests: conftest gains a make_hub factory (real OdioHub seeded through
  pyodio from_dict parsers, autospec'd client) + push_event/set_connected;
  low-level client/SSE/upgrade-semantics suites moved to pyodio
- dev deps: pyodio pinned from git (ha-parity-rc3) until a PyPI release;
  manifest.json intentionally unchanged for now

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016r5tpRc96W4yR2df2MjdcJ
Declare pyodio in the manifest now that it is published — HA installs
integration requirements from PyPI — and pin the dev group to the same
release instead of the git branch.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016r5tpRc96W4yR2df2MjdcJ
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