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

Resetting time field in Config Flow has wrong behavior #24405

Open
4 tasks done
hcraveiro opened this issue Feb 26, 2025 · 5 comments
Open
4 tasks done

Resetting time field in Config Flow has wrong behavior #24405

hcraveiro opened this issue Feb 26, 2025 · 5 comments

Comments

@hcraveiro
Copy link

Checklist

  • I have updated to the latest available Home Assistant version.
  • I have cleared the cache of my browser.
  • I have tried a different browser to see if it is related to my browser.
  • I have tried reproducing the issue in safe mode to rule out problems with unsupported custom resources.

Describe the issue you are experiencing

When I'm filling the configuration of an integration in a Config Flow and it has time input fields, if I fill out a field and then click on 'X' to erase the data on the field, what is passed as payload is that every input that was not filled is null, the field that was erased disappears from the payload.

Describe the behavior you expected

I expected the field which data was erased should have been passed as null like the others

Steps to reproduce the issue

1.Add an Integration which has in it's configuration a time selector field
2.Fill in the field
3.Erase the data on the field by clicking on the -X-
4.Inspect the payload being submitted when you press Next
...

What version of Home Assistant Core has the issue?

core-2025.2.5

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue?

Google Chrome 133.0.6943.99 (Official Build) (64-bit)

Which operating system are you using to run this browser?

Windows 11 Enterprise 23H2

State of relevant entities

Problem-relevant frontend configuration

Javascript errors shown in your browser console/inspector

Additional information

No response

@karwosts
Copy link
Contributor

Could it be that some fields are required and some are optional, which could explain the difference?

Maybe you can attach the example config schema passed to frontend, and the response value as additional information.

@hcraveiro
Copy link
Author

Sure.

Example when the optional time fields are not filled:
{
"interval_days": 2,
"station_1_minutes": 5,
"hour_1": null,
"hour_2": null,
"hour_3": null,
"hour_4": null,
"hour_5": null
}

Example when one of the optional fields is filled:
{
"interval_days": 2,
"station_1_minutes": 5,
"hour_1": "07:00:00",
"hour_2": null,
"hour_3": null,
"hour_4": null,
"hour_5": null
}

Example when one of the fields is filled and then I click on the 'X' and it resets the field like it wasn't filled (in this case 'hour_2' is not passed on the payload):
{
"interval_days": 2,
"station_1_minutes": 5,
"hour_2": null,
"hour_3": null,
"hour_4": null,
"hour_5": null
}

@karwosts
Copy link
Contributor

karwosts commented Feb 27, 2025

I can't convince myself that this is actually the wrong behavior. I don't see any reason why it should be expected it to return null instead of undefined.

I see the same behavior for textfields as well. If you backspace the text in an optional textfield to empty, that key is also not returned in the config flow response.

Is there a particular reason you expected it to be the other way?

The only way I can even get a time field to be null is if I pass in default=None, (instead of just omitting the default) and that doesn't even seem to work when I try to submit it:

Image

Image

@hcraveiro
Copy link
Author

I can give 2 reasons:

  • first one is consistency. If I have 5 time fields and they are all empty, either because they were not filled or because they were filled and then erased, should have the same behavior
  • I'm building an Integration for irrigation controller that has a Config Flow where I want to configure the irrigation pattern for each month of the year (scheduled irrigation times, number of minutes watering, etc). When I transition from the config of one month to the other I copy the settings from the previous one since a lot of times it will be kept or just slightly changed. I use the same step for the month configuration, as it doesn't make sense to create 12 steps. When I erase the hour_2 field (2nd irrigation time of the day), when I click next, although the hour_2 field was removed from the payload the behavior is that when I get to the new month it has the previous value.
Image Image Image Image

@karwosts
Copy link
Contributor

Is your config flow code posted online anywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants