Skip to content

Fix Plugwise recovering from aiohttp client error#71642

Merged
frenck merged 1 commit intodevfrom
frenck-2022-0994
May 10, 2022
Merged

Fix Plugwise recovering from aiohttp client error#71642
frenck merged 1 commit intodevfrom
frenck-2022-0994

Conversation

@frenck
Copy link
Copy Markdown
Member

@frenck frenck commented May 10, 2022

Proposed change

I just experienced a power grid outage @ my home, when it returned, I noticed that Plugwise didn't recover. The reason is that Home Assistant was faster in starting up then Plugwise and the connection failed.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 335, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/plugwise/__init__.py", line 13, in async_setup_entry
    return await async_setup_entry_gw(hass, entry)
  File "/usr/src/homeassistant/homeassistant/components/plugwise/gateway.py", line 43, in async_setup_entry_gw
    connected = await api.connect()
  File "/usr/local/lib/python3.9/site-packages/plugwise/smile.py", line 260, in connect
    result = await self._request(DOMAIN_OBJECTS)
  File "/usr/local/lib/python3.9/site-packages/plugwise/helper.py", line 259, in _request
    resp = await self._websession.get(url, headers=headers, auth=self._auth)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.9/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 10.10.11.200:80 ssl:default [Connect call failed ('10.10.11.200', 80)]

However, this error isn't handled by the integration and thus the integration will not retry.
This PR fixes that.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @CoMPaTech, @bouwew, @brefra, mind taking a look at this pull request as it has been labeled with an integration (plugwise) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

LOGGER.error("Invalid username or Smile ID")
return False
except PlugwiseException as err:
except (ClientConnectionError, PlugwiseException) as err:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Longterm this should probably be caught by the library and raised as a library exception.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree.

CC @CoMPaTech @bouwew

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've fixed this in plugwise-beta some time ago, in almost the same way.

We need to think about how to do this in the library...

@frenck frenck merged commit ef16e6c into dev May 10, 2022
@frenck frenck deleted the frenck-2022-0994 branch May 10, 2022 13:28
@github-actions github-actions bot locked and limited conversation to collaborators May 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants