diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index e7beddec0c7..e9da56bf3af 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -328,7 +328,7 @@ def _async_dispatch_entity_id_event( return for job in callbacks_list.copy(): try: - hass.async_run_hass_job(job, event) + hass.async_run_hass_job(job, event, eager_start=True) except Exception: # pylint: disable=broad-except _LOGGER.exception( "Error while dispatching event for %s to %s", diff --git a/tests/components/knx/test_expose.py b/tests/components/knx/test_expose.py index 0eea78d85b7..d2b7653cfe8 100644 --- a/tests/components/knx/test_expose.py +++ b/tests/components/knx/test_expose.py @@ -32,14 +32,17 @@ async def test_binary_expose(hass: HomeAssistant, knx: KNXTestKit) -> None: # Change state to on hass.states.async_set(entity_id, "on", {}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", True) # Change attribute; keep state hass.states.async_set(entity_id, "on", {"brightness": 180}) + await hass.async_block_till_done() await knx.assert_no_telegram() # Change attribute and state hass.states.async_set(entity_id, "off", {"brightness": 0}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", False) @@ -64,10 +67,12 @@ async def test_expose_attribute(hass: HomeAssistant, knx: KNXTestKit) -> None: # Change state to "on"; no attribute hass.states.async_set(entity_id, "on", {}) + await hass.async_block_till_done() await knx.assert_telegram_count(0) # Change attribute; keep state hass.states.async_set(entity_id, "on", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (1,)) # Read in between @@ -76,22 +81,27 @@ async def test_expose_attribute(hass: HomeAssistant, knx: KNXTestKit) -> None: # Change state keep attribute hass.states.async_set(entity_id, "off", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_telegram_count(0) # Change state and attribute hass.states.async_set(entity_id, "on", {attribute: 0}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (0,)) # Change state to "off"; no attribute hass.states.async_set(entity_id, "off", {}) + await hass.async_block_till_done() await knx.assert_telegram_count(0) # Change attribute; keep state hass.states.async_set(entity_id, "on", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (1,)) # Change state to "off"; null attribute hass.states.async_set(entity_id, "off", {attribute: None}) + await hass.async_block_till_done() await knx.assert_telegram_count(0) @@ -119,18 +129,22 @@ async def test_expose_attribute_with_default( # Change state to "on"; no attribute hass.states.async_set(entity_id, "on", {}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (0,)) # Change attribute; keep state hass.states.async_set(entity_id, "on", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (1,)) # Change state keep attribute hass.states.async_set(entity_id, "off", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_no_telegram() # Change state and attribute hass.states.async_set(entity_id, "on", {attribute: 3}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (3,)) # Read in between @@ -139,14 +153,17 @@ async def test_expose_attribute_with_default( # Change state to "off"; no attribute hass.states.async_set(entity_id, "off", {}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (0,)) # Change state and attribute hass.states.async_set(entity_id, "on", {attribute: 1}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (1,)) # Change state to "off"; null attribute hass.states.async_set(entity_id, "off", {attribute: None}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (0,)) @@ -179,6 +196,7 @@ async def test_expose_string(hass: HomeAssistant, knx: KNXTestKit) -> None: "on", {attribute: "This is a very long string that is larger than 14 bytes"}, ) + await hass.async_block_till_done() await knx.assert_write( "1/1/8", (84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 118, 101, 114, 121) ) @@ -200,13 +218,16 @@ async def test_expose_cooldown(hass: HomeAssistant, knx: KNXTestKit) -> None: ) # Change state to 1 hass.states.async_set(entity_id, "1", {}) + await hass.async_block_till_done() await knx.assert_write("1/1/8", (1,)) # Change state to 2 - skip because of cooldown hass.states.async_set(entity_id, "2", {}) + await hass.async_block_till_done() await knx.assert_no_telegram() # Change state to 3 hass.states.async_set(entity_id, "3", {}) + await hass.async_block_till_done() await knx.assert_no_telegram() # Wait for cooldown to pass async_fire_time_changed_exact( @@ -245,6 +266,7 @@ async def test_expose_conversion_exception( "on", {attribute: 101}, ) + await hass.async_block_till_done() await knx.assert_no_telegram() assert ( 'Could not expose fake.entity fake_attribute value "101.0" to KNX:' diff --git a/tests/components/knx/test_services.py b/tests/components/knx/test_services.py index 95cf60f1e68..a6688f7a14c 100644 --- a/tests/components/knx/test_services.py +++ b/tests/components/knx/test_services.py @@ -208,6 +208,7 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None: # no exposure registered hass.states.async_set(test_entity, STATE_ON, {}) + await hass.async_block_till_done() await knx.assert_no_telegram() # register exposure @@ -218,6 +219,7 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None: blocking=True, ) hass.states.async_set(test_entity, STATE_OFF, {}) + await hass.async_block_till_done() await knx.assert_write(test_address, False) # register exposure @@ -228,6 +230,7 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None: blocking=True, ) hass.states.async_set(test_entity, STATE_ON, {}) + await hass.async_block_till_done() await knx.assert_no_telegram() # register exposure for attribute with default @@ -245,8 +248,10 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None: ) # no attribute on first change wouldn't work because no attribute change since last test hass.states.async_set(test_entity, STATE_ON, {test_attribute: 30}) + await hass.async_block_till_done() await knx.assert_write(test_address, (30,)) hass.states.async_set(test_entity, STATE_OFF, {}) + await hass.async_block_till_done() await knx.assert_write(test_address, (0,)) # don't send same value sequentially hass.states.async_set(test_entity, STATE_ON, {test_attribute: 25}) @@ -254,6 +259,7 @@ async def test_exposure_register(hass: HomeAssistant, knx: KNXTestKit) -> None: hass.states.async_set(test_entity, STATE_ON, {test_attribute: 25, "unrelated": 2}) hass.states.async_set(test_entity, STATE_OFF, {test_attribute: 25}) await hass.async_block_till_done() + await hass.async_block_till_done() await knx.assert_telegram_count(1) await knx.assert_write(test_address, (25,))