Skip to content

Exclude access token from host info updates in Konnected config flow#33912

Merged
MartinHjelmare merged 2 commits intohome-assistant:devfrom
konnected-io:preserve_token
Apr 9, 2020
Merged

Exclude access token from host info updates in Konnected config flow#33912
MartinHjelmare merged 2 commits intohome-assistant:devfrom
konnected-io:preserve_token

Conversation

@kit-klein
Copy link
Copy Markdown
Contributor

Proposed change

In the Konnected config flow we want to automatically update the host info for a konnected config entry if SSDP indicates it changed. When updating host info we were also including a randomly generated access token in the self.data object passed to self._abort_if_unique_id_configured(updates=self.data). This was causing config entry updates even though the host info did not change.

In most cases this is fine as the config entry gets reloaded and the new access token is sent to the panel. However a race condition can occur where the reload is called after the konnected component is loaded, but before it's platforms are not yet loaded. Causing this error

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 295, in async_unload
    hass, self
  File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 138, in async_unload_entry
    return await hass.data[DOMAIN].async_unload_entry(entry)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 180, in async_unload_entry
    raise ValueError("Config entry was never loaded!")
ValueError: Config entry was never loaded!

When this happens the reload fails such that the panel is using the old access token but the config_entry contains the new access token. This effectively blocks any updates from the panel until the config_entry is reloaded (via a restart or manually via the integrations UI) and sends the updated settings to the panel.

This PR defers creation of the access_token during the konnected config flow so that it is not included as part of the host info changes. This prevents the panels from being orphaned if host info changes and also prevents the unnecessary config entry updates stemming from the changed access token.

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

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

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

@probot-home-assistant
Copy link
Copy Markdown

Hey there @heythisisnate, mind taking a look at this pull request as its been labeled with a integration (konnected) you are listed as a codeowner for? Thanks!

@kit-klein
Copy link
Copy Markdown
Contributor Author

If another 0.108 build is released this would be a great fix to include.

Copy link
Copy Markdown
Contributor

@heythisisnate heythisisnate left a comment

Choose a reason for hiding this comment

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

LGTM

@springstan springstan changed the title konnected: don't include access token as part of host info updates Exclude access token from host info updates in Konnected config flow Apr 9, 2020
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good!

@MartinHjelmare MartinHjelmare added this to the 0.108.2 milestone Apr 9, 2020
@MartinHjelmare MartinHjelmare merged commit c2d1db6 into home-assistant:dev Apr 9, 2020
balloob pushed a commit that referenced this pull request Apr 10, 2020
…33912)

* black updates

* test that host update doesn't impact access token
@balloob balloob mentioned this pull request Apr 10, 2020
@lock lock Bot locked and limited conversation to collaborators Apr 15, 2020
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.

Konnected panel randomly not responding after reboot

5 participants