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 Config Flow to Obihai #88627

Merged
merged 30 commits into from
Feb 27, 2023

Conversation

ejpenney
Copy link
Contributor

@ejpenney ejpenney commented Feb 22, 2023

Breaking change

N/A

Proposed change

Adds config_flow to the Obihai integration, deprecates YAML configuration.

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

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:

  • Documentation added/updated for [www.home-assistant.io(http://www.home-assistant.io][docs-repository/)]

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:

@home-assistant home-assistant bot added cla-signed config-flow This integration migrates to the UI by adding a config flow deprecation Indicates a breaking change to happen in the future integration: obihai new-feature labels Feb 22, 2023
@home-assistant
Copy link

Hey there @dshokouhi, mind taking a look at this pull request as it has been labeled with an integration (obihai) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of obihai can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign obihai Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@dshokouhi
Copy link
Member

This great! Please also consider adding yourself to the codeowners for this integration as I have not done any updates to this in a very long time 😬

@ejpenney
Copy link
Contributor Author

Ugh, bit by pre-commit. Running it offline now, another commit coming momentarily...

@ejpenney ejpenney force-pushed the ejpenney_obihai_enhancements branch from c3f2619 to 1c92605 Compare February 22, 2023 19:11
@ejpenney
Copy link
Contributor Author

I don't know what the heck is going on. These tests are passing for me offline.

@ejpenney
Copy link
Contributor Author

@dshokouhi, looks like I got the pre-commit working. Added myself as code owner. Let me know if you think anything else needs done!

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.

Please split into smaller pr

  • one for code owners
  • one for reboot service
  • one for ConfigFlow (without dhcp)
  • one follow up for dhcp

@home-assistant home-assistant bot marked this pull request as draft February 22, 2023 20:20
@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.

@ejpenney ejpenney force-pushed the ejpenney_obihai_enhancements branch from eb6f859 to 0620082 Compare February 22, 2023 21:02
@ejpenney ejpenney changed the title Obihai: Add Config Flow and reboot service Obihai: Add Config Flow Feb 22, 2023
@ejpenney ejpenney marked this pull request as ready for review February 22, 2023 21:09
@home-assistant home-assistant bot requested a review from epenet February 22, 2023 21:09
.coveragerc Outdated Show resolved Hide resolved
homeassistant/components/obihai/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/obihai_api.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft February 22, 2023 21:14
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.

Also please ensure that you have 100% test coverage on config flow.

homeassistant/components/obihai/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/strings.json Outdated Show resolved Hide resolved
@ejpenney ejpenney marked this pull request as ready for review February 22, 2023 23:45
@home-assistant home-assistant bot requested a review from epenet February 22, 2023 23:45
@ejpenney
Copy link
Contributor Author

ejpenney commented Feb 22, 2023

@epenet, I believe I have resolved (or otherwise addressed) all your concerns. When this gets submitted I'll submit a few other PRs. The other config_flow changes might take a bit since they don't have tests...

Let me know if it's looking good.

homeassistant/components/obihai/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/const.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/obihai_api.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/strings.json Outdated Show resolved Hide resolved
homeassistant/components/obihai/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/obihai/sensor.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft February 23, 2023 10:33
ejpenney and others added 13 commits February 27, 2023 07:25
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
@ejpenney ejpenney force-pushed the ejpenney_obihai_enhancements branch from 8763c3f to 5e72f24 Compare February 27, 2023 07:25
@ejpenney ejpenney marked this pull request as ready for review February 27, 2023 07:26
@home-assistant home-assistant bot requested a review from epenet February 27, 2023 07:26
@home-assistant home-assistant bot marked this pull request as draft February 27, 2023 08:10
ejpenney and others added 2 commits February 27, 2023 07:26
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
@ejpenney ejpenney marked this pull request as ready for review February 27, 2023 15:29
@home-assistant home-assistant bot requested a review from epenet February 27, 2023 15:30
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 👍

@epenet epenet merged commit 0e8d28d into home-assistant:dev Feb 27, 2023
Copy link
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.

Please address the comments in a new PR. Thanks!

async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
"""Handle a flow initialized by importing a config."""
self._async_abort_entries_match({CONF_HOST: config[CONF_HOST]})
return self.async_create_entry(
Copy link
Member

Choose a reason for hiding this comment

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

We should test the connection to the device with the config before creating the config entry, as we do in the user step. Abort if it doesn't work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you have objections to just using LOGGER to drop a warning in system log if YAML import failed? I suppose we could create an "issue", but that seems overkill IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Strike that, I'm just going to use async_abort and hand it cannot_connect.

"manual_migration",
breaks_in_ha_version="2023.6.0",
is_fixable=False,
severity=issue_registry.IssueSeverity.ERROR,
Copy link
Member

Choose a reason for hiding this comment

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

Please use warning severity.

@@ -148,6 +157,10 @@ def icon(self):

def update(self) -> None:
"""Update the sensor."""
if not self._pyobihai.check_account():
Copy link
Member

Choose a reason for hiding this comment

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

What does False mean here? If we can't connect we should set the available property to False in the entity. If credentials are bad we should start a reauth flow.

https://developers.home-assistant.io/docs/config_entries_config_flow_handler#reauthentication

Copy link
Contributor Author

@ejpenney ejpenney Feb 27, 2023

Choose a reason for hiding this comment

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

The available property will return False if self._state is None which is what we've done here. I'll take a look at the re-auth feedback, though I think that should be a PR in-and-of-itself as it would require new classes and tests.

Copy link
Member

Choose a reason for hiding this comment

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

Setting the native value to None means that the state is unknown. This is different than state unavailable. It would be better not to couple these things to avoid confusion when reading the code.

},
"issues": {
"manual_migration": {
"title": "Manual migration required for Obihai",
Copy link
Member

Choose a reason for hiding this comment

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

What manual migration is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you be more specific about what's confusing here? This is C+P from other components that require migration from YAML. This is just a title. The description is... more descriptive of the process. Would you like the title to describe how to migrate?

Copy link
Member

Choose a reason for hiding this comment

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

The title is incorrect. There is no manual migration required (it has already migrated). It should state the YAML configuration is deprecated and should be removed.

@ejpenney ejpenney mentioned this pull request Feb 27, 2023
19 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2023
@ejpenney ejpenney deleted the ejpenney_obihai_enhancements branch April 3, 2023 19:54
@ejpenney ejpenney restored the ejpenney_obihai_enhancements branch April 6, 2023 18:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed config-flow This integration migrates to the UI by adding a config flow deprecation Indicates a breaking change to happen in the future integration: obihai new-feature Quality Scale: No score
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants