-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Support readonly selectors in config_flows #129456
base: dev
Are you sure you want to change the base?
Support readonly selectors in config_flows #129456
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I didn't receive any response on my proposal for a read only selector (which is guess should close as this is likely a better suggestion anyhow), that and this proposal share the same issue eg. They should be only for display and not sent back to core (the helper should not need to consider fields which are there only for display purpose I think).
@@ -44,6 +44,9 @@ async def test_form( | |||
result = await hass.config_entries.flow.async_configure( | |||
result["flow_id"], | |||
{ | |||
CONF_ENTITY_ID: "binary_sensor.test_monitored", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read only fields should not be set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was kind of disappointed I had to do this to pass the testing, was initially hoping it would be less invasive.
If I mark the disabled fields as vol.Required, I have to pass them into this function.
If I mark the disabled fields as vol.Optional, (and don't pass them in here), they don't get passed through the config+options flow and the assert fails at the end.
Will have to think about this some more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok trying a bit different approach.
- Make readonly fields vol.Optional instead of vol.Required.
- Change frontend to delete the readonly fields before sending data back to backend.
- Change backend to not delete optional/readonly fields when they are not provided by the step flow (which they never will be provided).
With this can revert all the changes to the test.
Yeah, |
Small nit: I would rename |
I'll let a little more time to accumulate for further opinions, then I will change this if no other objections. |
I've never heard the term "display only", whereas I know exactly what "read only" means. That said, this option is only in the code so maybe from a core perspective it makes more sense. |
I don't agree as |
@@ -66,6 +66,17 @@ async def validate_options( | |||
) | |||
DATA_SCHEMA_OPTIONS = vol.Schema( | |||
{ | |||
vol.Optional(CONF_ENTITY_ID, description={"readonly": True}): EntitySelector(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to read_only
b501945
to
a1ce4a5
Compare
So we discussed this PR in the core team and we had the following remarks:
|
Frontend shouldn't be allowed to send read only or core can just discard it. Checking if it matches is not worth it. |
I've changed such that read_only is a flag to the selector config. Hope I have understood what you were asking for.
Current behavior of frontend is that it does not send data for read_only selector. |
Proposed change
A common complaint for a UI configured entity is that after the initial config flow, the inputs to that config flow are no longer visible, and you can't review how you configured it in the first place.
As a solution to this I propose supporting readonly/disabled selectors in options flows, which can show the values chosen during config flow, but freeze them so that they cannot be changed.
I've configured history_stats in this PR as a proof of concept of this flow.
A small frontend change is also required to support the way the disabled flag is passed to the form.
Type of change
Additional information
Checklist
ruff format 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
.To help with the load of incoming pull requests: