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 Smarty #127540

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft

Conversation

joostlek
Copy link
Member

@joostlek joostlek commented Oct 4, 2024

Breaking change

Configuring Smarty via YAML is deprecated, your configuration has been imported. Please configure Smarty via the UI.

Proposed change

Add config flow to Smarty

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

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 Hacktoberfest has-tests integration: smarty new-feature Quality Scale: No score labels Oct 4, 2024
@home-assistant
Copy link

home-assistant bot commented Oct 4, 2024

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

Code owner commands

Code owners of smarty 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 smarty Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

homeassistant/components/smarty/fan.py Outdated Show resolved Hide resolved
homeassistant/components/smarty/sensor.py Outdated Show resolved Hide resolved
joostlek and others added 3 commits October 4, 2024 11:15
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Oct 18, 2024
@joostlek
Copy link
Member Author

@marcodutto can you maybe test this PR?

Comment on lines +117 to +119
async def async_unload_entry(hass: HomeAssistant, entry: SmartyConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you forget to cancel the periodic call to poll_device_update. Do we need to do anything else to shut down the client?

self, import_config: dict[str, Any]
) -> ConfigFlowResult:
"""Handle a flow initialized by import."""
self._async_abort_entries_match({CONF_HOST: import_config[CONF_HOST]})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this check needed, an import flow is only started if there are no existing config entries?

Comment on lines +40 to +42
return self.async_create_entry(
title=user_input[CONF_HOST], data=user_input
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the API not provide any source for a unique ID?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, it's just a modbus device

try:
if smarty.update():
return None
except Exception: # noqa: BLE001
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there nothing more narrow to catch?
Also, I think we should log here.

"issues": {
"deprecated_yaml_import_issue_unknown": {
"title": "YAML import failed with unknown error",
"description": "Configuring {integration_title} using YAML is being removed but there was an unknown error while importing your existing configuration.\nSetup will not proceed.\n\nVerify that your {integration_title} is operating correctly and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the `{domain}` configuration from your configuration.yaml entirely, restart Home Assistant, and add the {integration_title} integration manually."
Copy link
Contributor

Choose a reason for hiding this comment

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

There doesn't seem to be anything specific for the Smarty integration here. Please use the translations from the homeassistant integration instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

But this is the translation where we explain that we could not import it



async def setup_integration(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Fixture for setting up the component."""
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a fixture


@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Please improve the docstring

@home-assistant home-assistant bot marked this pull request as draft October 21, 2024 19:23
@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.

@emontnemery
Copy link
Contributor

As discussed on Discord, this PR either needs to have test coverage of modified code, or be tested with Smarty devices (doing both would of course be the best option).

@marcodutto
Copy link

As discussed on Discord, this PR either needs to have test coverage of modified code, or be tested with Smarty devices (doing both would of course be the best option).

I'm on a business trip right now, I'll be testing this in two days with my Smarty device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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 Hacktoberfest has-tests integration: smarty new-feature Quality Scale: No score smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants