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

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

Add config flow to Yamaha #131246

wants to merge 13 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
Comment on lines 81 to 82
if serial_number is None:
errors["base"] = "no_yamaha_device"
Copy link
Member

Choose a reason for hiding this comment

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

Are there devices without serial number?

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 am unsure, I did assume there was going to be. I was doubting to add CONF_HOST as fallback as the unique_id but that would not accepted I read?
How should I move forward with this?

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'm gonna leave this for now, the implementation is the same as the Yamaha Musiccast integration now. I found some SSDP replies through github (https://github.com/foxthefox/yamaha-yxc-nodejs/blob/da9039e3edb1cc338b6f5c19710bbbfb6770b428/lib/data/ssdp_answer_WX30.xml#L17 and https://github.com/foxthefox/yamaha-yxc-nodejs/blob/da9039e3edb1cc338b6f5c19710bbbfb6770b428/lib/data/ssdp_answer_YSP1600.xml#L17).
As well as my RX-A2010

Copy link
Contributor

Choose a reason for hiding this comment

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

@joostlek @slyoldfox yes from my experience there seem to be ssdp responses without serial in the wild, and the rxv lib doesn't support /cant get the serial post ssdp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pssc does that include crawls from http://IP/YamahaRemoteControl/desc.xml ?
@joostlek how should I handle these?

homeassistant/components/yamaha/config_flow.py Outdated Show resolved Hide resolved
config_entry: ConfigEntry,
) -> OptionsFlow:
"""Return the options flow."""
return YamahaOptionsFlowHandler(config_entry)
Copy link
Member

Choose a reason for hiding this comment

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

Config flow.py is required to be 100% unit tested

Comment on lines 103 to 110
if config.get(CONF_HOST):
if hass.config_entries.async_entries(DOMAIN) and config[CONF_HOST] not in [
entry.data[CONF_HOST] for entry in hass.config_entries.async_entries(DOMAIN)
]:
_LOGGER.error(
"Configuration in configuration.yaml is not supported anymore. "
"Please add this device using the config flow: %s",
config[CONF_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 should raise issues instead. Check the smarty integration for an example. (but keep the YAML entrypoint the same)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also IMO better to let it go to the config flow and abort there instead of checking here.

Comment on lines +222 to +224
OPTION_INPUT_SOURCES_IGNORE: user_input.get(
OPTION_INPUT_SOURCES_IGNORE
),
Copy link
Member

Choose a reason for hiding this comment

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

For the ignore one, I believe there is a way on the device to limit the sources, can explore that option?

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 checked my receiver (RX-A2010) but didn't find a way to ignore inputs.
I can rename inputs on the device but even those modified names do not get propagated outside the unit, the output of rxv.inputs() stays the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here not on my device (RX2020) there is no functionality to support it in the rxv lib.

Copy link
Contributor

Choose a reason for hiding this comment

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

It also isn't supported by the integration in HACS via the device and that uses a different protocol / method than rxv.

@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
Comment on lines 103 to 110
if config.get(CONF_HOST):
if hass.config_entries.async_entries(DOMAIN) and config[CONF_HOST] not in [
entry.data[CONF_HOST] for entry in hass.config_entries.async_entries(DOMAIN)
]:
_LOGGER.error(
"Configuration in configuration.yaml is not supported anymore. "
"Please add this device using the config flow: %s",
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.

Also IMO better to let it go to the config flow and abort there instead of checking here.

homeassistant/components/yamaha/media_player.py Outdated Show resolved Hide resolved
)
)
else:
_LOGGER.error(
Copy link
Contributor

Choose a reason for hiding this comment

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

Start a discovery instead and for each discovered receiver launch an import flow.

* 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

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