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

Add support for native oauth2 in Point #118243

Merged
merged 42 commits into from
Sep 20, 2024
Merged

Conversation

fredrike
Copy link
Contributor

@fredrike fredrike commented May 27, 2024

Proposed change

Add support for native oauth2 in Point integration.

Type of change

Change log of pypoint: fredrike/pypoint@v2.3.2...v3.0.0

  • 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

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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.

To help with the load of incoming pull requests:

@fredrike
Copy link
Contributor Author

@edenhaus we had a discussion a while ago #100843 (comment) regarding oauth2 in point integration. I did start from scratch with the config_flow and this works fine. The problem is now to migrate existing yaml configuration and using existing entries in core.config_entries. Can you point me in a direction where this is done successfully?

If I have an old entry in core.config_entries this codes fails with this error:

2024-05-27 22:27:46.344 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Minut Point for point
Traceback (most recent call last):
  File "/Users/fer/Documents/github/home-assistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/fer/Documents/github/home-assistant/homeassistant/components/point/__init__.py", line 113, in async_setup_entry
    await config_entry_oauth2_flow.async_get_config_entry_implementation(
  File "/Users/fer/Documents/github/home-assistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 428, in async_get_config_entry_implementation
    implementation = implementations.get(config_entry.data["auth_implementation"])
                                         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'auth_implementation'

Please advise how I can build a seemless update to the native oauth2 flow.

@fredrike fredrike marked this pull request as ready for review May 29, 2024 07:29
@fredrike
Copy link
Contributor Author

@edenhaus we had a discussion a while ago #100843 (comment) regarding oauth2 in point integration. I did start from scratch with the config_flow and this works fine. The problem is now to migrate existing yaml configuration and using existing entries in core.config_entries. Can you point me in a direction where this is done successfully?

If I have an old entry in core.config_entries this codes fails with this error:

2024-05-27 22:27:46.344 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry Minut Point for point
Traceback (most recent call last):
  File "/Users/fer/Documents/github/home-assistant/homeassistant/config_entries.py", line 594, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/fer/Documents/github/home-assistant/homeassistant/components/point/__init__.py", line 113, in async_setup_entry
    await config_entry_oauth2_flow.async_get_config_entry_implementation(
  File "/Users/fer/Documents/github/home-assistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 428, in async_get_config_entry_implementation
    implementation = implementations.get(config_entry.data["auth_implementation"])
                                         ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'auth_implementation'

Please advise how I can build a seemless update to the native oauth2 flow.

I've managed to solve this.

@edenhaus
Copy link
Contributor

edenhaus commented Jun 4, 2024

Please don't ping members asking for a review. This is not allowed.
Please be patient and wait until someone is reviewing your PR

@robkirk
Copy link

robkirk commented Jun 25, 2024

Any news on when this will get reviewed? This integration has been broken for over a year and Fredrike has kindly produced a suggested patch to fix it.

Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks for bumping the dependency! However, could you please update the PR description to contain at least one (or multiple) of the following:

  • A link to the release notes of this package version, and all versions in between.
  • A link to the changelog of this package.
  • A link to a Git(Hub) diff/compare view from the current version to the bumped version.

This allows us to review upstream changes, which is needed to decide this change is working as intended and/or if we can include it in, for example, a patch release of Home Assistant.

Thanks already! 👍

@home-assistant home-assistant bot marked this pull request as draft June 26, 2024 13:45
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@fredrike
Copy link
Contributor Author

Thanks for bumping the dependency! However, could you please update the PR description to contain at least one (or multiple) of the following:

  • A link to the release notes of this package version, and all versions in between.
  • A link to the changelog of this package.
  • A link to a Git(Hub) diff/compare view from the current version to the bumped version.

This allows us to review upstream changes, which is needed to decide this change is working as intended and/or if we can include it in, for example, a patch release of Home Assistant.

Thanks already! 👍

Here is the changed code in pypoint fredrike/pypoint@v2.3.2...v3.0.0

@fredrike fredrike marked this pull request as ready for review June 26, 2024 14:50
@home-assistant home-assistant bot requested a review from edenhaus June 26, 2024 14:50
@edenhaus
Copy link
Contributor

edenhaus commented Jul 5, 2024

Sanity check pypoint==3.0.0 ✔️

Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Please fix the merge conflicts and make sure the CI is passinh

@home-assistant home-assistant bot marked this pull request as draft July 5, 2024 14:55
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Tests are failing, can you take a look?

@home-assistant home-assistant bot marked this pull request as draft September 19, 2024 08:03
@fredrike
Copy link
Contributor Author

Tests are failing, can you take a look?

Sure, are we happy with the rest of the integration so far?

@fredrike fredrike marked this pull request as ready for review September 19, 2024 12:38
@joostlek joostlek merged commit 1768daf into home-assistant:dev Sep 20, 2024
43 of 44 checks passed
@joostlek joostlek deleted the point-oauth branch September 20, 2024 10:02
sarog pushed a commit to sarog/hass-core that referenced this pull request Sep 20, 2024
* initial oauth2 implementation

* fix unload_entry

* read old yaml/entry config

* update tests

* fix: pylint on tests

* Apply suggestions from code review

Co-authored-by: Robert Resch <robert@resch.dev>

* fix constants, formatting

* use runtime_data

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* fix missing import

* adopt to PointData dataclass

* fix typing

* add more strings (copied from weheat)

* move the PointData dataclass to avoid circular imports

* use configflow inspired by withings

* raise ConfigEntryAuthFailed

* it is called entry_lock

* fix webhook issue

* fix oauth_create_entry

* stop using async_forward_entry_setup

* Fixup

* fix strings

* fix issue that old config might be without unique_id

* parametrize tests

* Update homeassistant/components/point/config_flow.py

* Update tests/components/point/test_config_flow.py

* Fix

---------

Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
async_dispatcher_send(
self._hass, POINT_DISCOVERY_NEW.format(platform, DOMAIN), device_id
)

self._is_available = True
for home_id in self._client.homes:
if home_id not in self._known_homes:
await self._hass.config_entries.async_forward_entry_setups(
Copy link
Member

@MartinHjelmare MartinHjelmare Sep 21, 2024

Choose a reason for hiding this comment

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

We're only allowed to forward the config entry to a platform once until the config entry is unloaded. This looks like it could happen more than once for this config entry.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if more devices are added, what is the best approach for adding more devices on the fly?

Copy link
Member

Choose a reason for hiding this comment

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

You already have a way to add new entities from new devices using the dispatch helper.

await new_device(home_id, "alarm_control_panel")
self._known_homes.add(home_id)
for device in self._client.devices:
if device.device_id not in self._known_devices:
await self._hass.config_entries.async_forward_entry_setups(
Copy link
Member

Choose a reason for hiding this comment

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

As above.

JakeMartin-ICL pushed a commit to JakeMartin-ICL/home-assistant that referenced this pull request Sep 21, 2024
* initial oauth2 implementation

* fix unload_entry

* read old yaml/entry config

* update tests

* fix: pylint on tests

* Apply suggestions from code review

Co-authored-by: Robert Resch <robert@resch.dev>

* fix constants, formatting

* use runtime_data

* Apply suggestions from code review

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* fix missing import

* adopt to PointData dataclass

* fix typing

* add more strings (copied from weheat)

* move the PointData dataclass to avoid circular imports

* use configflow inspired by withings

* raise ConfigEntryAuthFailed

* it is called entry_lock

* fix webhook issue

* fix oauth_create_entry

* stop using async_forward_entry_setup

* Fixup

* fix strings

* fix issue that old config might be without unique_id

* parametrize tests

* Update homeassistant/components/point/config_flow.py

* Update tests/components/point/test_config_flow.py

* Fix

---------

Co-authored-by: Robert Resch <robert@resch.dev>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2024
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.

Unable to setup authentication with Minut Point
6 participants