mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Tweak selectors (#68267)
* Optionally don't convert output of duration and time selectors * Allow number selector selection to be None * Never convert output of duration and time selectors * Revert "Allow number selector selection to be None" This reverts commit b6f52c1e83dc287a30c8ef4c2e417dc20b26a1d6.
This commit is contained in:
parent
2fcced333d
commit
d7145095ef
@ -2,7 +2,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import time as time_sys, timedelta
|
||||
from typing import Any, cast
|
||||
|
||||
import voluptuous as vol
|
||||
@ -261,9 +260,10 @@ class TimeSelector(Selector):
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({})
|
||||
|
||||
def __call__(self, data: Any) -> time_sys:
|
||||
def __call__(self, data: Any) -> str:
|
||||
"""Validate the passed selection."""
|
||||
return cv.time(data)
|
||||
cv.time(data)
|
||||
return cast(str, data)
|
||||
|
||||
|
||||
@SELECTORS.register("target")
|
||||
@ -409,10 +409,10 @@ class DurationSelector(Selector):
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({})
|
||||
|
||||
def __call__(self, data: Any) -> timedelta:
|
||||
def __call__(self, data: Any) -> dict[str, float]:
|
||||
"""Validate the passed selection."""
|
||||
duration: timedelta = cv.time_period_dict(data)
|
||||
return duration
|
||||
cv.time_period_dict(data)
|
||||
return cast(dict[str, float], data)
|
||||
|
||||
|
||||
@SELECTORS.register("icon")
|
||||
|
@ -1,11 +1,8 @@
|
||||
"""Test selectors."""
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers import config_validation as cv, selector
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
FAKE_UUID = "a266a680b608c32770e6c45bfe6b8411"
|
||||
|
||||
@ -253,9 +250,7 @@ def test_boolean_selector_schema(schema, valid_selections, invalid_selections):
|
||||
)
|
||||
def test_time_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test time selector."""
|
||||
_test_selector(
|
||||
"time", schema, valid_selections, invalid_selections, dt_util.parse_time
|
||||
)
|
||||
_test_selector("time", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@ -393,13 +388,7 @@ def test_attribute_selector_schema(schema, valid_selections, invalid_selections)
|
||||
)
|
||||
def test_duration_selector_schema(schema, valid_selections, invalid_selections):
|
||||
"""Test duration selector."""
|
||||
_test_selector(
|
||||
"duration",
|
||||
schema,
|
||||
valid_selections,
|
||||
invalid_selections,
|
||||
lambda x: timedelta(**x),
|
||||
)
|
||||
_test_selector("duration", schema, valid_selections, invalid_selections)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user