Sure Petcare integration can not be set up

Hi there!

I’m triying to set up the Sure Petcare integration, but I get invalid config message. My config seems to be ok

surepetcare:
  username: [email protected]
  password: xxxxxxxxxxx
  feeders: [123456]
  pets: [654321]

I have 3 error messages in the log

Message 1

Logger: homeassistant.util.async_
Source: util/async_.py:129
First occurred: 0:30:53 (1 occurrences)
Last logged: 0:30:53

Detected I/O inside the event loop. This is causing stability issues. Please report issue for surepetcare doing I/O at homeassistant/components/surepetcare/__init__.py, line 114: device_data = await surepy.device(device[CONF_ID])

Message 2

Logger: surepy
Source: /usr/local/lib/python3.8/site-packages/surepy/__init__.py:310
First occurred: 0:31:09 (1 occurrences)
Last logged: 0:31:09

Can not load data from https://app.api.surehub.io/api/me/start

Message 3

Logger: homeassistant.setup
Source: components/surepetcare/__init__.py:114
First occurred: 0:31:09 (1 occurrences)
Last logged: 0:31:09

Error during setup of component surepetcare
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 277, in _get_resource
    await self._session.options(resource, headers=headers)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 280, in _get_resource
    logger.debug("response.status: %d", response.status)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 45, in __exit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 213, in _async_setup_component
    result = await task
  File "/usr/src/homeassistant/homeassistant/components/surepetcare/__init__.py", line 114, in async_setup
    device_data = await surepy.device(device[CONF_ID])
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 184, in device
    device: Dict[str, Any] = (await self.devices).get(device_id, {})
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 181, in devices
    return await self.get_entities("devices")
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 244, in get_entities
    await self._get_resource(resource=MESTART_RESOURCE)
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 311, in _get_resource
    raise SurePetcareConnectionError()
surepy.SurePetcareConnectionError

Any idea?

Message 1 has already been raised as an issue: https://github.com/home-assistant/core/issues/46449
Whilst it’s something that needs to be addressed, it does not prevent the integration working.

Messages 2 & 3 are related to the poor performance of Sure Petcare’s cloud infrastructure and the currently configured timeout - the best I can suggest is restart, unless you feel comfortable editing the integration source code to increase the timeout. Similar messages are periodically seen with the integration configured and running, e.g. from my system overnight running with an increased timeout:

2021-03-04 20:23:15 ERROR (MainThread) [surepy] Can not load data from https://app.api.surehub.io/api/me/start
2021-03-04 20:23:15 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.8/site-packages/surepy/__init__.py", line 278, in _get_resource
response: aiohttp.ClientResponse = await self._session.get(resource, headers=headers, timeout=timeout)
File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/client.py", line 544, in _request
await resp.start(conn)
File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 890, in start
message, payload = await self._protocol.read() # type: ignore
File "/srv/homeassistant/lib/python3.8/site-packages/aiohttp/streams.py", line 604, in read
await self._waiter
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.8/site-packages/surepy/__init__.py", line 280, in _get_resource
logger.debug("response.status: %d", response.status)
File "/srv/homeassistant/lib/python3.8/site-packages/async_timeout/__init__.py", line 45, in __exit__
self._do_exit(exc_type)
File "/srv/homeassistant/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/components/surepetcare/__init__.py", line 200, in async_update
await self.surepy._get_resource( # pylint: disable=protected-access
File "/srv/homeassistant/lib/python3.8/site-packages/surepy/__init__.py", line 311, in _get_resource
raise SurePetcareConnectionError()
surepy.SurePetcareConnectionError

Issues with infrastructure can usually be confirmed by checking the Sure Petcare app load time.

Well, in my case I have a feeder and the hub and after setting up the config.yaml I will get 4 new devices, the feeder battery, the feeder connectivity, the hub and my pet but all are unavailable. Restarting doesn’t solve it unfortunately

I’ve switched environment to a docker environment this morning and had this exact issue again with multiple restarts not resolving it. All entities showed as unavailable.

From my logs this morning, this is pretty much identical to your Message 3.

Log Details (ERROR)
Logger: homeassistant.setup
Source: components/surepetcare/__init__.py:114
First occurred: 13:17:10 (1 occurrences)
Last logged: 13:17:10

Error during setup of component surepetcare
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 277, in _get_resource
    await self._session.options(resource, headers=headers)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 520, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 535, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 892, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1020, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 969, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore  # noqa
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1050, in create_connection
    transport, protocol = await self._create_connection_transport(
  File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1080, in _create_connection_transport
    await waiter
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 280, in _get_resource
    logger.debug("response.status: %d", response.status)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 45, in __exit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.8/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 213, in _async_setup_component
    result = await task
  File "/usr/src/homeassistant/homeassistant/components/surepetcare/__init__.py", line 114, in async_setup
    device_data = await surepy.device(device[CONF_ID])
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 184, in device
    device: Dict[str, Any] = (await self.devices).get(device_id, {})
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 181, in devices
    return await self.get_entities("devices")
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 244, in get_entities
    await self._get_resource(resource=MESTART_RESOURCE)
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 311, in _get_resource
    raise SurePetcareConnectionError()
surepy.SurePetcareConnectionError

I resolved this by:
editing the file

/usr/local/lib/python3.8/site-packages/surepy/__init__.py

increasing the constant API_TIMEOUT from 15 to 30
and restarting.

NB: this will need to be checked on each HA update in case the file is updated / modified and depending on your installation type

If you had a configuration error you should have a logged message about configuration error and pointing to an line number within configuration.yaml.
You are getting timeout errors, which is a result of Surepet’s poor-performing infrastructure.
I was involved in the beta release of their connected hardware and they have had regular issues with server and code performance since the first release candidate.