Skip to content

Improve PumpSpy coordinator resiliency and daily totals handling#17

Open
aschoorl wants to merge 6 commits intoCrewski:mainfrom
aschoorl:fix-coordinator-updatefailed
Open

Improve PumpSpy coordinator resiliency and daily totals handling#17
aschoorl wants to merge 6 commits intoCrewski:mainfrom
aschoorl:fix-coordinator-updatefailed

Conversation

@aschoorl
Copy link
Copy Markdown

@aschoorl aschoorl commented Sep 7, 2025

Summary

  • Maintain a persistent aiohttp session with retry/backoff logic for token acquisition and broadened network error handling across the PumpSpy client.
  • Correct PumpSpy interval endpoint mapping for RHT outlets and ensure fetched interval payloads fall back to empty lists when absent.
  • Simplify the coordinator’s update path by letting DataUpdateCoordinator surface fetch errors while keeping unload logic minimal.
  • Rework totaling sensors to return only the record for the current period (day/week/month) and report 0 when the API hasn’t published data yet.

Testing

  • python -m compileall custom_components/pumpspy_ha/sensor.py
  • ✅ Running in Home Assistant production environment for several days without regressions

Use Home Assistant’s UpdateFailed in the coordinator so transient auth or connection errors don’t clear data and mark entities unavailable. Replaces previous silent None return with explicit failure signaling (InvalidAccessToken, ConnectionError). No functional change on success; reduces unavailable state flapping during brief outages.
- keep a reference to the coordinator during unload so we can reach its API client
- call `coordinator.api.async_close()` after platforms unload, releasing the shared aiohttp session we introduced for connection reuse
- avoids lingering TCP sockets or warnings when a config entry is removed or reloaded
@aschoorl aschoorl changed the title fix: retain entity states by raising UpdateFailed on poll errors Harden PumpSpy coordinator refresh with UpdateFailed handling and pooled session Sep 28, 2025
@aschoorl aschoorl changed the title Harden PumpSpy coordinator refresh with UpdateFailed handling and pooled session Improve PumpSpy coordinator resiliency and daily totals handling Oct 7, 2025
When the PumpSpy server returns HTTP 500, fetch_current_data returns None.
Previously the coordinator passed this through, causing sensors to crash
on attribute access and go unavailable until the next successful poll.

Now _async_update_data raises UpdateFailed so Home Assistant's
DataUpdateCoordinator preserves the last known good state instead of
pushing None to entities. Also downgraded the transient 500 log from
error to warning.
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