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 Yamaha #131246

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

Add config flow to Yamaha #131246

wants to merge 19 commits into from

Conversation

slyoldfox
Copy link
Contributor

@slyoldfox slyoldfox commented Nov 22, 2024

Breaking change

Proposed change

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 130820
  • 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 bugfix 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: yamaha Quality Scale: No score labels Nov 22, 2024
@slyoldfox
Copy link
Contributor Author

As discussed in #130820 this is a first attempt to add a config flow to the Yamaha integration.

As this was a first attempt at this and for people that are stumbling on this in the future, it's a mix of https://github.com/home-assistant/core/pull/51561/files and the current state of the yahama_musiccast integration.

I've removed references to rxv.find in this integration because the SSDP logic in rxv contains a bug and the library is hardly maintained. It now relies on the internal SSDP logic in HA.

I still have 2 unit tests marked as ignore in which I need your help to understand if they can be removed.

Hope this is more or less adequate for a first attempt :-)

@epenet epenet changed the title #130820 Add config flow to Yamaha Add config flow to Yamaha Nov 22, 2024
@joostlek
Copy link
Member

The CI is failing

@slyoldfox
Copy link
Contributor Author

The CI is failing

Yes sorry about that, it seems my dev environment is not running the git pre commit hooks, i'll fix this as soon as possible!

@joostlek joostlek marked this pull request as draft November 22, 2024 11:07
@joostlek
Copy link
Member

I'll convert to draft for now.

I'll also ping @pssc and @Petro31 since they know about the device and might be able to help you.

@slyoldfox slyoldfox marked this pull request as ready for review November 22, 2024 11:41
@joostlek
Copy link
Member

FYI, you don't have to add the issue to the commit message. If you want to do so, feel free to do so, but you're not required to :)

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Some initial comments to steer into the right direction

homeassistant/components/yamaha/yamaha_config_info.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
@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.

@home-assistant home-assistant bot marked this pull request as draft November 22, 2024 11:49
Copy link
Contributor

@arturpragacz arturpragacz left a comment

Choose a reason for hiding this comment

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

The config flow itself seems not quite finished at the moment, so I have not reviewed it.

Instead couple of pointers for some other stuff.

homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
* Realign code with yamaha_musiccast and store UPNP Description instead of model and name
* Reuse rxv.ssdp.rxv_details for querying the rxv data instead of querying from HA code
@slyoldfox slyoldfox marked this pull request as ready for review November 27, 2024 17:41
@slyoldfox
Copy link
Contributor Author

I hope this is moving in the right direction, so I've requested another review.
Not sure why the code coverage is now failing even though I added tests and seem to have covered all of config_flow.py

Comment on lines +42 to +43
if entry.data.get(CONF_UPNP_DESC) is None:
hass.config_entries.async_update_entry(
Copy link
Member

Choose a reason for hiding this comment

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

How does this work?

Like I am known with the technique to do this in the config flow discovery step, so for example when someone setup the integration using the host and then we find either a zeroconf or DHCP flow that we can link to it (for example if the entry uses the same host and is loaded) and then we update the entry to have that unique identifier. Examples of this are fritzbox and reolink, both do this in the DHCP step I believe.

From my understanding this does the same, but I am wondering how the order of discovery works, because if the integration is setup and after that the SSDP picks up the advertisement, this code is not run anymore.

So I am not really sure what is best here, but I do want to share this info with you to at stir up the discussion.

Comment on lines +46 to +47
CONF_HOST: entry.data[CONF_HOST],
CONF_SERIAL: entry.data[CONF_SERIAL],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CONF_HOST: entry.data[CONF_HOST],
CONF_SERIAL: entry.data[CONF_SERIAL],
**entry.data,

},
)

hass.data.setdefault(DOMAIN, {})
Copy link
Member

Choose a reason for hiding this comment

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

You're storing nothing here so this line can be removed

Comment on lines 53 to 55
rxv_details = await YamahaConfigInfo.get_rxv_details(
entry.data[CONF_UPNP_DESC], hass
)
Copy link
Member

Choose a reason for hiding this comment

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

So our code relies on having that info, but why do we then only set the upnp description during initialisation and why not during the config (or import) flow?

return upnp_desc


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Copy link
Member

Choose a reason for hiding this comment

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


return await self.async_step_confirm()

async def async_step_confirm(self, user_input=None) -> ConfigFlowResult:
Copy link
Member

Choose a reason for hiding this comment

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

missing typing

Comment on lines +149 to +152
OPTION_INPUT_SOURCES_IGNORE: user_input.get(
OPTION_INPUT_SOURCES_IGNORE
)
or [],
Copy link
Member

Choose a reason for hiding this comment

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

Let's wrap these multiline statements in parenthesis

Comment on lines +159 to +161
async def async_step_import(self, import_data: dict) -> ConfigFlowResult:
"""Import data from configuration.yaml into the config flow."""
return await self.async_step_user(import_data)
Copy link
Member

Choose a reason for hiding this comment

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

While for the user flow we want to raise errors, for the import flow we should abort when an error happens.

Also, typing is missing

homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft December 9, 2024 09:38
…class to utils, reverted self._attr_unique_id change in media_player
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed code-quality 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: yamaha Quality Scale: No score
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants