diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index cfbc40e7ed0..2529b49d263 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -107,7 +107,6 @@ class _KeyedEventTracker(Generic[_TypedDictT]): ], bool, ] - run_immediately: bool @dataclass(slots=True) @@ -339,7 +338,6 @@ _KEYED_TRACK_STATE_CHANGE = _KeyedEventTracker( event_type=EVENT_STATE_CHANGED, dispatcher_callable=_async_dispatch_entity_id_event, filter_callable=_async_state_change_filter, - run_immediately=False, ) @@ -417,7 +415,7 @@ def _async_track_event( tracker.event_type, ft.partial(tracker.dispatcher_callable, hass, callbacks), event_filter=ft.partial(tracker.filter_callable, hass, callbacks), - run_immediately=tracker.run_immediately, + run_immediately=True, ) job = HassJob(action, f"track {tracker.event_type} event {keys}", job_type=job_type) @@ -471,7 +469,6 @@ _KEYED_TRACK_ENTITY_REGISTRY_UPDATED = _KeyedEventTracker( event_type=EVENT_ENTITY_REGISTRY_UPDATED, dispatcher_callable=_async_dispatch_old_entity_id_or_entity_id_event, filter_callable=_async_entity_registry_updated_filter, - run_immediately=True, ) @@ -530,7 +527,6 @@ _KEYED_TRACK_DEVICE_REGISTRY_UPDATED = _KeyedEventTracker( event_type=EVENT_DEVICE_REGISTRY_UPDATED, dispatcher_callable=_async_dispatch_device_id_event, filter_callable=_async_device_registry_updated_filter, - run_immediately=True, ) @@ -599,7 +595,6 @@ _KEYED_TRACK_STATE_ADDED_DOMAIN = _KeyedEventTracker( event_type=EVENT_STATE_CHANGED, dispatcher_callable=_async_dispatch_domain_event, filter_callable=_async_domain_added_filter, - run_immediately=False, ) @@ -635,7 +630,6 @@ _KEYED_TRACK_STATE_REMOVED_DOMAIN = _KeyedEventTracker( event_type=EVENT_STATE_CHANGED, dispatcher_callable=_async_dispatch_domain_event, filter_callable=_async_domain_removed_filter, - run_immediately=False, ) diff --git a/tests/components/generic_thermostat/test_climate.py b/tests/components/generic_thermostat/test_climate.py index 8903f4b6606..ff409511221 100644 --- a/tests/components/generic_thermostat/test_climate.py +++ b/tests/components/generic_thermostat/test_climate.py @@ -808,10 +808,10 @@ async def test_heating_cooling_switch_does_not_toggle_when_within_min_cycle_dura # Given await _setup_thermostat_with_min_cycle_duration(hass, ac_mode, initial_hvac_mode) calls = _setup_switch(hass, initial_switch_state) - _setup_sensor(hass, sensor_temperature) # When await common.async_set_temperature(hass, target_temperature) + _setup_sensor(hass, sensor_temperature) await hass.async_block_till_done() # Then @@ -849,10 +849,10 @@ async def test_heating_cooling_switch_toggles_when_outside_min_cycle_duration( fake_changed = datetime.datetime(1970, 11, 11, 11, 11, 11, tzinfo=dt_util.UTC) with freeze_time(fake_changed): calls = _setup_switch(hass, initial_switch_state) - _setup_sensor(hass, sensor_temperature) # When await common.async_set_temperature(hass, target_temperature) + _setup_sensor(hass, sensor_temperature) await hass.async_block_till_done() # Then @@ -894,10 +894,10 @@ async def test_hvac_mode_change_toggles_heating_cooling_switch_even_when_within_ # Given await _setup_thermostat_with_min_cycle_duration(hass, ac_mode, initial_hvac_mode) calls = _setup_switch(hass, initial_switch_state) - _setup_sensor(hass, sensor_temperature) # When await common.async_set_temperature(hass, target_temperature) + _setup_sensor(hass, sensor_temperature) await hass.async_block_till_done() # Then diff --git a/tests/components/group/test_config_flow.py b/tests/components/group/test_config_flow.py index 3de6d9ac32d..3aea9d21f0c 100644 --- a/tests/components/group/test_config_flow.py +++ b/tests/components/group/test_config_flow.py @@ -540,6 +540,7 @@ async def test_config_flow_preview( } ) msg = await client.receive_json() + preview_subscribe_id = msg["id"] assert msg["success"] assert msg["result"] is None @@ -549,9 +550,32 @@ async def test_config_flow_preview( "state": "unavailable", } + await client.send_json_auto_id( + { + "type": "unsubscribe_events", + "subscription": preview_subscribe_id, + } + ) + msg = await client.receive_json() + assert msg["success"] + hass.states.async_set(input_entities[0], input_states[0]) hass.states.async_set(input_entities[1], input_states[1]) + await client.send_json_auto_id( + { + "type": "group/start_preview", + "flow_id": result["flow_id"], + "flow_type": "config_flow", + "user_input": {"name": "My group", "entities": input_entities} + | extra_user_input, + } + ) + msg = await client.receive_json() + preview_subscribe_id = msg["id"] + assert msg["success"] + assert msg["result"] is None + msg = await client.receive_json() assert msg["event"] == { "attributes": { diff --git a/tests/components/template/test_config_flow.py b/tests/components/template/test_config_flow.py index 59a2c4f38a3..8c5dda401dd 100644 --- a/tests/components/template/test_config_flow.py +++ b/tests/components/template/test_config_flow.py @@ -8,6 +8,7 @@ from pytest_unordered import unordered from homeassistant import config_entries from homeassistant.components.template import DOMAIN, async_setup_entry +from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResultType @@ -276,7 +277,7 @@ async def test_options( "{{ float(states('sensor.one'), default='') + float(states('sensor.two'), default='') }}", {}, {"one": "30.0", "two": "20.0"}, - ["", "50.0"], + ["", STATE_UNAVAILABLE, "50.0"], [{}, {}], [["one", "two"], ["one", "two"]], ), @@ -342,20 +343,24 @@ async def test_config_flow_preview( hass.states.async_set( f"{template_type}.{input_entity}", input_states[input_entity], {} ) + await hass.async_block_till_done() - msg = await client.receive_json() - assert msg["event"] == { - "attributes": {"friendly_name": "My template"} - | extra_attributes[0] - | extra_attributes[1], - "listeners": { - "all": False, - "domains": [], - "entities": unordered([f"{template_type}.{_id}" for _id in listeners[1]]), - "time": False, - }, - "state": template_states[1], - } + for template_state in template_states[1:]: + msg = await client.receive_json() + assert msg["event"] == { + "attributes": {"friendly_name": "My template"} + | extra_attributes[0] + | extra_attributes[1], + "listeners": { + "all": False, + "domains": [], + "entities": unordered( + [f"{template_type}.{_id}" for _id in listeners[1]] + ), + "time": False, + }, + "state": template_state, + } assert len(hass.states.async_all()) == 2