Prevent optional time fields in ha-service-control from auto-enabling #15124
+24
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed change
Services with an optional time parameter (using ha-selector-time) do not behave correctly, in that every time the service is loaded in the UI editor, the time parameter is always set to enabled. Other optional parameters are always disabled by default.
This means that every time an automation is loaded in the UI, a
time: "00:00:00"
will be added to a service that has an optional time parameter, even if user does not desire that parameter to be defined. Deleting it, and refreshing the page, will bring it right back again.This occurs because when time is initialized (undefined by default), if localization requires an am/pm selector, it will instance the selector, default to AM, and then fire a "valueChanged" event with the value:
When ha-time-input gets this event, it coerces it into a value of "00:00:00" and itself fires a value changed up to its parent selector and service control. This event tricks the service control into thinking the time parameter exists with a value of 12am, and sets that parameter to enabled.
Suggest fix this in ha-time-input by treating valueChanged events with hours, minutes, and seconds as NaN as an undefined value, instead of "00:00:00". Then the time key remains correctly undefined after initialization, if the value is not already present in the yaml.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: