ha-knmi icon indicating copy to clipboard operation
ha-knmi copied to clipboard

Suggestion to work around failed updates

Open jcjveraa opened this issue 4 months ago • 3 comments

Hi @golles, perhaps this could be an idea? Ideally the API is 'fixed' to return non-corrupt json, but there might be other reasons too why the API would not be available - i.e. we can't rely on the API always being there. To allow for that, we could implement something like this to ensure a single failed update does not turn the entities 'unavailable'.

I have this running with my own API key on a 'devcontainer-hass' now, I'll leave it running for a few hours to see if this has actually worked as expected. I have zero experience with HASS development, but my assumption is that the state of the integration's entities will only become 'unavailable' if an error is thrown.

Ideally for me (and perhaps other users):

  • I prefer 'stale' data (old data) over 'no data' ('unavailable), provided I can control how old the data can be;
  • I would like to see how old the data is so that for "time critical" data I can perhaps deviate from the default (already provided by the integration via knmi_latest_update, so no change required).

Note: treat this as a 'stub', should be expanded with tests etc, but unfortunately I'm not too familiar with HASS python coding and my VSCode IDE PyLance doesn't seem to pick up the installed requirements_dev packages, so no guarantee I will do that for now

It seems to work so far. As is, a 20 minute (2 failed updates) gap in the data: image

With this PR (I started up HASS around 09:06): image

jcjveraa avatar Apr 16 '24 07:04 jcjveraa