diff --git a/homeassistant/components/homematicip_cloud/alarm_control_panel.py b/homeassistant/components/homematicip_cloud/alarm_control_panel.py index c2f4d833a35..902755bfa07 100644 --- a/homeassistant/components/homematicip_cloud/alarm_control_panel.py +++ b/homeassistant/components/homematicip_cloud/alarm_control_panel.py @@ -98,7 +98,7 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): def _async_device_changed(self, *args, **kwargs) -> None: """Handle device state changes.""" _LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME) - self.async_schedule_update_ha_state() + self.async_schedule_update_ha_state(True) @property def name(self) -> str: diff --git a/homeassistant/components/ps4/media_player.py b/homeassistant/components/ps4/media_player.py index 33b5c556c7d..28d201d78cd 100644 --- a/homeassistant/components/ps4/media_player.py +++ b/homeassistant/components/ps4/media_player.py @@ -97,11 +97,7 @@ class PS4Device(MediaPlayerDevice): def status_callback(self): """Handle status callback. Parse status.""" self._parse_status() - - @callback - def schedule_update(self): - """Schedules update with HA.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def subscribe_to_protocol(self): @@ -184,7 +180,6 @@ class PS4Device(MediaPlayerDevice): self._media_content_id = title_id if self._use_saved(): _LOGGER.debug("Using saved data for media: %s", title_id) - self.schedule_update() return self._media_title = name @@ -223,13 +218,11 @@ class PS4Device(MediaPlayerDevice): """Set states for state idle.""" self.reset_title() self._state = STATE_IDLE - self.schedule_update() def state_standby(self): """Set states for state standby.""" self.reset_title() self._state = STATE_STANDBY - self.schedule_update() def state_unknown(self): """Set states for state unknown.""" @@ -286,8 +279,8 @@ class PS4Device(MediaPlayerDevice): self._media_image = art or None self._media_type = media_type - self.update_list() - self.schedule_update() + await self.hass.async_add_executor_job(self.update_list) + self.async_write_ha_state() def update_list(self): """Update Game List, Correct data if different.""" diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 4c3b9448f5a..49ed0f4a567 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -441,7 +441,10 @@ class Entity(ABC): If state is changed more than once before the ha state change task has been executed, the intermediate state transitions will be missed. """ - self.hass.async_create_task(self.async_update_ha_state(force_refresh)) + if force_refresh: + self.hass.async_create_task(self.async_update_ha_state(force_refresh)) + else: + self.async_write_ha_state() async def async_device_update(self, warning=True): """Process 'update' or 'async_update' from entity. diff --git a/tests/components/device_sun_light_trigger/test_init.py b/tests/components/device_sun_light_trigger/test_init.py index dda4a90f31b..c8d0e334412 100644 --- a/tests/components/device_sun_light_trigger/test_init.py +++ b/tests/components/device_sun_light_trigger/test_init.py @@ -187,6 +187,7 @@ async def test_lights_turn_on_when_coming_home_after_sun_set_person(hass, scanne # person home switches on hass.states.async_set(device_1, STATE_HOME) await hass.async_block_till_done() + await hass.async_block_till_done() assert all( light.is_on(hass, ent_id) diff --git a/tests/components/rflink/test_binary_sensor.py b/tests/components/rflink/test_binary_sensor.py index 18c4f946318..2a67cf5348d 100644 --- a/tests/components/rflink/test_binary_sensor.py +++ b/tests/components/rflink/test_binary_sensor.py @@ -130,6 +130,7 @@ async def test_off_delay(hass, monkeypatch): async_fire_time_changed(hass, future) event_callback(on_event) await hass.async_block_till_done() + await hass.async_block_till_done() state = hass.states.get("binary_sensor.test2") assert state.state == STATE_ON assert len(events) == 1 @@ -140,6 +141,7 @@ async def test_off_delay(hass, monkeypatch): async_fire_time_changed(hass, future) event_callback(on_event) await hass.async_block_till_done() + await hass.async_block_till_done() state = hass.states.get("binary_sensor.test2") assert state.state == STATE_ON assert len(events) == 2 @@ -149,6 +151,7 @@ async def test_off_delay(hass, monkeypatch): with patch(("homeassistant.helpers.event.dt_util.utcnow"), return_value=future): async_fire_time_changed(hass, future) await hass.async_block_till_done() + await hass.async_block_till_done() state = hass.states.get("binary_sensor.test2") assert state.state == STATE_ON assert len(events) == 2 @@ -158,6 +161,7 @@ async def test_off_delay(hass, monkeypatch): with patch(("homeassistant.helpers.event.dt_util.utcnow"), return_value=future): async_fire_time_changed(hass, future) await hass.async_block_till_done() + await hass.async_block_till_done() state = hass.states.get("binary_sensor.test2") assert state.state == STATE_OFF assert len(events) == 3 diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index dc286502068..e10cdc20143 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -144,6 +144,7 @@ async def test_firing_bus_event(hass, monkeypatch): # test event for new unconfigured sensor event_callback({"id": "protocol_0_0", "command": "down"}) await hass.async_block_till_done() + await hass.async_block_till_done() assert calls[0].data == {"state": "down", "entity_id": DOMAIN + ".test"} diff --git a/tests/components/rflink/test_light.py b/tests/components/rflink/test_light.py index 5dc06b5b2ff..87696191ac8 100644 --- a/tests/components/rflink/test_light.py +++ b/tests/components/rflink/test_light.py @@ -184,6 +184,7 @@ async def test_firing_bus_event(hass, monkeypatch): # test event for new unconfigured sensor event_callback({"id": "protocol_0_0", "command": "off"}) await hass.async_block_till_done() + await hass.async_block_till_done() assert calls[0].data == {"state": "off", "entity_id": DOMAIN + ".test"} diff --git a/tests/components/rflink/test_switch.py b/tests/components/rflink/test_switch.py index d1fced33208..bcade409d3e 100644 --- a/tests/components/rflink/test_switch.py +++ b/tests/components/rflink/test_switch.py @@ -214,6 +214,7 @@ async def test_device_defaults(hass, monkeypatch): # test event for new unconfigured sensor event_callback({"id": "protocol_0_0", "command": "off"}) await hass.async_block_till_done() + await hass.async_block_till_done() assert calls[0].data == {"state": "off", "entity_id": DOMAIN + ".test"}