mirror of
https://github.com/home-assistant/core.git
synced 2025-12-27 14:31:13 +00:00
Add datetime_today template method (#57435)
This commit is contained in:
@@ -1080,6 +1080,44 @@ def test_utcnow(mock_is_safe, hass):
|
||||
assert info.has_time is True
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.helpers.template.TemplateEnvironment.is_safe_callable",
|
||||
return_value=True,
|
||||
)
|
||||
def test_today_at(mock_is_safe, hass):
|
||||
"""Test today_at method."""
|
||||
now = dt_util.now()
|
||||
with patch("homeassistant.util.dt.now", return_value=now):
|
||||
now = now.replace(hour=10, minute=0, second=0, microsecond=0)
|
||||
result = template.Template(
|
||||
"{{ today_at('10:00').isoformat() }}",
|
||||
hass,
|
||||
).async_render()
|
||||
assert result == now.isoformat()
|
||||
|
||||
result = template.Template(
|
||||
"{{ today_at('10:00:00').isoformat() }}",
|
||||
hass,
|
||||
).async_render()
|
||||
assert result == now.isoformat()
|
||||
|
||||
result = template.Template(
|
||||
"{{ ('10:00:00' | today_at).isoformat() }}",
|
||||
hass,
|
||||
).async_render()
|
||||
assert result == now.isoformat()
|
||||
|
||||
now = now.replace(hour=0)
|
||||
result = template.Template(
|
||||
"{{ today_at().isoformat() }}",
|
||||
hass,
|
||||
).async_render()
|
||||
assert result == now.isoformat()
|
||||
|
||||
with pytest.raises(TemplateError):
|
||||
template.Template("{{ today_at('bad') }}", hass).async_render()
|
||||
|
||||
|
||||
@patch(
|
||||
"homeassistant.helpers.template.TemplateEnvironment.is_safe_callable",
|
||||
return_value=True,
|
||||
|
||||
Reference in New Issue
Block a user