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 frontier_silicon #64365

Merged
merged 37 commits into from
Mar 10, 2023
Merged

Conversation

wlcrs
Copy link
Contributor

@wlcrs wlcrs commented Jan 18, 2022

Breaking change

Frontier Silicon integration moves to configuration via Config Flow. Users need to remove their existing integration from configuration.yaml .

Proposed change

Update to FSAPI 0.2.0, which is a large overhaul of the previous implementation. (cfr: wlcrs/python-afsapi@0.0.4...0.2.0 )

It does not longer interfere with the use of the UNDOK application to control the radio.

This PR is the first in a series that will add new functionality to this integration (oa. selecting presets). As per the instructions I'm splitting these out in multiple PR's to ease the process.

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

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

.coveragerc Show resolved Hide resolved
Copy link
Contributor

@iMicknl iMicknl left a comment

Choose a reason for hiding this comment

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

Thanks! I had a quick look to get you started. Please add untested files to .coveragerc or add tests. Currently this PR is hard to review since there are warnings due to untested code.

homeassistant/components/frontier_silicon/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/media_player.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/manifest.json Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/frontier_silicon/config_flow.py Outdated Show resolved Hide resolved
@wlcrs wlcrs marked this pull request as draft January 19, 2022 19:23
@wlcrs wlcrs marked this pull request as ready for review January 21, 2022 21:13
@wlcrs wlcrs force-pushed the fsapi-0.2.0-update branch from 0fb58be to 659c348 Compare January 27, 2022 15:38
@wlcrs wlcrs marked this pull request as draft January 27, 2022 16:59
@wlcrs wlcrs force-pushed the fsapi-0.2.0-update branch from 659c348 to 81f0a7c Compare January 27, 2022 18:48
@wlcrs wlcrs marked this pull request as ready for review January 27, 2022 20:00
@TopdRob
Copy link
Contributor

TopdRob commented Feb 9, 2022

Tested this with a Philips TAPR802/12 radio and it works without any problems.

@frenck frenck added the config-flow This integration migrates to the UI by adding a config flow label Mar 19, 2022
@wlcrs wlcrs requested a review from a team as a code owner April 5, 2022 15:24
@wlcrs
Copy link
Contributor Author

wlcrs commented Mar 9, 2023

Hi @epenet , thank you for your feedback on this PR in the last few days. Can you please finalize your review so that we have ample time to add the other config flows in 2023.4 release? I've already used your feedback from this PR to improve the code in the other flows (+their tests), so it should be smooth sailing.

@home-assistant home-assistant bot marked this pull request as draft March 9, 2023 08:27
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
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, but I'd like a second pair of eyes

@epenet epenet added second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. deprecation Indicates a breaking change to happen in the future and removed breaking-change integration: discovery dependency code-quality core labels Mar 9, 2023

YAML is deprecated, and imported automatically.
SSDP discovery is temporarily retained - to be refactor subsequently.
"""
if discovery_info is not None:
Copy link
Member

Choose a reason for hiding this comment

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

You should only do the import in the platform setup and add the media player entities only from the setup_entry method. Right now you add the entities twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In which case are the entities loaded twice? I fail to see what problem you are mentioning?

In case of an SSDP discovery: they are added here in async_setup_platform and not in setup_entry.
In case of an import of the old YAML: the entity is migrated here but not added. It is subsequently added from setup_entry.
In case of an entity added via the config flow: only added via setup_entry.

Copy link
Member

@Kane610 Kane610 Mar 9, 2023

Choose a reason for hiding this comment

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

In which case are the entities loaded twice? I fail to see what problem you are mentioning?

In case of an SSDP discovery: they are added here in async_setup_platform and not in setup_entry. In case of an import of the old YAML: the entity is migrated here but not added. It is subsequently added from setup_entry. In case of an entity added via the config flow: only added via setup_entry.

Aah sorry, I apparently forgot the nomenclature for the old way of loading entities. Still good I mentioned it as you should also move the SSDP discovery from the old discovery way to the config flow, there shouldn't be any in-between steps, its either old platform or new way. Can't say that I have any other comments apart from this though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - that was a recommendation that I made, to reduce the size of the PR.
I felt it was easier to review without SSDP, and then migrate SSDP as a follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

Ok. And this was the future config entry PR mentioned? If that is the case I can be ok with that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll be creating a PR for the following branch from the moment this one is merged: wlcrs/home-assistant-core@fsapi-0.2.0-update...wlcrs:home-assistant-core:frontier_silicon_ssdp

@wlcrs wlcrs marked this pull request as ready for review March 9, 2023 19:22
@home-assistant home-assistant bot requested review from epenet and Kane610 March 9, 2023 19:22
@epenet epenet merged commit b8bda93 into home-assistant:dev Mar 10, 2023
@epenet
Copy link
Contributor

epenet commented Mar 10, 2023

Thanks @wlcrs 👍
And thanks @Kane610 for the second opinion👍

Copy link
Member

@frenck frenck 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 these comments in a new PR.

Thanks 👍

../Frenck

Comment on lines +40 to +45
def __init__(self) -> None:
"""Initialize flow."""

self._webfsapi_url: str | None = None
self._name: str | None = None
self._unique_id: str | None = None
Copy link
Member

Choose a reason for hiding this comment

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

These can be set up as class variables instead.

try:
afsapi = AFSAPI(self._webfsapi_url, import_info[CONF_PIN])

self._unique_id = await afsapi.get_radio_id()
Copy link
Member

Choose a reason for hiding this comment

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

Why is this assigned to a class variable? It isn't used anywhere later on?

Comment on lines +173 to +174
assert self._name is not None
assert self._webfsapi_url is not None
Copy link
Member

Choose a reason for hiding this comment

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

These asserts are not needed. It means the typing isn't correct. Please correct that instead and remove these asserts.

errors=errors,
)

async def _create_entry(self, pin: str | None = None) -> FlowResult:
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this method adds complexity that is not needed.
Instead of a simple async_create_entry call, we not have additional variables and calls over the place (that are out of standard).

I suggest to just remove this method fully, as the only thing it does is making a single call.

"flow_title": "{name}",
"step": {
"user": {
"title": "Frontier Silicon Setup",
Copy link
Member

Choose a reason for hiding this comment

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

This is already implied, please remove title.

@@ -0,0 +1,35 @@
{
"config": {
"flow_title": "{name}",
Copy link
Member

Choose a reason for hiding this comment

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

This is the default flow title and should thus be removed.


assert result3["type"] == FlowResultType.FORM
assert result2["step_id"] == "device_config"
assert result3["errors"] == {"base": result_error}
Copy link
Member

Choose a reason for hiding this comment

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

This test is incomplete. Please finish the test with the user doing an second attempt and finishes the config flow until the create entry.

This ensures there are no side-effects from the error.


assert result2["type"] == FlowResultType.FORM
assert result2["step_id"] == "user"
assert result2["errors"] == {"base": result_error}
Copy link
Member

Choose a reason for hiding this comment

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

This test is incomplete. Please finish the test with the user doing an second attempt and finishes the config flow until the create entry.

This ensures there are no side-effects from the error.

@wlcrs wlcrs deleted the fsapi-0.2.0-update branch March 10, 2023 13:24
@github-actions github-actions bot locked and limited conversation to collaborators Mar 11, 2023
try:
await afsapi.get_power()
except FSConnectionError as exception:
raise PlatformNotReady from exception
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be ConfigEntryNotReady for it to work as intended

"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
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 abort reason strings for cannot_connect, invalid_auth and unknown.

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 has-tests integration: frontier_silicon second-opinion-wanted Add this label when a reviewer needs a second opinion from another member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants