From d645e80ccd5acb92c5ee6bce30c20bc634fc3e77 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 25 Mar 2022 23:22:58 +0100 Subject: [PATCH] Clean up async_update_entity helper usage (#68641) --- .../components/homeassistant/__init__.py | 4 +- .../components/androidtv/test_media_player.py | 41 ++++++++++--------- tests/components/awair/test_sensor.py | 5 +-- tests/components/broadlink/test_sensors.py | 17 +++----- .../canary/test_alarm_control_panel.py | 9 ++-- tests/components/canary/test_sensor.py | 5 ++- tests/components/dexcom/test_sensor.py | 17 +++----- tests/components/freedompro/test_cover.py | 3 +- tests/components/freedompro/test_fan.py | 5 ++- tests/components/freedompro/test_lock.py | 3 +- tests/components/freedompro/test_switch.py | 3 +- tests/components/history_stats/test_sensor.py | 5 ++- tests/components/homeassistant/test_init.py | 2 +- tests/components/konnected/test_panel.py | 9 ++-- tests/components/kulersky/test_light.py | 3 +- tests/components/nzbget/test_switch.py | 3 +- .../components/plugwise/test_binary_sensor.py | 5 +-- tests/components/plugwise/test_sensor.py | 5 +-- .../ruckus_unleashed/test_device_tracker.py | 7 ++-- .../components/template/test_binary_sensor.py | 13 +++--- tests/components/template/test_sensor.py | 17 ++++---- tests/components/template/test_vacuum.py | 5 +-- tests/helpers/test_entity_component.py | 4 +- 23 files changed, 87 insertions(+), 103 deletions(-) diff --git a/homeassistant/components/homeassistant/__init__.py b/homeassistant/components/homeassistant/__init__.py index c2d855d3135..f79213e2484 100644 --- a/homeassistant/components/homeassistant/__init__.py +++ b/homeassistant/components/homeassistant/__init__.py @@ -23,6 +23,7 @@ from homeassistant.const import ( import homeassistant.core as ha from homeassistant.exceptions import HomeAssistantError, Unauthorized, UnknownUser from homeassistant.helpers import config_validation as cv, recorder, restore_state +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.service import ( async_extract_config_entry_ids, async_extract_referenced_entity_ids, @@ -199,8 +200,7 @@ async def async_setup(hass: ha.HomeAssistant, config: ConfigType) -> bool: # no ) tasks = [ - hass.helpers.entity_component.async_update_entity(entity) - for entity in call.data[ATTR_ENTITY_ID] + async_update_entity(hass, entity) for entity in call.data[ATTR_ENTITY_ID] ] if tasks: diff --git a/tests/components/androidtv/test_media_player.py b/tests/components/androidtv/test_media_player.py index a0bab1736ff..59f31085ad2 100644 --- a/tests/components/androidtv/test_media_player.py +++ b/tests/components/androidtv/test_media_player.py @@ -60,6 +60,7 @@ from homeassistant.const import ( STATE_STANDBY, STATE_UNAVAILABLE, ) +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util import slugify from tests.common import MockConfigEntry @@ -170,7 +171,7 @@ async def test_reconnect(hass, caplog, config): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -182,7 +183,7 @@ async def test_reconnect(hass, caplog, config): patch_key ], patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER: for _ in range(5): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_UNAVAILABLE @@ -195,7 +196,7 @@ async def test_reconnect(hass, caplog, config): with patchers.patch_connect(True)[patch_key], patchers.patch_shell( SHELL_RESPONSE_STANDBY )[patch_key], patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None @@ -238,7 +239,7 @@ async def test_adb_shell_returns_none(hass, config): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state != STATE_UNAVAILABLE @@ -246,7 +247,7 @@ async def test_adb_shell_returns_none(hass, config): with patchers.patch_shell(None)[patch_key], patchers.patch_shell(error=True)[ patch_key ], patchers.PATCH_ANDROIDTV_OPEN, patchers.PATCH_SIGNER: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_UNAVAILABLE @@ -267,7 +268,7 @@ async def test_setup_with_adbkey(hass): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -301,7 +302,7 @@ async def test_sources(hass, config0): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -325,7 +326,7 @@ async def test_sources(hass, config0): ) with patch_update: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_PLAYING @@ -351,7 +352,7 @@ async def test_sources(hass, config0): ) with patch_update: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_PLAYING @@ -380,7 +381,7 @@ async def _test_exclude_sources(hass, config0, expected_sources): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -416,7 +417,7 @@ async def _test_exclude_sources(hass, config0, expected_sources): ) with patch_update: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_PLAYING @@ -461,7 +462,7 @@ async def _test_select_source(hass, config0, source, expected_arg, method_patch) assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -688,7 +689,7 @@ async def test_setup_fail(hass, config): assert await hass.config_entries.async_setup(config_entry.entry_id) is False await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is None @@ -851,7 +852,7 @@ async def test_update_lock_not_acquired(hass): await hass.async_block_till_done() with patchers.patch_shell(SHELL_RESPONSE_OFF)[patch_key]: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF @@ -860,13 +861,13 @@ async def test_update_lock_not_acquired(hass): "androidtv.androidtv.androidtv_async.AndroidTVAsync.update", side_effect=LockNotAcquiredException, ), patchers.patch_shell(SHELL_RESPONSE_STANDBY)[patch_key]: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF with patchers.patch_shell(SHELL_RESPONSE_STANDBY)[patch_key]: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_STANDBY @@ -1003,7 +1004,7 @@ async def test_get_image(hass, hass_ws_client): await hass.async_block_till_done() with patchers.patch_shell("11")[patch_key]: - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) client = await hass_ws_client(hass) @@ -1208,20 +1209,20 @@ async def test_exception(hass): assert await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF # When an unforeseen exception occurs, we close the ADB connection and raise the exception with patchers.PATCH_ANDROIDTV_UPDATE_EXCEPTION, pytest.raises(Exception): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_UNAVAILABLE # On the next update, HA will reconnect to the device - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) state = hass.states.get(entity_id) assert state is not None assert state.state == STATE_OFF diff --git a/tests/components/awair/test_sensor.py b/tests/components/awair/test_sensor.py index 658ba802e8e..5f30be81d6f 100644 --- a/tests/components/awair/test_sensor.py +++ b/tests/components/awair/test_sensor.py @@ -28,6 +28,7 @@ from homeassistant.const import ( TEMP_CELSIUS, ) from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from .const import ( AWAIR_UUID, @@ -336,9 +337,7 @@ async def test_awair_unavailable(hass): ) with patch("python_awair.AwairClient.query", side_effect=OFFLINE_FIXTURE): - await hass.helpers.entity_component.async_update_entity( - "sensor.living_room_awair_score" - ) + await async_update_entity(hass, "sensor.living_room_awair_score") assert_expected_properties( hass, registry, diff --git a/tests/components/broadlink/test_sensors.py b/tests/components/broadlink/test_sensors.py index 28caa212278..b5a49fdae15 100644 --- a/tests/components/broadlink/test_sensors.py +++ b/tests/components/broadlink/test_sensors.py @@ -4,6 +4,7 @@ from datetime import timedelta from homeassistant.components.broadlink.const import DOMAIN from homeassistant.components.broadlink.updater import BroadlinkSP4UpdateManager from homeassistant.const import Platform +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.entity_registry import async_entries_for_device from homeassistant.util import dt @@ -81,9 +82,7 @@ async def test_a1_sensor_update(hass): "light": 3, "noise": 2, } - await hass.helpers.entity_component.async_update_entity( - next(iter(sensors)).entity_id - ) + await async_update_entity(hass, next(iter(sensors)).entity_id) assert mock_setup.api.check_sensors_raw.call_count == 2 sensors_and_states = { @@ -144,9 +143,7 @@ async def test_rm_pro_sensor_update(hass): assert len(sensors) == 1 mock_setup.api.check_sensors.return_value = {"temperature": 25.8} - await hass.helpers.entity_component.async_update_entity( - next(iter(sensors)).entity_id - ) + await async_update_entity(hass, next(iter(sensors)).entity_id) assert mock_setup.api.check_sensors.call_count == 2 sensors_and_states = { @@ -178,9 +175,7 @@ async def test_rm_pro_filter_crazy_temperature(hass): assert len(sensors) == 1 mock_setup.api.check_sensors.return_value = {"temperature": -7} - await hass.helpers.entity_component.async_update_entity( - next(iter(sensors)).entity_id - ) + await async_update_entity(hass, next(iter(sensors)).entity_id) assert mock_setup.api.check_sensors.call_count == 2 sensors_and_states = { @@ -258,9 +253,7 @@ async def test_rm4_pro_hts2_sensor_update(hass): assert len(sensors) == 2 mock_setup.api.check_sensors.return_value = {"temperature": 16.8, "humidity": 34.0} - await hass.helpers.entity_component.async_update_entity( - next(iter(sensors)).entity_id - ) + await async_update_entity(hass, next(iter(sensors)).entity_id) assert mock_setup.api.check_sensors.call_count == 2 sensors_and_states = { diff --git a/tests/components/canary/test_alarm_control_panel.py b/tests/components/canary/test_alarm_control_panel.py index 84cef7e81ff..5034792d389 100644 --- a/tests/components/canary/test_alarm_control_panel.py +++ b/tests/components/canary/test_alarm_control_panel.py @@ -16,6 +16,7 @@ from homeassistant.const import ( STATE_ALARM_DISARMED, STATE_UNKNOWN, ) +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.setup import async_setup_component from . import mock_device, mock_location, mock_mode @@ -59,7 +60,7 @@ async def test_alarm_control_panel(hass, canary) -> None: # test private system type(mocked_location).is_private = PropertyMock(return_value=True) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) @@ -74,7 +75,7 @@ async def test_alarm_control_panel(hass, canary) -> None: return_value=mock_mode(4, LOCATION_MODE_HOME) ) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) @@ -86,7 +87,7 @@ async def test_alarm_control_panel(hass, canary) -> None: return_value=mock_mode(5, LOCATION_MODE_AWAY) ) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) @@ -98,7 +99,7 @@ async def test_alarm_control_panel(hass, canary) -> None: return_value=mock_mode(6, LOCATION_MODE_NIGHT) ) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) diff --git a/tests/components/canary/test_sensor.py b/tests/components/canary/test_sensor.py index 0c95152338c..d9946cab6a0 100644 --- a/tests/components/canary/test_sensor.py +++ b/tests/components/canary/test_sensor.py @@ -16,6 +16,7 @@ from homeassistant.const import ( SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_CELSIUS, ) +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.setup import async_setup_component from homeassistant.util.dt import utcnow @@ -126,7 +127,7 @@ async def test_sensors_attributes_pro(hass, canary) -> None: future = utcnow() + timedelta(seconds=30) async_fire_time_changed(hass, future) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state2 = hass.states.get(entity_id) @@ -142,7 +143,7 @@ async def test_sensors_attributes_pro(hass, canary) -> None: future += timedelta(seconds=30) async_fire_time_changed(hass, future) - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state3 = hass.states.get(entity_id) diff --git a/tests/components/dexcom/test_sensor.py b/tests/components/dexcom/test_sensor.py index 15de72e9c95..ff1256a9bc0 100644 --- a/tests/components/dexcom/test_sensor.py +++ b/tests/components/dexcom/test_sensor.py @@ -10,6 +10,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, STATE_UNKNOWN, ) +from homeassistant.helpers.entity_component import async_update_entity from tests.components.dexcom import GLUCOSE_READING, init_integration @@ -36,12 +37,8 @@ async def test_sensors_unknown(hass): "homeassistant.components.dexcom.Dexcom.get_current_glucose_reading", return_value=None, ): - await hass.helpers.entity_component.async_update_entity( - "sensor.dexcom_test_username_glucose_value" - ) - await hass.helpers.entity_component.async_update_entity( - "sensor.dexcom_test_username_glucose_trend" - ) + await async_update_entity(hass, "sensor.dexcom_test_username_glucose_value") + await async_update_entity(hass, "sensor.dexcom_test_username_glucose_trend") test_username_glucose_value = hass.states.get( "sensor.dexcom_test_username_glucose_value" @@ -61,12 +58,8 @@ async def test_sensors_update_failed(hass): "homeassistant.components.dexcom.Dexcom.get_current_glucose_reading", side_effect=SessionError, ): - await hass.helpers.entity_component.async_update_entity( - "sensor.dexcom_test_username_glucose_value" - ) - await hass.helpers.entity_component.async_update_entity( - "sensor.dexcom_test_username_glucose_trend" - ) + await async_update_entity(hass, "sensor.dexcom_test_username_glucose_value") + await async_update_entity(hass, "sensor.dexcom_test_username_glucose_trend") test_username_glucose_value = hass.states.get( "sensor.dexcom_test_username_glucose_value" diff --git a/tests/components/freedompro/test_cover.py b/tests/components/freedompro/test_cover.py index 11dc35b374c..ed14da90789 100644 --- a/tests/components/freedompro/test_cover.py +++ b/tests/components/freedompro/test_cover.py @@ -14,6 +14,7 @@ from homeassistant.const import ( STATE_OPEN, ) from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed @@ -149,7 +150,7 @@ async def test_cover_close( "homeassistant.components.freedompro.get_states", return_value=states_response, ): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() diff --git a/tests/components/freedompro/test_fan.py b/tests/components/freedompro/test_fan.py index 3404c5d17e4..3192398a323 100644 --- a/tests/components/freedompro/test_fan.py +++ b/tests/components/freedompro/test_fan.py @@ -10,6 +10,7 @@ from homeassistant.components.fan import ( ) from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, STATE_OFF, STATE_ON from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed @@ -78,7 +79,7 @@ async def test_fan_set_off(hass, init_integration): "homeassistant.components.freedompro.get_states", return_value=states_response, ): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() @@ -107,7 +108,7 @@ async def test_fan_set_off(hass, init_integration): "homeassistant.components.freedompro.get_states", return_value=states_response, ): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() diff --git a/tests/components/freedompro/test_lock.py b/tests/components/freedompro/test_lock.py index e0d25ce91d9..44811faffe8 100644 --- a/tests/components/freedompro/test_lock.py +++ b/tests/components/freedompro/test_lock.py @@ -9,6 +9,7 @@ from homeassistant.components.lock import ( ) from homeassistant.const import ATTR_ENTITY_ID, STATE_LOCKED, STATE_UNLOCKED from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed @@ -73,7 +74,7 @@ async def test_lock_set_unlock(hass, init_integration): "homeassistant.components.freedompro.get_states", return_value=states_response, ): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() diff --git a/tests/components/freedompro/test_switch.py b/tests/components/freedompro/test_switch.py index 6b62e028d72..f71ec4b896f 100644 --- a/tests/components/freedompro/test_switch.py +++ b/tests/components/freedompro/test_switch.py @@ -5,6 +5,7 @@ from unittest.mock import ANY, patch from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN, SERVICE_TURN_ON from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, STATE_OFF, STATE_ON from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util.dt import utcnow from tests.common import async_fire_time_changed @@ -61,7 +62,7 @@ async def test_switch_set_off(hass, init_integration): "homeassistant.components.freedompro.get_states", return_value=states_response, ): - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) async_fire_time_changed(hass, utcnow() + timedelta(hours=2)) await hass.async_block_till_done() diff --git a/tests/components/history_stats/test_sensor.py b/tests/components/history_stats/test_sensor.py index 105943d4444..c018553efc6 100644 --- a/tests/components/history_stats/test_sensor.py +++ b/tests/components/history_stats/test_sensor.py @@ -11,6 +11,7 @@ from homeassistant.components.history_stats import DOMAIN from homeassistant.components.history_stats.sensor import HistoryStatsSensor from homeassistant.const import SERVICE_RELOAD, STATE_UNKNOWN import homeassistant.core as ha +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.template import Template from homeassistant.setup import async_setup_component, setup_component import homeassistant.util.dt as dt_util @@ -339,7 +340,7 @@ async def test_measure_multiple(hass): return_value=fake_states, ), patch("homeassistant.components.recorder.history.get_state", return_value=None): for i in range(1, 5): - await hass.helpers.entity_component.async_update_entity(f"sensor.sensor{i}") + await async_update_entity(hass, f"sensor.sensor{i}") await hass.async_block_till_done() assert hass.states.get("sensor.sensor1").state == "0.5" @@ -416,7 +417,7 @@ async def async_test_measure(hass): return_value=fake_states, ), patch("homeassistant.components.recorder.history.get_state", return_value=None): for i in range(1, 5): - await hass.helpers.entity_component.async_update_entity(f"sensor.sensor{i}") + await async_update_entity(hass, f"sensor.sensor{i}") await hass.async_block_till_done() assert hass.states.get("sensor.sensor1").state == "0.5" diff --git a/tests/components/homeassistant/test_init.py b/tests/components/homeassistant/test_init.py index fb4a0f4c1da..8e89be00433 100644 --- a/tests/components/homeassistant/test_init.py +++ b/tests/components/homeassistant/test_init.py @@ -280,7 +280,7 @@ async def test_entity_update(hass): await async_setup_component(hass, "homeassistant", {}) with patch( - "homeassistant.helpers.entity_component.async_update_entity", + "homeassistant.components.homeassistant.async_update_entity", return_value=None, ) as mock_update: await hass.services.async_call( diff --git a/tests/components/konnected/test_panel.py b/tests/components/konnected/test_panel.py index bf2da15b7a4..e7e5784ba71 100644 --- a/tests/components/konnected/test_panel.py +++ b/tests/components/konnected/test_panel.py @@ -5,6 +5,7 @@ from unittest.mock import patch import pytest from homeassistant.components.konnected import config_flow, panel +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.setup import async_setup_component from homeassistant.util import utcnow @@ -654,15 +655,11 @@ async def test_connect_retry(hass, mock_panel): # confirm switch is unavailable after second attempt async_fire_time_changed(hass, utcnow() + timedelta(seconds=11)) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity( - "switch.konnected_445566_actuator_6" - ) + await async_update_entity(hass, "switch.konnected_445566_actuator_6") assert hass.states.get("switch.konnected_445566_actuator_6").state == "unavailable" # confirm switch is available after third attempt async_fire_time_changed(hass, utcnow() + timedelta(seconds=21)) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity( - "switch.konnected_445566_actuator_6" - ) + await async_update_entity(hass, "switch.konnected_445566_actuator_6") assert hass.states.get("switch.konnected_445566_actuator_6").state == "off" diff --git a/tests/components/kulersky/test_light.py b/tests/components/kulersky/test_light.py index 3315286967d..fabd263771f 100644 --- a/tests/components/kulersky/test_light.py +++ b/tests/components/kulersky/test_light.py @@ -29,6 +29,7 @@ from homeassistant.const import ( STATE_ON, STATE_UNAVAILABLE, ) +from homeassistant.helpers.entity_component import async_update_entity import homeassistant.util.dt as dt_util from tests.common import MockConfigEntry, async_fire_time_changed @@ -102,7 +103,7 @@ async def test_update_exception(hass, mock_light): """Test platform setup.""" mock_light.get_color.side_effect = pykulersky.PykulerskyException - await hass.helpers.entity_component.async_update_entity("light.bedroom") + await async_update_entity(hass, "light.bedroom") state = hass.states.get("light.bedroom") assert state is not None assert state.state == STATE_UNAVAILABLE diff --git a/tests/components/nzbget/test_switch.py b/tests/components/nzbget/test_switch.py index debfd9a1be8..d2bad2a46e1 100644 --- a/tests/components/nzbget/test_switch.py +++ b/tests/components/nzbget/test_switch.py @@ -8,6 +8,7 @@ from homeassistant.const import ( STATE_ON, ) from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from . import init_integration @@ -32,7 +33,7 @@ async def test_download_switch(hass, nzbget_api) -> None: # test download paused instance.status.return_value["DownloadPaused"] = True - await hass.helpers.entity_component.async_update_entity(entity_id) + await async_update_entity(hass, entity_id) await hass.async_block_till_done() state = hass.states.get(entity_id) diff --git a/tests/components/plugwise/test_binary_sensor.py b/tests/components/plugwise/test_binary_sensor.py index aacb9e469bb..1e4df8fb673 100644 --- a/tests/components/plugwise/test_binary_sensor.py +++ b/tests/components/plugwise/test_binary_sensor.py @@ -4,6 +4,7 @@ from unittest.mock import MagicMock from homeassistant.const import STATE_OFF, STATE_ON from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_component import async_update_entity from tests.common import MockConfigEntry @@ -41,9 +42,7 @@ async def test_anna_climate_binary_sensor_change( assert state assert state.state == STATE_ON - await hass.helpers.entity_component.async_update_entity( - "binary_sensor.opentherm_dhw_state" - ) + await async_update_entity(hass, "binary_sensor.opentherm_dhw_state") state = hass.states.get("binary_sensor.opentherm_dhw_state") assert state diff --git a/tests/components/plugwise/test_sensor.py b/tests/components/plugwise/test_sensor.py index edb479354bb..d5edeae3508 100644 --- a/tests/components/plugwise/test_sensor.py +++ b/tests/components/plugwise/test_sensor.py @@ -3,6 +3,7 @@ from unittest.mock import MagicMock from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_component import async_update_entity from tests.common import MockConfigEntry @@ -27,9 +28,7 @@ async def test_adam_climate_sensor_entities( assert state assert float(state.state) == 7.37 - await hass.helpers.entity_component.async_update_entity( - "sensor.zone_lisa_wk_battery" - ) + await async_update_entity(hass, "sensor.zone_lisa_wk_battery") state = hass.states.get("sensor.zone_lisa_wk_battery") assert state diff --git a/tests/components/ruckus_unleashed/test_device_tracker.py b/tests/components/ruckus_unleashed/test_device_tracker.py index 2c64bd3d0a8..b6a991f4c75 100644 --- a/tests/components/ruckus_unleashed/test_device_tracker.py +++ b/tests/components/ruckus_unleashed/test_device_tracker.py @@ -5,6 +5,7 @@ from unittest.mock import patch from homeassistant.components.ruckus_unleashed import API_MAC, DOMAIN from homeassistant.const import STATE_HOME, STATE_NOT_HOME, STATE_UNAVAILABLE from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.util import utcnow from tests.common import async_fire_time_changed @@ -33,7 +34,7 @@ async def test_client_connected(hass): ): async_fire_time_changed(hass, future) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(TEST_CLIENT_ENTITY_ID) + await async_update_entity(hass, TEST_CLIENT_ENTITY_ID) test_client = hass.states.get(TEST_CLIENT_ENTITY_ID) assert test_client.state == STATE_HOME @@ -51,7 +52,7 @@ async def test_client_disconnected(hass): async_fire_time_changed(hass, future) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(TEST_CLIENT_ENTITY_ID) + await async_update_entity(hass, TEST_CLIENT_ENTITY_ID) test_client = hass.states.get(TEST_CLIENT_ENTITY_ID) assert test_client.state == STATE_NOT_HOME @@ -68,7 +69,7 @@ async def test_clients_update_failed(hass): async_fire_time_changed(hass, future) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity(TEST_CLIENT_ENTITY_ID) + await async_update_entity(hass, TEST_CLIENT_ENTITY_ID) test_client = hass.states.get(TEST_CLIENT_ENTITY_ID) assert test_client.state == STATE_UNAVAILABLE diff --git a/tests/components/template/test_binary_sensor.py b/tests/components/template/test_binary_sensor.py index 1d8d9473f3c..4bd6c9ce305 100644 --- a/tests/components/template/test_binary_sensor.py +++ b/tests/components/template/test_binary_sensor.py @@ -17,6 +17,7 @@ from homeassistant.const import ( ) from homeassistant.core import Context, CoreState, State from homeassistant.helpers import entity_registry +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -753,14 +754,10 @@ async def test_no_update_template_match_all(hass, caplog): assert hass.states.get("binary_sensor.all_entity_picture").state == OFF assert hass.states.get("binary_sensor.all_attribute").state == OFF - await hass.helpers.entity_component.async_update_entity("binary_sensor.all_state") - await hass.helpers.entity_component.async_update_entity("binary_sensor.all_icon") - await hass.helpers.entity_component.async_update_entity( - "binary_sensor.all_entity_picture" - ) - await hass.helpers.entity_component.async_update_entity( - "binary_sensor.all_attribute" - ) + await async_update_entity(hass, "binary_sensor.all_state") + await async_update_entity(hass, "binary_sensor.all_icon") + await async_update_entity(hass, "binary_sensor.all_entity_picture") + await async_update_entity(hass, "binary_sensor.all_attribute") assert hass.states.get("binary_sensor.all_state").state == ON assert hass.states.get("binary_sensor.all_icon").state == OFF diff --git a/tests/components/template/test_sensor.py b/tests/components/template/test_sensor.py index b9b1a0cd93b..cffb714da9a 100644 --- a/tests/components/template/test_sensor.py +++ b/tests/components/template/test_sensor.py @@ -19,6 +19,7 @@ from homeassistant.const import ( ) from homeassistant.core import Context, CoreState, callback from homeassistant.helpers import entity_registry +from homeassistant.helpers.entity_component import async_update_entity from homeassistant.helpers.template import Template from homeassistant.setup import ATTR_COMPONENT, async_setup_component import homeassistant.util.dt as dt_util @@ -407,7 +408,7 @@ async def test_invalid_attribute_template(hass, caplog, start_ha, caplog_setup_t hass.bus.async_fire(EVENT_HOMEASSISTANT_START) await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity("sensor.invalid_template") + await async_update_entity(hass, "sensor.invalid_template") assert "TemplateError" in caplog_setup_text assert "test_attribute" in caplog.text @@ -506,15 +507,11 @@ async def test_no_template_match_all(hass, caplog): assert hass.states.get("sensor.invalid_friendly_name").state == "hello" assert hass.states.get("sensor.invalid_attribute").state == "hello" - await hass.helpers.entity_component.async_update_entity("sensor.invalid_state") - await hass.helpers.entity_component.async_update_entity("sensor.invalid_icon") - await hass.helpers.entity_component.async_update_entity( - "sensor.invalid_entity_picture" - ) - await hass.helpers.entity_component.async_update_entity( - "sensor.invalid_friendly_name" - ) - await hass.helpers.entity_component.async_update_entity("sensor.invalid_attribute") + await async_update_entity(hass, "sensor.invalid_state") + await async_update_entity(hass, "sensor.invalid_icon") + await async_update_entity(hass, "sensor.invalid_entity_picture") + await async_update_entity(hass, "sensor.invalid_friendly_name") + await async_update_entity(hass, "sensor.invalid_attribute") assert hass.states.get("sensor.invalid_state").state == "2" assert hass.states.get("sensor.invalid_icon").state == "hello" diff --git a/tests/components/template/test_vacuum.py b/tests/components/template/test_vacuum.py index 8b283f247e5..1fd875f2df8 100644 --- a/tests/components/template/test_vacuum.py +++ b/tests/components/template/test_vacuum.py @@ -11,6 +11,7 @@ from homeassistant.components.vacuum import ( STATE_RETURNING, ) from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN +from homeassistant.helpers.entity_component import async_update_entity from tests.common import assert_setup_component from tests.components.vacuum import common @@ -244,9 +245,7 @@ async def test_attribute_templates(hass, start_ha): hass.states.async_set("sensor.test_state", "Works") await hass.async_block_till_done() - await hass.helpers.entity_component.async_update_entity( - "vacuum.test_template_vacuum" - ) + await async_update_entity(hass, "vacuum.test_template_vacuum") state = hass.states.get("vacuum.test_template_vacuum") assert state.attributes["test_attribute"] == "It Works." diff --git a/tests/helpers/test_entity_component.py b/tests/helpers/test_entity_component.py index 1d18111b0d3..4df78317700 100644 --- a/tests/helpers/test_entity_component.py +++ b/tests/helpers/test_entity_component.py @@ -16,7 +16,7 @@ from homeassistant.const import ( import homeassistant.core as ha from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers import discovery -from homeassistant.helpers.entity_component import EntityComponent +from homeassistant.helpers.entity_component import EntityComponent, async_update_entity from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -385,7 +385,7 @@ async def test_update_entity(hass): # Called as part of async_add_entities assert len(entity.async_write_ha_state.mock_calls) == 1 - await hass.helpers.entity_component.async_update_entity(entity.entity_id) + await async_update_entity(hass, entity.entity_id) assert len(entity.async_update_ha_state.mock_calls) == 1 assert entity.async_update_ha_state.mock_calls[-1][1][0] is True