Add config flow support to songpal integration#34714
Conversation
|
Hey there @rytilahti, mind taking a look at this pull request as its been labeled with a integration ( |
rytilahti
left a comment
There was a problem hiding this comment.
Thanks a lot for doing this, this is a great improvement! 💯
I tested that the following methods are working:
- Existing configuration from yaml gets imported correctly.
- If
ssdpintegration is not loaded, using manual configuration works. - SSDP integration works, but requires a change to ignore bravia televisions.
The following documentation needs to be updated:
- https://www.home-assistant.io/integrations/songpal/
- https://www.home-assistant.io/integrations/ssdp/
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.
| def device_info(self): | ||
| """Return the device info.""" | ||
| return { | ||
| "identifiers": {(DOMAIN, self.unique_id)}, |
There was a problem hiding this comment.
Should this info define connections, too?
There was a problem hiding this comment.
We only need either connections or identifiers.
|
@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? |
rytilahti
left a comment
There was a problem hiding this comment.
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!
|
@rytilahti Thanks for the review. I'm gonna make some changes to the name and model part. |
|
@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 Otherwise this looks good to go! |
|
@rytilahti That's a good thing to have. I'll add it today. |
7294dcd to
f80a797
Compare
|
@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. |
| """Set up the Songpal platform.""" | ||
| if PLATFORM not in hass.data: | ||
| hass.data[PLATFORM] = {} | ||
| async def async_setup_platform( |
There was a problem hiding this comment.
To add config flow, the integration can't use platform set up and should be set up as a top level config entry. You can see how I implemented this for vizio here: https://github.com/home-assistant/core/blob/2e6edb0447f6e6c460eb5ab1a1d9c75602eebddd/homeassistant/components/vizio/__init__.py
https://github.com/home-assistant/core/blob/2e6edb0447f6e6c460eb5ab1a1d9c75602eebddd/homeassistant/components/vizio/media_player.py
There was a problem hiding this comment.
This function can be removed.
|
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 😄 |
This reverts commit 9be076a.
|
@shenxn please rebase on dev and force push to resolve the conflict |
|
@raman325 Done. Should be good to merge. |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Some comments for the future.
| endpoint = config_entry.data[CONF_ENDPOINT] | ||
|
|
||
| if endpoint in hass.data[PLATFORM]: | ||
| if endpoint in hass.data[DOMAIN]: |
There was a problem hiding this comment.
This is already checked in the config flow.
| """Test the songpal config flow.""" | ||
| import copy | ||
|
|
||
| from asynctest import MagicMock, patch |
There was a problem hiding this comment.
Please import all mocks and patch from tests.async_mock.
| } | ||
|
|
||
| for device in hass.data[PLATFORM].values(): | ||
| for device in hass.data[DOMAIN].values(): |
There was a problem hiding this comment.
We can use the platform service registration helper and avoid storing the entities.
https://developers.home-assistant.io/docs/dev_101_services#entity-services
Breaking change
Entries for
songpalinconfiguration.yamlhave to move out of a platform config to a top level config.Proposed change
Add config flow support to songpal integration
Type of change
Example entry for
configuration.yaml:# Example configuration.yamlAdditional 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: