Add enable_millisecond to duration selector (#122821)

* Add enable_milliseconds to duration selector.

* One more test
This commit is contained in:
karwosts 2024-07-31 07:13:05 -07:00 committed by GitHub
parent 97de1c2b66
commit 3df78043c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -725,6 +725,7 @@ class DurationSelectorConfig(TypedDict, total=False):
"""Class to represent a duration selector config."""
enable_day: bool
enable_millisecond: bool
allow_negative: bool
@ -739,6 +740,8 @@ class DurationSelector(Selector[DurationSelectorConfig]):
# Enable day field in frontend. A selection with `days` set is allowed
# even if `enable_day` is not set
vol.Optional("enable_day"): cv.boolean,
# Enable millisecond field in frontend.
vol.Optional("enable_millisecond"): cv.boolean,
# Allow negative durations. Will default to False in HA Core 2025.6.0.
vol.Optional("allow_negative"): cv.boolean,
}

View file

@ -739,12 +739,13 @@ def test_attribute_selector_schema(
(
{"seconds": 10},
{"days": 10}, # Days is allowed also if `enable_day` is not set
{"milliseconds": 500},
),
(None, {}),
),
(
{"enable_day": True},
({"seconds": 10}, {"days": 10}),
{"enable_day": True, "enable_millisecond": True},
({"seconds": 10}, {"days": 10}, {"milliseconds": 500}),
(None, {}),
),
(