home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.13k stars 29.18k forks source link

Sure Petcare fails to reconnect or setup when server is temporarily unavailable #33515

Closed i00 closed 4 years ago

i00 commented 4 years ago

The problem

4:00 yesterday stopped working with: Unable to connect to surepetcare.io: Wrong ! Web page and phone app still work without issue

Environment

Problem-relevant configuration.yaml

Not relevant

Traceback/Error logs

Logger: homeassistant.components.surepetcare
Source: components/surepetcare/__init__.py:87
Integration: surepetcare (documentation, issues)
First occurred: 10:25:44 AM (1 occurrences)
Last logged: 10:25:44 AM

Unable to connect to surepetcare.io: Wrong !

Additional information

probot-home-assistant[bot] commented 4 years ago

Hey there @benleb, mind taking a look at this issue as its been labeled with a integration (surepetcare) you are listed as a codeowner for? Thanks!

i00 commented 4 years ago

OK ... must have been a temp thing ... started working again yest

tomverboon commented 4 years ago

I am not so sure that it has been resolved yet.

After reading your comment, I have restarted my Home Assisstant and still got the error:

2020-04-04 08:27:46 ERROR (MainThread) [homeassistant.components.surepetcare] Unable to connect to surepetcare.io: Wrong !

What about other users?

i00 commented 4 years ago

Ok ... I restarted it again today and got the same issue???

i00 commented 4 years ago

Also it shouldn't just say a generic there "is an issue with my config" (which there is not) and fall over... why can't it back off and try again?

i00 commented 4 years ago

Ok it seems that sometimes their server is inaccessible for short periods of times and that the integration never bothers to try and reconnect to it again if the connection fails the first time with this incorrect message in the notifications: image ... the real message that I posted in the op is in the log ... but still this is not a config issue and should not result in it breaking until HA is next restarted.

Groodles commented 4 years ago

Version 0.108.3 still has this issue.

crgreenwood commented 4 years ago

I've spent some time investigating this evening as, after adding another integration I saw this go from an intermittent issue to something that I experienced on nearly every restart. It appears that version of @benleb 's surepy library that is specified by the surepetcare component is one level down (0.2.3) from the latest the @benleb has published on pypi (v0.2.4). In v0.2.3 the API_TIMEOUT value is ignored when the connection is tried and is instead hardcoded to 5 seconds. In v0.2.4 he's updated the code to use the API_TIMEOUT value of 10 seconds (among other changes). I'm not sure why he hasn't yet updated the component to use the newer version. In the meantime I have successfully tested both updating to v0.2.4 and also hacking v0.2.3 to use the API_TIMEOUT variable (set to 10) instead of 5 on my own installation as a short term fix.

tomverboon commented 4 years ago

@crgreenwood, can you provide me a more detailed explanation on how to hack v0.2.3 to use the longer timeout?

crgreenwood commented 4 years ago

@tomverboon I exec'ed into the homeassistant container on my installation (through Portainer). Once in you can run: pip list | grep surepy to ensure that you are already running surepy v0.2.3. Then edit the file with: vi /usr/local/lib/python3.7/site-packages/surepy/__init__.py On line 146 after async_timeout.timeout( replace 5 with API_TIMEOUT (which is already defined further up the file. The resulting line should read: with async_timeout.timeout(API_TIMEOUT, loop=self._loop): Save and quit. This is super hacky and will need repeating after every homeassistant update but has taken me from the integration being effectively broken to working again. There are other changes in the latest library from @benleb but this change seems to do the job.

tomverboon commented 4 years ago

@tomverboon I exec'ed into the homeassistant container on my installation (through Portainer). Once in you can run: pip list | grep surepy to ensure that you are already running surepy v0.2.3. Then edit the file with: vi /usr/local/lib/python3.7/site-packages/surepy/__init__.py On line 146 after async_timeout.timeout( replace 5 with API_TIMEOUT (which is already defined further up the file. The resulting line should read: with async_timeout.timeout(API_TIMEOUT, loop=self._loop): Save and quit. This is super hacky and will need repeating after every homeassistant update but has taken me from the integration being effectively broken to working again. There are other changes in the latest library from @benleb but this change seems to do the job.

Thanks for the instructions, much appreciated.