Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions homeassistant/components/homeassistant/triggers/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def update_entity_trigger(
# entity
update_entity_trigger(at_time, new_state=hass.states.get(at_time))
to_track.append(TrackEntity(at_time, update_entity_trigger_event))
elif isinstance(at_time, dict) and CONF_OFFSET in at_time:
# entity with offset
entity_id: str = at_time.get(CONF_ENTITY_ID, "")
elif isinstance(at_time, dict):
# entity with optional offset
entity_id: str = at_time[CONF_ENTITY_ID]
offset: timedelta = at_time.get(CONF_OFFSET, timedelta(0))
update_entity_trigger(
entity_id, new_state=hass.states.get(entity_id), offset=offset
Expand Down
46 changes: 46 additions & 0 deletions tests/components/homeassistant/triggers/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,52 @@ async def test_if_fires_using_at_sensor_with_offset(
)


async def test_if_fires_using_at_sensor_dict_without_offset(
hass: HomeAssistant,
freezer: FrozenDateTimeFactory,
service_calls: list[ServiceCall],
) -> None:
"""Test for firing at sensor time using dict format without offset."""
now = dt_util.now()

trigger_dt = now.replace(hour=5, minute=0, second=0, microsecond=0) + timedelta(2)

hass.states.async_set(
"sensor.next_alarm",
trigger_dt.isoformat(),
{ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP},
)

time_that_will_not_match_right_away = trigger_dt - timedelta(minutes=1)

freezer.move_to(dt_util.as_utc(time_that_will_not_match_right_away))
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "time",
"at": {
"entity_id": "sensor.next_alarm",
},
},
"action": {
"service": "test.automation",
"data_template": {"some": "{{ trigger.entity_id }}"},
},
}
},
)
await hass.async_block_till_done()

async_fire_time_changed(hass, trigger_dt + timedelta(seconds=1))
await hass.async_block_till_done()

assert len(service_calls) == 1
assert service_calls[0].data["some"] == "sensor.next_alarm"


@pytest.mark.parametrize(
"conf",
[
Expand Down