Skip to content

Add config flow support to songpal integration#34714

Merged
rytilahti merged 21 commits into
home-assistant:devfrom
shenxn:songpal-configflow
May 6, 2020
Merged

Add config flow support to songpal integration#34714
rytilahti merged 21 commits into
home-assistant:devfrom
shenxn:songpal-configflow

Conversation

@shenxn
Copy link
Copy Markdown
Contributor

@shenxn shenxn commented Apr 26, 2020

Breaking change

Entries for songpal in configuration.yaml have to move out of a platform config to a top level config.

Proposed change

Add config flow support to songpal integration

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

Example entry for configuration.yaml:

# Example configuration.yaml

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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link
Copy Markdown

Hey there @rytilahti, mind taking a look at this pull request as its been labeled with a integration (songpal) you are listed as a codeowner for? Thanks!

Copy link
Copy Markdown
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Thanks a lot for doing this, this is a great improvement! 💯

I tested that the following methods are working:

  1. Existing configuration from yaml gets imported correctly.
  2. If ssdp integration is not loaded, using manual configuration works.
  3. SSDP integration works, but requires a change to ignore bravia televisions.

The following documentation needs to be updated:

Got this error in logs at some point with ssdp autodetected instance:

Apr 26 15:05:18 nuc hass[2714273]: 2020-04-26 15:05:18 ERROR (MainThread) [homeassistant.components.songpal.config_flow] Unable to import songpal configuration (None: None). Please check your endpoint.

Comment thread homeassistant/components/songpal/config_flow.py
Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py Outdated
def device_info(self):
"""Return the device info."""
return {
"identifiers": {(DOMAIN, self.unique_id)},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this info define connections, too?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We only need either connections or identifiers.

Comment thread homeassistant/components/songpal/strings.json Outdated
Comment thread homeassistant/components/songpal/strings.json Outdated
Comment thread homeassistant/components/songpal/translations/en.json Outdated
Comment thread homeassistant/components/songpal/translations/en.json Outdated
@shenxn
Copy link
Copy Markdown
Contributor Author

shenxn commented Apr 27, 2020

@rytilahti I couldn't reproduce that error in my dev environment. The import step should never be triggered when there is nothing in the yaml configuration. Can you try to figure out what causes that problem?

@shenxn shenxn marked this pull request as ready for review April 27, 2020 01:01
@shenxn shenxn requested a review from rytilahti April 27, 2020 01:36
Copy link
Copy Markdown
Member

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks good to me, but I'm woefully unaware of how to write proper configuration flows, so let's hope someone else will also take a look at it!

Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py
Comment thread homeassistant/components/songpal/media_player.py Outdated
@rytilahti rytilahti added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Apr 27, 2020
@shenxn
Copy link
Copy Markdown
Contributor Author

shenxn commented Apr 27, 2020

@rytilahti Thanks for the review. I'm gonna make some changes to the name and model part.

@shenxn shenxn requested a review from rytilahti April 27, 2020 04:46
@rytilahti
Copy link
Copy Markdown
Member

rytilahti commented Apr 27, 2020

@shenxn do you think it would make sense to add support for unloading also as part of this PR? https://developers.home-assistant.io/docs/config_entries_index/#unloading-entries - this would involve stop listening to the events and cleaning up the hass.data for the domain, so it should be fairly easy to do (and would allow removing the integration without restarts).

Otherwise this looks good to go!

@shenxn
Copy link
Copy Markdown
Contributor Author

shenxn commented Apr 27, 2020

@rytilahti That's a good thing to have. I'll add it today.

@shenxn shenxn force-pushed the songpal-configflow branch from 7294dcd to f80a797 Compare April 28, 2020 07:06
@shenxn
Copy link
Copy Markdown
Contributor Author

shenxn commented Apr 28, 2020

@rytilahti Done. I didn't figure out how to easily rediscover the removed device without restarting. But since the device is manually deleted, I think that is not necessary.

Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/strings.json Outdated
Comment thread .coveragerc Outdated
@shenxn shenxn requested a review from raman325 April 29, 2020 01:56
Comment thread homeassistant/components/songpal/config_flow.py Outdated
Comment thread homeassistant/components/songpal/config_flow.py Outdated
"""Set up the Songpal platform."""
if PLATFORM not in hass.data:
hass.data[PLATFORM] = {}
async def async_setup_platform(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function can be removed.

Comment thread homeassistant/components/songpal/__init__.py Outdated
@raman325
Copy link
Copy Markdown
Contributor

raman325 commented May 1, 2020

Just to note, by changing how the configuration is defined, this will be a breaking change. But every config flow implementation from a former platform config integration is a breaking change, so no concerns there 😄

Copy link
Copy Markdown
Contributor

@raman325 raman325 left a comment

Choose a reason for hiding this comment

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

LGTM

@raman325
Copy link
Copy Markdown
Contributor

raman325 commented May 4, 2020

@shenxn please rebase on dev and force push to resolve the conflict

@shenxn
Copy link
Copy Markdown
Contributor Author

shenxn commented May 5, 2020

@raman325 Done. Should be good to merge.

@rytilahti
Copy link
Copy Markdown
Member

Thank you @shenxn for the PR and for your willingness to become a codeowner, the more eyeballs, the better. Thank you @raman325 for your reviews, I think it's time to get this merged now! 🎉

@rytilahti rytilahti merged commit 33077f0 into home-assistant:dev May 6, 2020
Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Some comments for the future.

endpoint = config_entry.data[CONF_ENDPOINT]

if endpoint in hass.data[PLATFORM]:
if endpoint in hass.data[DOMAIN]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is already checked in the config flow.

"""Test the songpal config flow."""
import copy

from asynctest import MagicMock, patch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please import all mocks and patch from tests.async_mock.

}

for device in hass.data[PLATFORM].values():
for device in hass.data[DOMAIN].values():
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can use the platform service registration helper and avoid storing the entities.

https://developers.home-assistant.io/docs/dev_101_services#entity-services

@shenxn shenxn mentioned this pull request May 7, 2020
20 tasks
@shenxn shenxn deleted the songpal-configflow branch May 7, 2020 05:55
@lock lock Bot locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

breaking-change cla-signed has-tests integration: songpal new-feature 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.

6 participants