-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Conversation
There was a problem hiding this 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.
0fb58be
to
659c348
Compare
659c348
to
81f0a7c
Compare
Tested this with a Philips TAPR802/12 radio and it works without any problems. |
de7e8cb
to
a49abee
Compare
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. |
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
There was a problem hiding this 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
|
||
YAML is deprecated, and imported automatically. | ||
SSDP discovery is temporarily retained - to be refactor subsequently. | ||
""" | ||
if discovery_info is not None: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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 insetup_entry
. In case of an import of the old YAML: the entity is migrated here but not added. It is subsequently added fromsetup_entry
. In case of an entity added via the config flow: only added viasetup_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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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
def __init__(self) -> None: | ||
"""Initialize flow.""" | ||
|
||
self._webfsapi_url: str | None = None | ||
self._name: str | None = None | ||
self._unique_id: str | None = None |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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?
assert self._name is not None | ||
assert self._webfsapi_url is not None |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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}", |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
try: | ||
await afsapi.get_power() | ||
except FSConnectionError as exception: | ||
raise PlatformNotReady from exception |
There was a problem hiding this comment.
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%]" |
There was a problem hiding this comment.
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
.
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
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: