core: Surepetcare: component does not load in 2021.4.0

The problem

Surepetcare integration fails to load with an error in 2021.4.0

What is version of Home Assistant Core has the issue?

2021.4.0

What was the last working version of Home Assistant Core?

2021.3.4

What type of installation are you running?

Home Assistant Core

Integration causing the issue

surepetcare

Link to integration documentation on our website

https://www.home-assistant.io/integrations/surepetcare/

Example YAML snippet

# Put your YAML below this line
surepetcare:
  username: !secret surepet_usr
  password: !secret surepet_pwd
  flaps: [ !secret surepet_flap_id ]
  feeders: [ !secret surepet_fig_bowl_id, !secret surepet_sami_bowl_id ]
  pets: [ !secret surepet_fig_id, !secret surepet_sami_id ]
  scan_interval: 300

Anything in the logs that might be useful for us?

Logger: homeassistant.setup
Source: util/async_.py:139
First occurred: 20:48:29 (1 occurrences)
Last logged: 20:48:29

Error during setup of component surepetcare
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 240, in _async_setup_component
    result = await task
  File "/usr/src/homeassistant/homeassistant/components/surepetcare/__init__.py", line 116, 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 262, in _get_resource
    self.get_token()
  File "/usr/local/lib/python3.8/site-packages/surepy/__init__.py", line 410, in get_token
    raw_response: requests.Response = requests.post(
  File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/lib/python3.8/http/client.py", line 1266, in _send_request
    self.putrequest(method, url, **skips)
  File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 214, in putrequest
    return _HTTPConnection.putrequest(self, method, url, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 150, in protected_loop_func
    check_loop()
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 139, in check_loop
    raise RuntimeError(
RuntimeError: I/O must be done in the executor; Use `await hass.async_add_executor_job()` at homeassistant/components/surepetcare/__init__.py, line 116: device_data = await surepy.device(device[CONF_ID])

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 33 (5 by maintainers)

Commits related to this issue

Most upvoted comments

already fixed in the lib 👍 but that’s the good part 😄 the integration uses an old version which has breaking changes compared to the current lib. I will look into it ✌️

@flyize This is how I do it on my Home Assistant OS using Portainer and vi. There may be easier ways, but this works fine for me.

  • Make sure you have Portainer set up (Install via Supervisor -> Add-on Store -> Portainer)
  • Update Home Assistant Core to latest version. After the update, a notification will inform you that surepetcare could not be set up.
  • Open Portainer and click on Containers in the menu.
  • Locate homeassistant in the list. Under Quick actions click on the >_ icon (Exec console), then click Connect to enter the container.
  • Navigate to the directory containing async_.py: cd /usr/src/homeassistant/homeassistant/util/
  • Edit the file using vi: vi async_.py
    • Navigate to line 139 using arrow keys or by typing ESC 139 shift-g
    • Enter insert mode by hitting the i key and add a # to the beginning of lines 139-142. It should look like this:
         #    raise RuntimeError(                                               
         #        f"I/O must be done in the executor; Use `await hass.async_add_executor_job()` "
         #        f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {found_frame.line.strip()}"
         #    )
      
    • Hit ESC to exit insert mode and type :wq to save the file.
    • In case you mess up, either hit ESC followed by u to undo your last action or hit ESC and type :q! to exit without saving and try again.
  • Restart Home Assistant (Configuration->Server Controls->Restart). Surepetcare should now be working again.

got a working version locally now but still needs a lot of work (mostly due to the breaking changes in the current library) until @MartinHjelmare will be happy :> I will create a (WIP) PR tomorrow probably ✌️

already fixed in the lib 👍 but that’s the good part 😄 the integration uses an old version which has breaking changes compared to the current lib. I will look into it ✌️

Would it be possible to update to also get the feeder data in too at same time please thanks.

@flyize This is how I do it on my Home Assistant OS using Portainer and vi. There may be easier ways, but this works fine for me.

  • Make sure you have Portainer set up (Install via Supervisor -> Add-on Store -> Portainer)

  • Update Home Assistant Core to latest version. After the update, a notification will inform you that surepetcare could not be set up.

  • Open Portainer and click on Containers in the menu.

  • Locate homeassistant in the list. Under Quick actions click on the >_ icon (Exec console), then click Connect to enter the container.

  • Navigate to the directory containing async_.py: cd /usr/src/homeassistant/homeassistant/util/

  • Edit the file using vi: vi async_.py

    • Navigate to line 139 using arrow keys or by typing ESC 139 shift-g
    • Enter insert mode by hitting the i key and add a # to the beginning of lines 139-142. It should look like this:
         #    raise RuntimeError(                                               
         #        f"I/O must be done in the executor; Use `await hass.async_add_executor_job()` "
         #        f"at {found_frame.filename[index:]}, line {found_frame.lineno}: {found_frame.line.strip()}"
         #    )
      
    • Hit ESC to exit insert mode and type :wq to save the file.
    • In case you mess up, either hit ESC followed by u to undo your last action or hit ESC and type :q! to exit without saving and try again.
  • Restart Home Assistant (Configuration->Server Controls->Restart). Surepetcare should now be working again.

Thanks, this worked great for me!

It may be that your home assistant containers are hidden by default. It’s been so long since I unhid mine that I can’t say for sure what’s the default setting now. Go to Settings in Portainer and look under Hidden containers at the bottom. I only have io.hass.type=supervisor.

Update: Yep, there we go: https://github.com/hassio-addons/addon-portainer/blob/main/portainer/DOCS.md#known-issues-and-limitations So I guess you need to remove the io.hass.type=core filter to see the homeassistant container.

For anyone who relies on it, the previous functionality (a warning, not an error) can be achieved temporarily by reversing the first file patch here:

https://github.com/home-assistant/core/pull/48387/commits/423eed5c6821b5231e7ea684ac602f42b32a589d

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

already fixed in the lib 👍 but that’s the good part 😄 the integration uses an old version which has breaking changes compared to the current lib. I will look into it ✌️

I have the same issue, thnx for quick response.

Just to understand how this integration works. since the only change I didto make it working initially was adding it to the configuration.yaml. for other Add-ons I can choose Auto update or do it manual

Do we have to wait for a new version of HA 2021.4.1? or can we as and ‘enduser’ reload this integration? or will it be automatically be updated?

@antb33: re your #48720 issue with the error “socket.gaierror: [Errno -3] Try again” in your logs. From some quick googling, that error message would seem to relate to DNS issues so may be worth looking to your network first.

I’m still on 2021.3.3 and getting similar errors to those reported on this issue and also this other one #48720. Restarting HA doesn’t resolve the issue.

@richard-underwood do you think your suggested fix would resolve both issues?

No - if you’re on 2021.3.3 it should still be working, but with warning messages. The work-around I suggested just reverts the 2021.4.0 behaviour (erroring and the integration not functioning at all) back to the 2021.3.3 behaviour (just the warning).