mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add entity ID to time trigger (#41933)
This commit is contained in:
parent
6f8e3d2544
commit
388a5d8c91
@ -37,11 +37,18 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
||||
job = HassJob(action)
|
||||
|
||||
@callback
|
||||
def time_automation_listener(description, now):
|
||||
def time_automation_listener(description, now, *, entity_id=None):
|
||||
"""Listen for time changes and calls action."""
|
||||
hass.async_run_hass_job(
|
||||
job,
|
||||
{"trigger": {"platform": "time", "now": now, "description": description}},
|
||||
{
|
||||
"trigger": {
|
||||
"platform": "time",
|
||||
"now": now,
|
||||
"description": description,
|
||||
"entity_id": entity_id,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
@callback
|
||||
@ -84,14 +91,22 @@ async def async_attach_trigger(hass, config, action, automation_info):
|
||||
if trigger_dt >= dt_util.now():
|
||||
remove = async_track_point_in_time(
|
||||
hass,
|
||||
partial(time_automation_listener, f"time set in {entity_id}"),
|
||||
partial(
|
||||
time_automation_listener,
|
||||
f"time set in {entity_id}",
|
||||
entity_id=entity_id,
|
||||
),
|
||||
trigger_dt,
|
||||
)
|
||||
elif has_time:
|
||||
# Else if it has time, then track time change.
|
||||
remove = async_track_time_change(
|
||||
hass,
|
||||
partial(time_automation_listener, f"time set in {entity_id}"),
|
||||
partial(
|
||||
time_automation_listener,
|
||||
f"time set in {entity_id}",
|
||||
entity_id=entity_id,
|
||||
),
|
||||
hour=hour,
|
||||
minute=minute,
|
||||
second=second,
|
||||
|
@ -93,7 +93,7 @@ async def test_if_fires_using_at_input_datetime(hass, calls, has_date, has_time)
|
||||
|
||||
time_that_will_not_match_right_away = trigger_dt - timedelta(minutes=1)
|
||||
|
||||
some_data = "{{ trigger.platform }}-{{ trigger.now.day }}-{{ trigger.now.hour }}"
|
||||
some_data = "{{ trigger.platform }}-{{ trigger.now.day }}-{{ trigger.now.hour }}-{{trigger.entity_id}}"
|
||||
with patch(
|
||||
"homeassistant.util.dt.utcnow",
|
||||
return_value=dt_util.as_utc(time_that_will_not_match_right_away),
|
||||
@ -117,7 +117,10 @@ async def test_if_fires_using_at_input_datetime(hass, calls, has_date, has_time)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == f"time-{trigger_dt.day}-{trigger_dt.hour}"
|
||||
assert (
|
||||
calls[0].data["some"]
|
||||
== f"time-{trigger_dt.day}-{trigger_dt.hour}-input_datetime.trigger"
|
||||
)
|
||||
|
||||
if has_date:
|
||||
trigger_dt += timedelta(days=1)
|
||||
@ -138,7 +141,10 @@ async def test_if_fires_using_at_input_datetime(hass, calls, has_date, has_time)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == f"time-{trigger_dt.day}-{trigger_dt.hour}"
|
||||
assert (
|
||||
calls[1].data["some"]
|
||||
== f"time-{trigger_dt.day}-{trigger_dt.hour}-input_datetime.trigger"
|
||||
)
|
||||
|
||||
|
||||
async def test_if_fires_using_multiple_at(hass, calls):
|
||||
|
Loading…
x
Reference in New Issue
Block a user