HA stops polling Data on error

Hi everyone,

i’ve build my first own integration which collects Data from a JSON API.

Sometimes the JSON Data is truncated and invalid for HA. This can occur due to a network error or the polled device is busy.

Now, instead of retrying to poll the Data, HA stops polling forever. I have to either restart HA or reload the integration so that polling continues.

What can I do to restart polling automatically?

You should be catching errors within your code and not let exceptions propagate back to home assistant. So if you receive invalid JSON handle the error within your code.

This is my code for updating data:

async def _async_update_data(self):

        try:

            with requests.Session() as sess:

                data = await self.hass.async_add_executor_job(sess.send, self._request)

                json_data = json.loads(data.text)

        except (OSError, Timeout, HTTPError, json.JSONDecodeError) as err:

            raise update_coordinator.UpdateFailed(err)

        _LOGGER.debug(

            "Connection to UVRLog successful. Retrieving latest UVRLog update from %s",

            data.url,

        )

        return json_data

So this part usually should do it?

except (OSError, Timeout, HTTPError, json.JSONDecodeError) as err:

            raise update_coordinator.UpdateFailed(err)

Looks like it should. Can you catch the error in the debugger and step through it?

Your debug statement should be before the raise to get called.

Perhaps add a separate except to catch any exceptions that don’t match the list?

Thank you PeteRage.

The Error is “Connection reset by Peer” which is not catched. I will try to implement this.