Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase sleep in Risco setup #77619

Merged
merged 2 commits into from
Sep 1, 2022
Merged

Conversation

OnFreund
Copy link
Contributor

Breaking change

Proposed change

Risco setup is stuck when trying to connect too quickly after closing the first connection (the first connection is in the config flow, the second one in async_setup_entry. The initial sleep of 1 second seemed to have solved it, but upon further testing 5 seconds seems like a safer value.

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)
  • Deprecation (breaking change to happen in the future)
  • 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:

epenet
epenet previously approved these changes Sep 1, 2022
Copy link
Contributor

@epenet epenet left a comment

Choose a reason for hiding this comment

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

LGTM (untested)

@OnFreund OnFreund marked this pull request as draft September 1, 2022 10:41
Move sleep to library
@OnFreund
Copy link
Contributor Author

OnFreund commented Sep 1, 2022

OK, after some more investigation, I was able to confirm (don't ask me how :) ) that Risco is recommending waiting 5 seconds upon disconnection. Through testing, I was also able to see that when connecting too quickly, the panel continues to communicate encrypted, even before the encryption key was obtained by the client, which is what's causing the problem.

Given that, I figured that it's probably best to move the sleep to the library:
OnFreund/pyrisco@v0.5.3...v0.5.4

This also fixes reloading for the config entry (e.g. when changing options).

The downside is that (I think) it can delay shutdown, but I'm not sure.

@OnFreund OnFreund marked this pull request as ready for review September 1, 2022 15:29
@OnFreund OnFreund requested a review from epenet September 1, 2022 15:29
@bdraco bdraco added this to the 2022.9.0 milestone Sep 1, 2022
@bdraco
Copy link
Member

bdraco commented Sep 1, 2022

The downside is that (I think) it can delay shutdown, but I'm not sure.

We don't unload config entries on shutdown last time I checked so it shouldn't be an issue

If you need to disconnect on shutdown you need to listen for the stop event. You could add that and call a different function in the lib that avoids the sleep in a future PR if it turns out to be needed

@@ -154,6 +154,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
if is_local(entry):
local_data: LocalData = hass.data[DOMAIN][entry.entry_id]
await local_data.system.disconnect()
Copy link
Member

Choose a reason for hiding this comment

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

Does this ever happen in the tests? If so it needs to be patched out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked test runtime before committing, so it looks like disconnect() is patched whenever this is used. It does make sense to add a specific test to make sure it's actually called, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@OnFreund
Copy link
Contributor Author

OnFreund commented Sep 1, 2022

RE HA shutdown - it's ok that we're not calling disconnect(). The only potential problem is if HA restarts within less than 5 seconds, which I don't have a good solution for. In the future I'll make the library a bit more robust so we can detect this situation and return ConfigEntryNotReady

@bdraco
Copy link
Member

bdraco commented Sep 1, 2022

The only potential problem is if HA restarts within less than 5 seconds, which I don't have a good solution for

I think that is a rare case, but maybe it won't be in the future

@balloob balloob merged commit 1692808 into home-assistant:dev Sep 1, 2022
@OnFreund OnFreund deleted the setup_timeout branch September 1, 2022 18:19
balloob pushed a commit that referenced this pull request Sep 2, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 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.

5 participants