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

Convert Vallox integration to config flow #62780

Merged
merged 21 commits into from
Dec 28, 2021

Conversation

slovdahl
Copy link
Contributor

@slovdahl slovdahl commented Dec 25, 2021

Breaking change

The Vallox integration migrated to configuration via the UI. Configuring Vallox via YAML configuration has been deprecated and will be removed in a future Home Assistant release.

Your existing YAML configuration is automatically imported on upgrade to this release; and thus can be safely removed from your YAML configuration after upgrading.

Proposed change

Update the Vallox integration to support UI configuration, and make the initialization of the integration more idiomatic. See #62308 (comment) and #61708 for more context.

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.
  • 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

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

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

Thanks. 👍

Please add test coverage for the config flow. We need 100% for these.

@andre-richter
Copy link
Contributor

Awesome. Thanks a lot for your effort 👍

@slovdahl
Copy link
Contributor Author

Thanks. 👍

Please add test coverage for the config flow. We need 100% for these.

Good point, added some more tests and improved the quality of the existing tests a bit too. How can I check the test coverage locally? 🤔 I ran tox -e cov -- tests/components/vallox locally before I opened the PR but that was all green. The reports available from CI were very useful.

@bdraco
Copy link
Member

bdraco commented Dec 26, 2021

pytest --cov=homeassistant/components/vallox/ --cov-report term-missing -- tests/components/vallox/

Inside the venv

slovdahl added a commit to slovdahl/home-assistant.io that referenced this pull request Dec 26, 2021
@slovdahl
Copy link
Contributor Author

Updated docs: home-assistant/home-assistant.io#20861

@slovdahl
Copy link
Contributor Author

Please add test coverage for the config flow. We need 100% for these.

This has now been fixed.

@slovdahl
Copy link
Contributor Author

One thing I really don't know is if it's possible to support unloading the integration with async_unload_entry. I did add it from the start, but realized there might be things that need to be cleaned up (closing the WebSocket connection maybe?). If someone is able to point me in the right direction with regard to this I could probably fix it at the same time.

@andre-richter
Copy link
Contributor

andre-richter commented Dec 26, 2021

One thing I really don't know is if it's possible to support unloading the integration with async_unload_entry. I did add it from the start, but realized there might be things that need to be cleaned up (closing the WebSocket connection maybe?). If someone is able to point me in the right direction with regard to this I could probably fix it at the same time.

I peeked into the vallox websocket API. Although I don’t know anything about websockets, it seems a connection is created (and closed again) for each request, and not once on class instantiation and kept open. So maybe no cleanup needed.

https://github.com/yozik04/vallox_websocket_api/blob/5c45be59e46bcd9cf9a14c92b4b1f48d86f38191/vallox_websocket_api/client.py#L195-L204

@slovdahl
Copy link
Contributor Author

Please run python3 -m script.hassfest

Passes locally:

root ➜ /workspaces/core (vallox-config-flow) $ python3 -m script.hassfest
Validating codeowners... done in 0.02s
Validating config_flow... done in 0.03s
Validating dependencies... done in 9.33s
Validating dhcp... done in 0.00s
Validating json... done in 0.00s
Validating manifest... done in 0.07s
Validating mqtt... done in 0.00s
Validating requirements... done in 0.02s
Validating services... done in 3.21s
Validating ssdp... done in 0.00s
Validating translations... done in 1.47s
Validating usb... done in 0.00s
Validating zeroconf... done in 0.00s
Validating coverage... done in 0.06s
Validating mypy_config... done in 0.02s

Integrations: 1020
Invalid integrations: 0

@bdraco
Copy link
Member

bdraco commented Dec 27, 2021

I checked the CI, and it looks like the problem was github having issues at the time and everything is fine with hassfest. I restarted the CI.

Copy link
Member

@bdraco bdraco 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 👍

Would you please retest yaml imports before I merge this?

@andre-richter
Copy link
Contributor

andre-richter commented Dec 27, 2021

Would you please retest yaml imports before I merge this?

I just tested this, and noticed no issues 👍. Config entry created from import was there, and you get the warning/hint to remove the yaml entry.

@slovdahl
Copy link
Contributor Author

Would you please retest yaml imports before I merge this?

Tested everything once more, seems to work in line with expectations.

@bdraco bdraco merged commit b5fd2e0 into home-assistant:dev Dec 28, 2021
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!

try:
await validate_host(self.hass, host)
except InvalidHost:
_LOGGER.exception("An invalid host is configured for Vallox")
Copy link
Member

Choose a reason for hiding this comment

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

We normally only log the stack trace for unknown exceptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, fixed this and all other comments in #63032.

"step": {
"user": {
"title": "Vallox",
"description": "Set up the Vallox integration. If you have problems with configuration go to https://www.home-assistant.io/integrations/vallox.",
Copy link
Member

Choose a reason for hiding this comment

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

Links are best to put in a description placeholder to avoid translation of the link.

"description": "Set up the Vallox integration. If you have problems with configuration go to https://www.home-assistant.io/integrations/vallox.",
"data": {
"host": "[%key:common::config_flow::data::host%]",
"name": "[%key:common::config_flow::data::name%]"
Copy link
Member

Choose a reason for hiding this comment

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

There's no name item in the user step form.

"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_host": "[%key:common::config_flow::error::invalid_host%]"
}
Copy link
Member

Choose a reason for hiding this comment

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

We're missing a string for unknown error.

},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
},
Copy link
Member

Choose a reason for hiding this comment

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

We're missing many abort reasons.

Copy link
Member

@bdraco bdraco Dec 28, 2021

Choose a reason for hiding this comment

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

Looks like invalid_host, cannot_connect, unknown are missing here

assert result["reason"] == "already_configured"


async def test_import_cannot_connect_OSError(hass: HomeAssistant) -> None:
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 lowercase snake_case function names.

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 thought about it too, but because no linter or pre-commit check complained I just assumed it was fine. Could/should it be enforced somehow? 🤔

@slovdahl slovdahl mentioned this pull request Dec 29, 2021
22 tasks
@slovdahl slovdahl deleted the vallox-config-flow branch December 30, 2021 11:34
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2021
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