mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix time condition microsecond offset when using input helpers (#51337)
This commit is contained in:
parent
63e16de6c0
commit
c5dc99c052
@ -752,7 +752,6 @@ def time(
|
||||
before_entity.attributes.get("hour", 23),
|
||||
before_entity.attributes.get("minute", 59),
|
||||
before_entity.attributes.get("second", 59),
|
||||
999999,
|
||||
)
|
||||
|
||||
if after < before:
|
||||
|
@ -791,6 +791,34 @@ async def test_time_using_input_datetime(hass):
|
||||
hass, after="input_datetime.pm", before="input_datetime.am"
|
||||
)
|
||||
|
||||
# Trigger on PM time
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.now",
|
||||
return_value=dt_util.now().replace(hour=18, minute=0, second=0),
|
||||
):
|
||||
assert condition.time(
|
||||
hass, after="input_datetime.pm", before="input_datetime.am"
|
||||
)
|
||||
assert not condition.time(
|
||||
hass, after="input_datetime.am", before="input_datetime.pm"
|
||||
)
|
||||
assert condition.time(hass, after="input_datetime.pm")
|
||||
assert not condition.time(hass, before="input_datetime.pm")
|
||||
|
||||
# Trigger on AM time
|
||||
with patch(
|
||||
"homeassistant.helpers.condition.dt_util.now",
|
||||
return_value=dt_util.now().replace(hour=6, minute=0, second=0),
|
||||
):
|
||||
assert not condition.time(
|
||||
hass, after="input_datetime.pm", before="input_datetime.am"
|
||||
)
|
||||
assert condition.time(
|
||||
hass, after="input_datetime.am", before="input_datetime.pm"
|
||||
)
|
||||
assert condition.time(hass, after="input_datetime.am")
|
||||
assert not condition.time(hass, before="input_datetime.am")
|
||||
|
||||
with pytest.raises(ConditionError):
|
||||
condition.time(hass, after="input_datetime.not_existing")
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user