home-assistant / architecture

Repo to discuss Home Assistant architecture
315 stars 99 forks source link

Support YAML as an input type for config flows #441

Closed raman325 closed 3 years ago

raman325 commented 3 years ago

Context

With the move to using config flows over YAML, there is a gap between what YAML can support and what config flows can support. It would be great to have a YAML input type which is converted to a dict/list as part of config validation.

Proposal

Add a new function to homeassistant.helpers.config_validation that validates a YAML input and converts it into a dict/list as part of the validation. Add frontend support so that the YAML code editor appears for fields that use this input type.

Consequences

It will make it easier for devs to move configuration options to config flows that currently can only be supported through configuration.yaml

raman325 commented 3 years ago

Assuming there is agreement, I am happy to do the backend work but would need some help implementing this in the frontend

frenck commented 3 years ago

I'm missing a concrete example of the issue you are trying to solve? Is it multi selects you are looking for?

raman325 commented 3 years ago

No, a concrete example would be one of the YAML config options for vizio (https://www.home-assistant.io/integrations/vizio/#apps). There is no way to accept a parameter like this through the UI as far as I can tell

Kane610 commented 3 years ago

Isn't it possible to just read the list of available apps?

Have a look at netatmo for a more complex config entry options flow

raman325 commented 3 years ago

I might be missing something, but the only complexity I see in netatmo is determining which coordinates are NE vs SW. The parameters are still well bounded, so it wouldn't fit this use case where the options are unbounded.

You are right about reading the list of available apps, that is already handled. Here's another example of an integration that would benefit from a UI option: https://www.home-assistant.io/integrations/androidtv/#apps

MartinHjelmare commented 3 years ago

This frontend PR to extend ha-form might be related: https://github.com/home-assistant/frontend/pull/7151

balloob commented 3 years ago

Can you describe what input you're missing from ha-form? Is it a way to enter Vizio apps? Can you explain how you would like it to work from a UI perspective?

raman325 commented 3 years ago

I was not aware of this frontend PR - that PR may have what I need. Let me review and I will close this if so

JeffLIrion commented 3 years ago

I saw this architecture issue and thought of the Android TV integration, which @raman325 has already mentioned. [Begin off-topic] It doesn't currently have a config flow, but if someone wants to add that it would be a welcome enhancement to the integration. I've never implemented a config flow and I simply don't have the time to do this myself. [End off-topic]

In the context of this issue, the Android TV state_detection_rules configuration parameter (see Full Configuration) is a dictionary/map with a sophisticated structure that extends well beyond simple key: value pairs. In terms of complexity, it looks comparable to the apps configuration for Vizio.

I don't think this type of configuration is currently supported by config flows. Furthermore, I think that @raman325's proposal of accepting YAML as input is a good way to support complicated configurations via the UI.

balloob commented 3 years ago

I am going to close this issue. The UI is an alternative to YAML. It should not become YAML again.

raman325 commented 3 years ago

We can keep this closed - there are probably better ways to represent and create maps/lists through a UI anyway. But I respectfully disagree that the UI is an alternative to YAML. That implies that you can choose to use one or the other but per https://github.com/home-assistant/architecture/blob/master/adr/0010-integration-configuration.md most integrations should favor UI configuration over YAML. I get that vizio, androidtv, and likely others would fall into the exception category, but this ADR points to having a way to configure any parameter type via the UI

balloob commented 3 years ago

Yes, we will be able to configure any paramter type via the UI, but we should build widgets that are intuitive ways to manipulate lists and dicts. It's easy to be more accessible than YAML.