diff --git a/homeassistant/components/alert/__init__.py b/homeassistant/components/alert/__init__.py index 9aa3c62e76c..1f8176968d8 100644 --- a/homeassistant/components/alert/__init__.py +++ b/homeassistant/components/alert/__init__.py @@ -249,7 +249,7 @@ class Alert(ToggleEntity): else: await self._schedule_notify() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def end_alerting(self): """End the alert procedures.""" @@ -259,7 +259,7 @@ class Alert(ToggleEntity): self._firing = False if self._send_done_message: await self._notify_done_message() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def _schedule_notify(self): """Schedule a notification.""" diff --git a/homeassistant/components/android_ip_webcam/switch.py b/homeassistant/components/android_ip_webcam/switch.py index 2d5f2412d85..a494e78bdc7 100644 --- a/homeassistant/components/android_ip_webcam/switch.py +++ b/homeassistant/components/android_ip_webcam/switch.py @@ -67,7 +67,7 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): else: await self._ipcam.change_setting(self._setting, True) self._state = True - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn device off.""" @@ -80,7 +80,7 @@ class IPWebcamSettingsSwitch(AndroidIPCamEntity, SwitchDevice): else: await self._ipcam.change_setting(self._setting, False) self._state = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def icon(self): diff --git a/homeassistant/components/apple_tv/media_player.py b/homeassistant/components/apple_tv/media_player.py index c34a46a8b82..8b9f3355930 100644 --- a/homeassistant/components/apple_tv/media_player.py +++ b/homeassistant/components/apple_tv/media_player.py @@ -138,7 +138,7 @@ class AppleTvDevice(MediaPlayerDevice): def playstatus_update(self, updater, playing): """Print what is currently playing when it changes.""" self._playing = playing - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def playstatus_error(self, updater, exception): @@ -151,7 +151,7 @@ class AppleTvDevice(MediaPlayerDevice): # implemented here later. updater.start(initial_delay=10) self._playing = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def media_content_type(self): diff --git a/homeassistant/components/aqualogic/sensor.py b/homeassistant/components/aqualogic/sensor.py index dde092dd1fa..002b032fa92 100644 --- a/homeassistant/components/aqualogic/sensor.py +++ b/homeassistant/components/aqualogic/sensor.py @@ -109,4 +109,4 @@ class AquaLogicSensor(Entity): panel = self._processor.panel if panel is not None: self._state = getattr(panel, self._type) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/aqualogic/switch.py b/homeassistant/components/aqualogic/switch.py index 6950929ee80..e54fcff139d 100644 --- a/homeassistant/components/aqualogic/switch.py +++ b/homeassistant/components/aqualogic/switch.py @@ -6,7 +6,6 @@ import voluptuous as vol from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchDevice from homeassistant.const import CONF_MONITORED_CONDITIONS -from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from . import DOMAIN, UPDATE_TOPIC @@ -51,7 +50,6 @@ class AquaLogicSwitch(SwitchDevice): def __init__(self, processor, switch_type): """Initialize switch.""" - self._processor = processor self._type = switch_type self._state_name = { @@ -66,6 +64,7 @@ class AquaLogicSwitch(SwitchDevice): "aux_6": States.AUX_6, "aux_7": States.AUX_7, }[switch_type] + self._unsub_disp = None @property def name(self): @@ -102,11 +101,11 @@ class AquaLogicSwitch(SwitchDevice): async def async_added_to_hass(self): """Register callbacks.""" - self.hass.helpers.dispatcher.async_dispatcher_connect( - UPDATE_TOPIC, self.async_update_callback + self._unsub_disp = self.hass.helpers.dispatcher.async_dispatcher_connect( + UPDATE_TOPIC, self.async_write_ha_state ) - @callback - def async_update_callback(self): - """Update callback.""" - self.async_schedule_update_ha_state() + async def async_will_remove_from_hass(self): + """When entity will be removed from hass.""" + self._unsub_disp() + self._unsub_disp = None diff --git a/homeassistant/components/arcam_fmj/media_player.py b/homeassistant/components/arcam_fmj/media_player.py index 8a54c745695..a49802ea96f 100644 --- a/homeassistant/components/arcam_fmj/media_player.py +++ b/homeassistant/components/arcam_fmj/media_player.py @@ -130,7 +130,7 @@ class ArcamFmj(MediaPlayerDevice): @callback def _data(host): if host == self._state.client.host: - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _started(host): @@ -160,7 +160,7 @@ class ArcamFmj(MediaPlayerDevice): async def async_mute_volume(self, mute): """Send mute command.""" await self._state.set_mute(mute) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_select_source(self, source): """Select a specific source.""" @@ -171,7 +171,7 @@ class ArcamFmj(MediaPlayerDevice): return await self._state.set_source(value) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_select_sound_mode(self, sound_mode): """Select a specific source.""" @@ -184,22 +184,22 @@ class ArcamFmj(MediaPlayerDevice): _LOGGER.error("Unsupported sound_mode %s", sound_mode) return - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_volume_level(self, volume): """Set volume level, range 0..1.""" await self._state.set_volume(round(volume * 99.0)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_volume_up(self): """Turn volume up for media player.""" await self._state.inc_volume() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_volume_down(self): """Turn volume up for media player.""" await self._state.dec_volume() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self): """Turn the media player on.""" diff --git a/homeassistant/components/arlo/camera.py b/homeassistant/components/arlo/camera.py index 8152a76feec..e2bb85c9f84 100644 --- a/homeassistant/components/arlo/camera.py +++ b/homeassistant/components/arlo/camera.py @@ -7,7 +7,6 @@ import voluptuous as vol from homeassistant.components.camera import PLATFORM_SCHEMA, Camera from homeassistant.components.ffmpeg import DATA_FFMPEG from homeassistant.const import ATTR_BATTERY_LEVEL -from homeassistant.core import callback from homeassistant.helpers.aiohttp_client import async_aiohttp_proxy_stream import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect @@ -62,6 +61,7 @@ class ArloCam(Camera): self._ffmpeg_arguments = device_info.get(CONF_FFMPEG_ARGUMENTS) self._last_refresh = None self.attrs = {} + self._unsub_disp = None def camera_image(self): """Return a still image response from the camera.""" @@ -69,12 +69,14 @@ class ArloCam(Camera): async def async_added_to_hass(self): """Register callbacks.""" - async_dispatcher_connect(self.hass, SIGNAL_UPDATE_ARLO, self._update_callback) + self._unsub_disp = async_dispatcher_connect( + self.hass, SIGNAL_UPDATE_ARLO, self.async_write_ha_state + ) - @callback - def _update_callback(self): - """Call update method.""" - self.async_schedule_update_ha_state() + async def async_will_remove_from_hass(self): + """When entity will be removed from hass.""" + self._unsub_disp() + self._unsub_disp = None async def handle_async_mjpeg_stream(self, request): """Generate an HTTP MJPEG stream from the camera.""" diff --git a/homeassistant/components/arwn/sensor.py b/homeassistant/components/arwn/sensor.py index 014c46fd73c..6684a5b882b 100644 --- a/homeassistant/components/arwn/sensor.py +++ b/homeassistant/components/arwn/sensor.py @@ -119,7 +119,7 @@ class ArwnSensor(Entity): """Update the sensor with the most recent event.""" self.event = {} self.event.update(event) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def state(self): diff --git a/homeassistant/components/axis/axis_base.py b/homeassistant/components/axis/axis_base.py index f22a169a102..e61c4cea6b0 100644 --- a/homeassistant/components/axis/axis_base.py +++ b/homeassistant/components/axis/axis_base.py @@ -41,7 +41,7 @@ class AxisEntityBase(Entity): @callback def update_callback(self, no_delay=None): """Update the entities state.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() class AxisEventBase(AxisEntityBase): diff --git a/homeassistant/components/axis/binary_sensor.py b/homeassistant/components/axis/binary_sensor.py index d7551abebc1..d992c28746c 100644 --- a/homeassistant/components/axis/binary_sensor.py +++ b/homeassistant/components/axis/binary_sensor.py @@ -53,13 +53,13 @@ class AxisBinarySensor(AxisEventBase, BinarySensorDevice): self.remove_timer = None if self.is_on or delay == 0 or no_delay: - self.async_schedule_update_ha_state() + self.async_write_ha_state() return @callback def _delay_update(now): """Timer callback for sensor update.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() self.remove_timer = None self.remove_timer = async_track_point_in_utc_time( diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index e2cc0dd31e2..300927abefa 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -426,7 +426,7 @@ class BluesoundPlayer(MediaPlayerDevice): # communication is moved to a separate library await self.force_update_sync_status() - self.async_schedule_update_ha_state() + self.async_write_ha_state() elif response.status == 595: _LOGGER.info("Status 595 returned, treating as timeout") raise BluesoundPlayer._TimeoutException() @@ -439,7 +439,7 @@ class BluesoundPlayer(MediaPlayerDevice): self._is_online = False self._last_status_update = None self._status = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() _LOGGER.info("Client connection error, marking %s as offline", self._name) raise diff --git a/homeassistant/components/cast/media_player.py b/homeassistant/components/cast/media_player.py index e0c48062dfb..edac0e6e3ec 100644 --- a/homeassistant/components/cast/media_player.py +++ b/homeassistant/components/cast/media_player.py @@ -356,7 +356,7 @@ class CastDevice(MediaPlayerDevice): self.cast_status = chromecast.status self.media_status = chromecast.media_controller.status self._chromecast.start() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_del_cast_info(self, cast_info): """Remove the service.""" @@ -411,7 +411,7 @@ class CastDevice(MediaPlayerDevice): self._dynamic_group_available = False self.dynamic_group_media_status = chromecast.media_controller.status self._dynamic_group_cast.start() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_del_dynamic_group(self): """Remove the dynamic group.""" @@ -432,7 +432,7 @@ class CastDevice(MediaPlayerDevice): self._dynamic_group_invalidate() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def _async_disconnect(self): """Disconnect Chromecast object if it is set.""" @@ -447,7 +447,7 @@ class CastDevice(MediaPlayerDevice): self._cast_info.port, ) self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() await self.hass.async_add_executor_job(self._chromecast.disconnect) if self._dynamic_group_cast is not None: @@ -455,7 +455,7 @@ class CastDevice(MediaPlayerDevice): self._invalidate() - self.async_schedule_update_ha_state() + self.async_write_ha_state() def _invalidate(self): """Invalidate some attributes.""" diff --git a/homeassistant/components/cloud/binary_sensor.py b/homeassistant/components/cloud/binary_sensor.py index 056105f8071..c2974678faa 100644 --- a/homeassistant/components/cloud/binary_sensor.py +++ b/homeassistant/components/cloud/binary_sensor.py @@ -62,7 +62,7 @@ class CloudRemoteBinary(BinarySensorDevice): async def async_state_update(data): """Update callback.""" await asyncio.sleep(WAIT_UNTIL_CHANGE) - self.async_schedule_update_ha_state() + self.async_write_ha_state() self._unsub_dispatcher = async_dispatcher_connect( self.hass, DISPATCHER_REMOTE_UPDATE, async_state_update diff --git a/homeassistant/components/deconz/binary_sensor.py b/homeassistant/components/deconz/binary_sensor.py index 6a528a66ba6..d16722525f9 100644 --- a/homeassistant/components/deconz/binary_sensor.py +++ b/homeassistant/components/deconz/binary_sensor.py @@ -64,7 +64,7 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorDevice): keys = {"on", "reachable", "state"} if force_update or self._device.changed_keys.intersection(keys): - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): diff --git a/homeassistant/components/deconz/deconz_device.py b/homeassistant/components/deconz/deconz_device.py index 0724f9f9b45..80557caeca6 100644 --- a/homeassistant/components/deconz/deconz_device.py +++ b/homeassistant/components/deconz/deconz_device.py @@ -106,7 +106,7 @@ class DeconzDevice(DeconzBase, Entity): if ignore_update: return - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def available(self): diff --git a/homeassistant/components/deconz/sensor.py b/homeassistant/components/deconz/sensor.py index fd8ffeeaaf0..ae0e55ae51f 100644 --- a/homeassistant/components/deconz/sensor.py +++ b/homeassistant/components/deconz/sensor.py @@ -109,7 +109,7 @@ class DeconzSensor(DeconzDevice): keys = {"on", "reachable", "state"} if force_update or self._device.changed_keys.intersection(keys): - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def state(self): @@ -174,7 +174,7 @@ class DeconzBattery(DeconzDevice): keys = {"battery", "reachable"} if force_update or self._device.changed_keys.intersection(keys): - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def unique_id(self): diff --git a/homeassistant/components/derivative/sensor.py b/homeassistant/components/derivative/sensor.py index 202c5885887..65bbd9affee 100644 --- a/homeassistant/components/derivative/sensor.py +++ b/homeassistant/components/derivative/sensor.py @@ -182,7 +182,7 @@ class DerivativeSensor(RestoreEntity): _LOGGER.error("Could not calculate derivative: %s", err) else: self._state = derivative - self.async_schedule_update_ha_state() + self.async_write_ha_state() async_track_state_change(self.hass, self._sensor_source_id, calc_derivative) diff --git a/homeassistant/components/dsmr_reader/sensor.py b/homeassistant/components/dsmr_reader/sensor.py index 01c010c4971..341451522d4 100644 --- a/homeassistant/components/dsmr_reader/sensor.py +++ b/homeassistant/components/dsmr_reader/sensor.py @@ -48,7 +48,7 @@ class DSMRSensor(Entity): else: self._state = message.payload - self.async_schedule_update_ha_state() + self.async_write_ha_state() await mqtt.async_subscribe(self.hass, self._topic, message_received, 1) diff --git a/homeassistant/components/emby/media_player.py b/homeassistant/components/emby/media_player.py index e063fc49f2f..19fad984b27 100644 --- a/homeassistant/components/emby/media_player.py +++ b/homeassistant/components/emby/media_player.py @@ -166,7 +166,7 @@ class EmbyDevice(MediaPlayerDevice): self.media_status_last_position = None self.media_status_received = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def available(self): diff --git a/homeassistant/components/envisalink/alarm_control_panel.py b/homeassistant/components/envisalink/alarm_control_panel.py index 7630169dcad..beb1c1cda82 100644 --- a/homeassistant/components/envisalink/alarm_control_panel.py +++ b/homeassistant/components/envisalink/alarm_control_panel.py @@ -121,7 +121,7 @@ class EnvisalinkAlarm(EnvisalinkDevice, AlarmControlPanel): def _update_callback(self, partition): """Update Home Assistant state, if needed.""" if partition is None or int(partition) == self._partition_number: - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def code_format(self): diff --git a/homeassistant/components/envisalink/binary_sensor.py b/homeassistant/components/envisalink/binary_sensor.py index fbe9824d067..f698a9d27d9 100644 --- a/homeassistant/components/envisalink/binary_sensor.py +++ b/homeassistant/components/envisalink/binary_sensor.py @@ -94,4 +94,4 @@ class EnvisalinkBinarySensor(EnvisalinkDevice, BinarySensorDevice): def _update_callback(self, zone): """Update the zone's state, if needed.""" if zone is None or int(zone) == self._zone_number: - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/envisalink/sensor.py b/homeassistant/components/envisalink/sensor.py index 05ad0783fac..b4f15a2999e 100644 --- a/homeassistant/components/envisalink/sensor.py +++ b/homeassistant/components/envisalink/sensor.py @@ -74,4 +74,4 @@ class EnvisalinkSensor(EnvisalinkDevice, Entity): def _update_callback(self, partition): """Update the partition state in HA, if needed.""" if partition is None or int(partition) == self._partition_number: - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index 9fbe3eff822..3895e172024 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -510,7 +510,7 @@ class EsphomeEntity(Entity): async def _on_state_update(self) -> None: """Update the entity state when state or static info changed.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def _on_device_update(self) -> None: """Update the entity state when device info has changed.""" @@ -519,7 +519,7 @@ class EsphomeEntity(Entity): # Only update the HA state when the full state arrives # through the next entity state packet. return - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_will_remove_from_hass(self) -> None: """Unregister callbacks.""" diff --git a/homeassistant/components/ffmpeg/__init__.py b/homeassistant/components/ffmpeg/__init__.py index bc402b46fb2..ad0c590b87d 100644 --- a/homeassistant/components/ffmpeg/__init__.py +++ b/homeassistant/components/ffmpeg/__init__.py @@ -202,6 +202,6 @@ class FFmpegBase(Entity): async def async_start_handle(event): """Start FFmpeg process.""" await self._async_start_ffmpeg(None) - self.async_schedule_update_ha_state() + self.async_write_ha_state() self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, async_start_handle) diff --git a/homeassistant/components/ffmpeg_motion/binary_sensor.py b/homeassistant/components/ffmpeg_motion/binary_sensor.py index 294fcc2518f..e3a9c09b5d9 100644 --- a/homeassistant/components/ffmpeg_motion/binary_sensor.py +++ b/homeassistant/components/ffmpeg_motion/binary_sensor.py @@ -70,7 +70,7 @@ class FFmpegBinarySensor(FFmpegBase, BinarySensorDevice): def _async_callback(self, state): """HA-FFmpeg callback for noise detection.""" self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): diff --git a/homeassistant/components/filter/sensor.py b/homeassistant/components/filter/sensor.py index 4d508ce2d81..7c2a35938b2 100644 --- a/homeassistant/components/filter/sensor.py +++ b/homeassistant/components/filter/sensor.py @@ -212,7 +212,7 @@ class SensorFilter(Entity): ) if update_ha: - self.async_schedule_update_ha_state() + self.async_write_ha_state() if "recorder" in self.hass.config.components: history_list = [] diff --git a/homeassistant/components/flux/switch.py b/homeassistant/components/flux/switch.py index 0205bb308be..61bdb9a2862 100644 --- a/homeassistant/components/flux/switch.py +++ b/homeassistant/components/flux/switch.py @@ -233,7 +233,7 @@ class FluxSwitch(SwitchDevice, RestoreEntity): # Make initial update await self.async_flux_update() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn off flux.""" @@ -241,7 +241,7 @@ class FluxSwitch(SwitchDevice, RestoreEntity): self.unsub_tracker() self.unsub_tracker = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_flux_update(self, utcnow=None): """Update all the lights using flux.""" diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index a7ddcc08314..09af5ad5c44 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -368,7 +368,7 @@ class GenericThermostat(ClimateDevice, RestoreEntity): """Handle heater switch state changes.""" if new_state is None: return - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _async_update_temp(self, state): diff --git a/homeassistant/components/greeneye_monitor/sensor.py b/homeassistant/components/greeneye_monitor/sensor.py index 1d53525ab37..ff5aff6fe50 100644 --- a/homeassistant/components/greeneye_monitor/sensor.py +++ b/homeassistant/components/greeneye_monitor/sensor.py @@ -129,7 +129,7 @@ class GEMSensor(Entity): async def async_will_remove_from_hass(self): """Remove listener from the sensor.""" if self._sensor: - self._sensor.remove_listener(self._schedule_update) + self._sensor.remove_listener(self.async_write_ha_state) else: monitors = self.hass.data[DATA_GREENEYE_MONITOR] monitors.remove_listener(self._on_new_monitor) @@ -140,16 +140,13 @@ class GEMSensor(Entity): return False self._sensor = self._get_sensor(monitor) - self._sensor.add_listener(self._schedule_update) + self._sensor.add_listener(self.async_write_ha_state) return True def _get_sensor(self, monitor): raise NotImplementedError() - def _schedule_update(self): - self.async_schedule_update_ha_state(False) - class CurrentSensor(GEMSensor): """Entity showing power usage on one channel of the monitor.""" diff --git a/homeassistant/components/harmony/remote.py b/homeassistant/components/harmony/remote.py index 7d23e15a4e7..024af9b1580 100644 --- a/homeassistant/components/harmony/remote.py +++ b/homeassistant/components/harmony/remote.py @@ -264,7 +264,7 @@ class HarmonyRemote(remote.RemoteDevice): self._current_activity = activity_name self._state = bool(activity_id != -1) self._available = True - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def new_config(self, _=None): """Call for updating the current activity.""" @@ -289,7 +289,7 @@ class HarmonyRemote(remote.RemoteDevice): if not self._available: # Still disconnected. Let the state engine know. - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self, **kwargs): """Start an activity from the Harmony device.""" diff --git a/homeassistant/components/hive/__init__.py b/homeassistant/components/hive/__init__.py index edd3388e74f..88103ec94c1 100644 --- a/homeassistant/components/hive/__init__.py +++ b/homeassistant/components/hive/__init__.py @@ -12,7 +12,6 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_USERNAME, ) -from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send @@ -183,14 +182,17 @@ class HiveEntity(Entity): self.session = session self.attributes = {} self._unique_id = f"{self.node_id}-{self.device_type}" + self._unsub_disp = None async def async_added_to_hass(self): """When entity is added to Home Assistant.""" - async_dispatcher_connect(self.hass, DOMAIN, self._update_callback) + self._unsub_disp = async_dispatcher_connect( + self.hass, DOMAIN, self.async_write_ha_state + ) if self.device_type in SERVICES: self.session.entity_lookup[self.entity_id] = self.node_id - @callback - def _update_callback(self): - """Call update method.""" - self.async_schedule_update_ha_state() + async def async_will_remove_from_hass(self): + """When entity will be removed from hass.""" + self._unsub_disp() + self._unsub_disp = None diff --git a/homeassistant/components/hlk_sw16/__init__.py b/homeassistant/components/hlk_sw16/__init__.py index 1750e9b0ff4..52a82184dcc 100644 --- a/homeassistant/components/hlk_sw16/__init__.py +++ b/homeassistant/components/hlk_sw16/__init__.py @@ -136,7 +136,7 @@ class SW16Device(Entity): """Propagate changes through ha.""" _LOGGER.debug("Relay %s new state callback: %r", self._device_port, event) self._is_on = event - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def should_poll(self): @@ -156,7 +156,7 @@ class SW16Device(Entity): @callback def _availability_callback(self, availability): """Update availability state.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Register update callback.""" diff --git a/homeassistant/components/homematicip_cloud/alarm_control_panel.py b/homeassistant/components/homematicip_cloud/alarm_control_panel.py index f5316350091..fd3958344f5 100644 --- a/homeassistant/components/homematicip_cloud/alarm_control_panel.py +++ b/homeassistant/components/homematicip_cloud/alarm_control_panel.py @@ -102,7 +102,7 @@ class HomematicipAlarmControlPanel(AlarmControlPanel): # Don't update disabled entities if self.enabled: _LOGGER.debug("Event %s (%s)", self.name, CONST_ALARM_CONTROL_PANEL_NAME) - self.async_schedule_update_ha_state() + self.async_write_ha_state() else: _LOGGER.debug( "Device Changed Event for %s (Alarm Control Panel) not fired. Entity is disabled.", diff --git a/homeassistant/components/homematicip_cloud/device.py b/homeassistant/components/homematicip_cloud/device.py index 0407a1a0fe2..c2b67758152 100644 --- a/homeassistant/components/homematicip_cloud/device.py +++ b/homeassistant/components/homematicip_cloud/device.py @@ -108,7 +108,7 @@ class HomematicipGenericDevice(Entity): # Don't update disabled entities if self.enabled: _LOGGER.debug("Event %s (%s)", self.name, self._device.modelType) - self.async_schedule_update_ha_state() + self.async_write_ha_state() else: _LOGGER.debug( "Device Changed Event for %s (%s) not fired. Entity is disabled.", diff --git a/homeassistant/components/homeworks/light.py b/homeassistant/components/homeworks/light.py index 56d5bcacc47..4cfb2b0a26d 100644 --- a/homeassistant/components/homeworks/light.py +++ b/homeassistant/components/homeworks/light.py @@ -93,4 +93,4 @@ class HomeworksLight(HomeworksDevice, Light): self._level = int((values[1] * 255.0) / 100.0) if self._level != 0: self._prev_level = self._level - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/iaqualink/__init__.py b/homeassistant/components/iaqualink/__init__.py index 16c8deac72e..214bdf302ea 100644 --- a/homeassistant/components/iaqualink/__init__.py +++ b/homeassistant/components/iaqualink/__init__.py @@ -25,7 +25,6 @@ from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME -from homeassistant.core import callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -203,14 +202,18 @@ class AqualinkEntity(Entity): def __init__(self, dev: AqualinkDevice): """Initialize the entity.""" self.dev = dev + self._unsub_disp = None async def async_added_to_hass(self) -> None: """Set up a listener when this entity is added to HA.""" - async_dispatcher_connect(self.hass, DOMAIN, self._update_callback) + self._unsub_disp = async_dispatcher_connect( + self.hass, DOMAIN, self.async_write_ha_state + ) - @callback - def _update_callback(self) -> None: - self.async_schedule_update_ha_state() + async def async_will_remove_from_hass(self): + """When entity will be removed from hass.""" + self._unsub_disp() + self._unsub_disp = None @property def should_poll(self) -> bool: diff --git a/homeassistant/components/insteon/insteon_entity.py b/homeassistant/components/insteon/insteon_entity.py index c489dd8e382..e411cd82045 100644 --- a/homeassistant/components/insteon/insteon_entity.py +++ b/homeassistant/components/insteon/insteon_entity.py @@ -80,7 +80,7 @@ class InsteonEntity(Entity): group, val, ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Register INSTEON update events.""" diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index 6201348f21c..3365e5b10c8 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -172,7 +172,7 @@ class IntegrationSensor(RestoreEntity): _LOGGER.error("Could not calculate integral: %s", err) else: self._state += integral - self.async_schedule_update_ha_state() + self.async_write_ha_state() async_track_state_change(self.hass, self._sensor_source_id, calc_integration) diff --git a/homeassistant/components/izone/climate.py b/homeassistant/components/izone/climate.py index dde71d14a9c..b17313925a8 100644 --- a/homeassistant/components/izone/climate.py +++ b/homeassistant/components/izone/climate.py @@ -175,7 +175,7 @@ class ControllerDevice(ClimateDevice): """Handle controller data updates.""" if ctrl is not self._controller: return - self.async_schedule_update_ha_state() + self.async_write_ha_state() for zone in self.zones.values(): zone.async_schedule_update_ha_state() @@ -210,7 +210,7 @@ class ControllerDevice(ClimateDevice): ) self._available = available - self.async_schedule_update_ha_state() + self.async_write_ha_state() for zone in self.zones.values(): zone.async_schedule_update_ha_state() @@ -439,7 +439,7 @@ class ZoneDevice(ClimateDevice): if zone is not self._zone: return self._name = zone.name.title() - self.async_schedule_update_ha_state() + self.async_write_ha_state() self.async_on_remove( async_dispatcher_connect(self.hass, DISPATCH_ZONE_UPDATE, zone_update) @@ -549,7 +549,7 @@ class ZoneDevice(ClimateDevice): """Set new target operation mode.""" mode = self._state_to_pizone[hvac_mode] await self._controller.wrap_and_catch(self._zone.set_mode(mode)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): @@ -562,9 +562,9 @@ class ZoneDevice(ClimateDevice): await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.AUTO)) else: await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.OPEN)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self): """Turn device off (close zone).""" await self._controller.wrap_and_catch(self._zone.set_mode(Zone.Mode.CLOSE)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/kiwi/lock.py b/homeassistant/components/kiwi/lock.py index b13906b44f5..4a58f8f43c2 100644 --- a/homeassistant/components/kiwi/lock.py +++ b/homeassistant/components/kiwi/lock.py @@ -94,7 +94,7 @@ class KiwiLock(LockDevice): def clear_unlock_state(self, _): """Clear unlock state automatically.""" self._state = STATE_LOCKED - self.async_schedule_update_ha_state() + self.async_write_ha_state() def unlock(self, **kwargs): """Unlock the device.""" diff --git a/homeassistant/components/knx/cover.py b/homeassistant/components/knx/cover.py index d0b8d8c1163..3c67e2fd558 100644 --- a/homeassistant/components/knx/cover.py +++ b/homeassistant/components/knx/cover.py @@ -204,7 +204,7 @@ class KNXCover(CoverDevice): @callback def auto_updater_hook(self, now): """Call for the autoupdater.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() if self.device.position_reached(): self.stop_auto_updater() diff --git a/homeassistant/components/kodi/media_player.py b/homeassistant/components/kodi/media_player.py index 4fd86d078a0..dccc4ac0765 100644 --- a/homeassistant/components/kodi/media_player.py +++ b/homeassistant/components/kodi/media_player.py @@ -364,14 +364,14 @@ class KodiDevice(MediaPlayerDevice): self._item = {} self._media_position_updated_at = None self._media_position = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def async_on_volume_changed(self, sender, data): """Handle the volume changes.""" self._app_properties["volume"] = data["volume"] self._app_properties["muted"] = data["muted"] - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def async_on_quit(self, sender, data): @@ -429,7 +429,7 @@ class KodiDevice(MediaPlayerDevice): # to reconnect on the next poll. pass # Update HA state after Kodi disconnects - self.async_schedule_update_ha_state() + self.async_write_ha_state() # Create a task instead of adding a tracking job, since this task will # run until the websocket connection is closed. diff --git a/homeassistant/components/konnected/binary_sensor.py b/homeassistant/components/konnected/binary_sensor.py index 50f897e3a85..f2f79f5ed7d 100644 --- a/homeassistant/components/konnected/binary_sensor.py +++ b/homeassistant/components/konnected/binary_sensor.py @@ -87,4 +87,4 @@ class KonnectedBinarySensor(BinarySensorDevice): def async_set_state(self, state): """Update the sensor's state.""" self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/konnected/sensor.py b/homeassistant/components/konnected/sensor.py index e936898d7fb..74554f2afc2 100644 --- a/homeassistant/components/konnected/sensor.py +++ b/homeassistant/components/konnected/sensor.py @@ -137,4 +137,4 @@ class KonnectedSensor(Entity): self._state = int(float(state)) else: self._state = round(float(state), 1) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/konnected/switch.py b/homeassistant/components/konnected/switch.py index b8ddec20440..afc83458aaf 100644 --- a/homeassistant/components/konnected/switch.py +++ b/homeassistant/components/konnected/switch.py @@ -117,7 +117,7 @@ class KonnectedSwitch(ToggleEntity): def _set_state(self, state): self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() _LOGGER.debug( "Setting status of %s actuator zone %s to %s", self._device_id, diff --git a/homeassistant/components/lacrosse/sensor.py b/homeassistant/components/lacrosse/sensor.py index 1d38764710a..f0ec885a8fe 100644 --- a/homeassistant/components/lacrosse/sensor.py +++ b/homeassistant/components/lacrosse/sensor.py @@ -171,7 +171,7 @@ class LaCrosseSensor(Entity): """Triggered when value is expired.""" self._expiration_trigger = None self._value = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LaCrosseTemperature(LaCrosseSensor): diff --git a/homeassistant/components/lcn/binary_sensor.py b/homeassistant/components/lcn/binary_sensor.py index e0039f29e58..249adf04af8 100644 --- a/homeassistant/components/lcn/binary_sensor.py +++ b/homeassistant/components/lcn/binary_sensor.py @@ -68,7 +68,7 @@ class LcnRegulatorLockSensor(LcnDevice, BinarySensorDevice): return self._value = input_obj.get_value().is_locked_regulator() - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnBinarySensor(LcnDevice, BinarySensorDevice): @@ -100,7 +100,7 @@ class LcnBinarySensor(LcnDevice, BinarySensorDevice): return self._value = input_obj.get_state(self.bin_sensor_port.value) - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnLockKeysSensor(LcnDevice, BinarySensorDevice): @@ -135,4 +135,4 @@ class LcnLockKeysSensor(LcnDevice, BinarySensorDevice): key_id = int(self.source.name[1]) - 1 self._value = input_obj.get_state(table_id, key_id) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lcn/climate.py b/homeassistant/components/lcn/climate.py index aec68af6076..12fff2f479b 100644 --- a/homeassistant/components/lcn/climate.py +++ b/homeassistant/components/lcn/climate.py @@ -125,7 +125,7 @@ class LcnClimate(LcnDevice, ClimateDevice): self.address_connection.lock_regulator(self.regulator_id, True) self._target_temperature = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_temperature(self, **kwargs): """Set new target temperature.""" @@ -137,7 +137,7 @@ class LcnClimate(LcnDevice, ClimateDevice): self.address_connection.var_abs( self.setpoint, self._target_temperature, self.unit ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() def input_received(self, input_obj): """Set temperature value when LCN input object is received.""" @@ -151,4 +151,4 @@ class LcnClimate(LcnDevice, ClimateDevice): if self._is_on: self._target_temperature = input_obj.get_value().to_var_unit(self.unit) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lcn/cover.py b/homeassistant/components/lcn/cover.py index c1bd7070f53..ba831c3a1a9 100644 --- a/homeassistant/components/lcn/cover.py +++ b/homeassistant/components/lcn/cover.py @@ -108,7 +108,7 @@ class LcnOutputsCover(LcnDevice, CoverDevice): elif self.state_down and not self.state_up: self._closed = True # Cover closed - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnRelayCover(LcnDevice, CoverDevice): @@ -167,4 +167,4 @@ class LcnRelayCover(LcnDevice, CoverDevice): if states[self.motor_port_onoff]: # motor is on self._closed = states[self.motor_port_updown] # set direction - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lcn/light.py b/homeassistant/components/lcn/light.py index 4c67156c787..40a592f89c9 100644 --- a/homeassistant/components/lcn/light.py +++ b/homeassistant/components/lcn/light.py @@ -132,7 +132,7 @@ class LcnOutputLight(LcnDevice, Light): self._is_dimming_to_zero = False if not self._is_dimming_to_zero: self._is_on = self.brightness > 0 - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnRelayLight(LcnDevice, Light): @@ -182,4 +182,4 @@ class LcnRelayLight(LcnDevice, Light): return self._is_on = input_obj.get_state(self.output.value) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lcn/sensor.py b/homeassistant/components/lcn/sensor.py index d4bb5566e34..ddf7e61a3f6 100644 --- a/homeassistant/components/lcn/sensor.py +++ b/homeassistant/components/lcn/sensor.py @@ -78,7 +78,7 @@ class LcnVariableSensor(LcnDevice): return self._value = input_obj.get_value().to_var_unit(self.unit) - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnLedLogicSensor(LcnDevice): @@ -115,4 +115,4 @@ class LcnLedLogicSensor(LcnDevice): elif self.source in pypck.lcn_defs.LogicOpPort: self._value = input_obj.get_logic_op_state(self.source.value).name.lower() - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lcn/switch.py b/homeassistant/components/lcn/switch.py index f19548c4aee..b0e16e412b3 100644 --- a/homeassistant/components/lcn/switch.py +++ b/homeassistant/components/lcn/switch.py @@ -76,7 +76,7 @@ class LcnOutputSwitch(LcnDevice, SwitchDevice): return self._is_on = input_obj.get_percent() > 0 - self.async_schedule_update_ha_state() + self.async_write_ha_state() class LcnRelaySwitch(LcnDevice, SwitchDevice): @@ -124,4 +124,4 @@ class LcnRelaySwitch(LcnDevice, SwitchDevice): return self._is_on = input_obj.get_state(self.output.value) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lightwave/light.py b/homeassistant/components/lightwave/light.py index 4aabcbc75c5..78e4c43a0e7 100644 --- a/homeassistant/components/lightwave/light.py +++ b/homeassistant/components/lightwave/light.py @@ -72,10 +72,10 @@ class LWRFLight(Light): else: self._lwlink.turn_on_light(self._device_id, self._name) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn the LightWave light off.""" self._state = False self._lwlink.turn_off(self._device_id, self._name) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/lightwave/switch.py b/homeassistant/components/lightwave/switch.py index bfc4407458a..16c2aa53462 100644 --- a/homeassistant/components/lightwave/switch.py +++ b/homeassistant/components/lightwave/switch.py @@ -49,10 +49,10 @@ class LWRFSwitch(SwitchDevice): """Turn the LightWave switch on.""" self._state = True self._lwlink.turn_on_switch(self._device_id, self._name) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn the LightWave switch off.""" self._state = False self._lwlink.turn_off(self._device_id, self._name) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/mediaroom/media_player.py b/homeassistant/components/mediaroom/media_player.py index 28d20d0db4b..8db9cb6fa37 100644 --- a/homeassistant/components/mediaroom/media_player.py +++ b/homeassistant/components/mediaroom/media_player.py @@ -176,7 +176,7 @@ class MediaroomDevice(MediaPlayerDevice): self.set_state(stb_state) _LOGGER.debug("STB(%s) is [%s]", self.host, self._state) self._available = True - self.async_schedule_update_ha_state() + self.async_write_ha_state() async_dispatcher_connect(self.hass, SIGNAL_STB_NOTIFY, async_notify_received) @@ -200,7 +200,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def unique_id(self): @@ -242,7 +242,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self): """Turn off the receiver.""" @@ -254,7 +254,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_media_play(self): """Send play command.""" @@ -267,7 +267,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_media_pause(self): """Send pause command.""" @@ -279,7 +279,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_media_stop(self): """Send stop command.""" @@ -291,7 +291,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_media_previous_track(self): """Send Program Down command.""" @@ -303,7 +303,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_media_next_track(self): """Send Program Up command.""" @@ -315,7 +315,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_volume_up(self): """Send volume up command.""" @@ -325,7 +325,7 @@ class MediaroomDevice(MediaPlayerDevice): self._available = True except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_volume_down(self): """Send volume up command.""" @@ -334,7 +334,7 @@ class MediaroomDevice(MediaPlayerDevice): await self.stb.send_cmd("VolDown") except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_mute_volume(self, mute): """Send mute command.""" @@ -343,4 +343,4 @@ class MediaroomDevice(MediaPlayerDevice): await self.stb.send_cmd("Mute") except PyMediaroomError: self._available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/mobile_app/entity.py b/homeassistant/components/mobile_app/entity.py index 5200c6b0c12..7a12f617740 100644 --- a/homeassistant/components/mobile_app/entity.py +++ b/homeassistant/components/mobile_app/entity.py @@ -103,4 +103,4 @@ class MobileAppEntity(Entity): return self._config = data - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/mqtt_room/sensor.py b/homeassistant/components/mqtt_room/sensor.py index 580ffd606f3..0d07133b396 100644 --- a/homeassistant/components/mqtt_room/sensor.py +++ b/homeassistant/components/mqtt_room/sensor.py @@ -92,7 +92,7 @@ class MQTTRoomSensor(Entity): self._distance = distance self._updated = dt.utcnow() - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def message_received(msg): diff --git a/homeassistant/components/mychevy/binary_sensor.py b/homeassistant/components/mychevy/binary_sensor.py index e5b0dc8b6ea..822a7988d0d 100644 --- a/homeassistant/components/mychevy/binary_sensor.py +++ b/homeassistant/components/mychevy/binary_sensor.py @@ -73,7 +73,7 @@ class EVBinarySensor(BinarySensorDevice): """Update state.""" if self._car is not None: self._is_on = getattr(self._car, self._attr, None) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def should_poll(self): diff --git a/homeassistant/components/mychevy/sensor.py b/homeassistant/components/mychevy/sensor.py index f45c81a0007..9f8ea5607d9 100644 --- a/homeassistant/components/mychevy/sensor.py +++ b/homeassistant/components/mychevy/sensor.py @@ -70,7 +70,7 @@ class MyChevyStatus(Entity): if self._state != MYCHEVY_SUCCESS: _LOGGER.debug("Successfully connected to mychevy website") self._state = MYCHEVY_SUCCESS - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def error(self): @@ -80,7 +80,7 @@ class MyChevyStatus(Entity): "This probably means the mychevy to OnStar link is down" ) self._state = MYCHEVY_ERROR - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def icon(self): @@ -156,7 +156,7 @@ class EVSensor(Entity): self._state = getattr(self._car, self._attr, None) for attr in self._extra_attrs: self._state_attributes[attr] = getattr(self._car, attr) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def state(self): diff --git a/homeassistant/components/mysensors/climate.py b/homeassistant/components/mysensors/climate.py index 4939c0c83e5..b00a0d0d9d5 100644 --- a/homeassistant/components/mysensors/climate.py +++ b/homeassistant/components/mysensors/climate.py @@ -162,7 +162,7 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateDevice): if self.gateway.optimistic: # Optimistically assume that device has changed state self._values[value_type] = value - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_fan_mode(self, fan_mode): """Set new target temperature.""" @@ -173,7 +173,7 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateDevice): if self.gateway.optimistic: # Optimistically assume that device has changed state self._values[set_req.V_HVAC_SPEED] = fan_mode - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_hvac_mode(self, hvac_mode): """Set new target temperature.""" @@ -187,7 +187,7 @@ class MySensorsHVAC(mysensors.device.MySensorsEntity, ClimateDevice): if self.gateway.optimistic: # Optimistically assume that device has changed state self._values[self.value_type] = hvac_mode - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the controller with the latest value from a sensor.""" diff --git a/homeassistant/components/mysensors/cover.py b/homeassistant/components/mysensors/cover.py index 6c02e430ba4..b60cf9457a9 100644 --- a/homeassistant/components/mysensors/cover.py +++ b/homeassistant/components/mysensors/cover.py @@ -52,7 +52,7 @@ class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): self._values[set_req.V_DIMMER] = 100 else: self._values[set_req.V_LIGHT] = STATE_ON - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" @@ -66,7 +66,7 @@ class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): self._values[set_req.V_DIMMER] = 0 else: self._values[set_req.V_LIGHT] = STATE_OFF - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_cover_position(self, **kwargs): """Move the cover to a specific position.""" @@ -78,7 +78,7 @@ class MySensorsCover(mysensors.device.MySensorsEntity, CoverDevice): if self.gateway.optimistic: # Optimistically assume that cover has changed state. self._values[set_req.V_DIMMER] = position - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_stop_cover(self, **kwargs): """Stop the device.""" diff --git a/homeassistant/components/mysensors/light.py b/homeassistant/components/mysensors/light.py index b25cf977d83..1585de4b462 100644 --- a/homeassistant/components/mysensors/light.py +++ b/homeassistant/components/mysensors/light.py @@ -149,7 +149,7 @@ class MySensorsLight(mysensors.device.MySensorsEntity, Light): # optimistically assume that light has changed state self._state = False self._values[value_type] = STATE_OFF - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _async_update_light(self): @@ -189,7 +189,7 @@ class MySensorsLightDimmer(MySensorsLight): self._turn_on_light() self._turn_on_dimmer(**kwargs) if self.gateway.optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the controller with the latest value from a sensor.""" @@ -215,7 +215,7 @@ class MySensorsLightRGB(MySensorsLight): self._turn_on_dimmer(**kwargs) self._turn_on_rgb_and_w("%02x%02x%02x", **kwargs) if self.gateway.optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the controller with the latest value from a sensor.""" @@ -242,4 +242,4 @@ class MySensorsLightRGBW(MySensorsLightRGB): self._turn_on_dimmer(**kwargs) self._turn_on_rgb_and_w("%02x%02x%02x%02x", **kwargs) if self.gateway.optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/mysensors/switch.py b/homeassistant/components/mysensors/switch.py index ec28649d70f..16bb1ee6deb 100644 --- a/homeassistant/components/mysensors/switch.py +++ b/homeassistant/components/mysensors/switch.py @@ -99,7 +99,7 @@ class MySensorsSwitch(mysensors.device.MySensorsEntity, SwitchDevice): if self.gateway.optimistic: # Optimistically assume that switch has changed state self._values[self.value_type] = STATE_ON - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn the switch off.""" @@ -109,7 +109,7 @@ class MySensorsSwitch(mysensors.device.MySensorsEntity, SwitchDevice): if self.gateway.optimistic: # Optimistically assume that switch has changed state self._values[self.value_type] = STATE_OFF - self.async_schedule_update_ha_state() + self.async_write_ha_state() class MySensorsIRSwitch(MySensorsSwitch): @@ -141,7 +141,7 @@ class MySensorsIRSwitch(MySensorsSwitch): # Optimistically assume that switch has changed state self._values[self.value_type] = self._ir_code self._values[set_req.V_LIGHT] = STATE_ON - self.async_schedule_update_ha_state() + self.async_write_ha_state() # Turn off switch after switch was turned on await self.async_turn_off() @@ -154,7 +154,7 @@ class MySensorsIRSwitch(MySensorsSwitch): if self.gateway.optimistic: # Optimistically assume that switch has changed state self._values[set_req.V_LIGHT] = STATE_OFF - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the controller with the latest value from a sensor.""" diff --git a/homeassistant/components/mystrom/binary_sensor.py b/homeassistant/components/mystrom/binary_sensor.py index 3da77d6d943..c584440874a 100644 --- a/homeassistant/components/mystrom/binary_sensor.py +++ b/homeassistant/components/mystrom/binary_sensor.py @@ -86,4 +86,4 @@ class MyStromBinarySensor(BinarySensorDevice): def async_on_update(self, value): """Receive an update.""" self._state = value - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/ness_alarm/alarm_control_panel.py b/homeassistant/components/ness_alarm/alarm_control_panel.py index f77244a584e..8b7867fdc06 100644 --- a/homeassistant/components/ness_alarm/alarm_control_panel.py +++ b/homeassistant/components/ness_alarm/alarm_control_panel.py @@ -111,4 +111,4 @@ class NessAlarmPanel(alarm.AlarmControlPanel): else: _LOGGER.warning("Unhandled arming state: %s", arming_state) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/ness_alarm/binary_sensor.py b/homeassistant/components/ness_alarm/binary_sensor.py index 0f15b6e937b..69acc97130d 100644 --- a/homeassistant/components/ness_alarm/binary_sensor.py +++ b/homeassistant/components/ness_alarm/binary_sensor.py @@ -79,4 +79,4 @@ class NessZoneBinarySensor(BinarySensorDevice): """Handle zone state update.""" if self._zone_id == data.zone_id: self._state = data.state - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/opentherm_gw/binary_sensor.py b/homeassistant/components/opentherm_gw/binary_sensor.py index eff11554a39..663635cd06a 100644 --- a/homeassistant/components/opentherm_gw/binary_sensor.py +++ b/homeassistant/components/opentherm_gw/binary_sensor.py @@ -69,7 +69,7 @@ class OpenThermBinarySensor(BinarySensorDevice): def receive_report(self, status): """Handle status updates from the component.""" self._state = bool(status.get(self._var)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def name(self): diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index 2db20662a77..b447018e799 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -80,7 +80,7 @@ class OpenThermClimate(ClimateDevice): """Update climate entity options.""" self.floor_temp = entry.options[CONF_FLOOR_TEMP] self.temp_precision = entry.options[CONF_PRECISION] - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Connect to the OpenTherm Gateway device.""" @@ -144,7 +144,7 @@ class OpenThermClimate(ClimateDevice): self._away_state_b = ( status.get(gw_vars.OTGW_GPIO_B_STATE) == self._away_mode_b ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def name(self): @@ -253,7 +253,7 @@ class OpenThermClimate(ClimateDevice): self._new_target_temperature = await self._gateway.gateway.set_target_temp( temp ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def supported_features(self): diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index 3739f77e69d..c82cf14228b 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -73,7 +73,7 @@ class OpenThermSensor(Entity): if isinstance(value, float): value = f"{value:2.1f}" self._value = value - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def name(self): diff --git a/homeassistant/components/otp/sensor.py b/homeassistant/components/otp/sensor.py index 3c4cd464d44..df5f6af1695 100644 --- a/homeassistant/components/otp/sensor.py +++ b/homeassistant/components/otp/sensor.py @@ -54,7 +54,7 @@ class TOTPSensor(Entity): @callback def _call_loop(self): self._state = self._otp.now() - self.async_schedule_update_ha_state() + self.async_write_ha_state() # Update must occur at even TIME_STEP, e.g. 12:00:00, 12:00:30, # 12:01:00, etc. in order to have synced time (see RFC6238) diff --git a/homeassistant/components/person/__init__.py b/homeassistant/components/person/__init__.py index 006929c7345..8399719e861 100644 --- a/homeassistant/components/person/__init__.py +++ b/homeassistant/components/person/__init__.py @@ -484,7 +484,7 @@ class Person(RestoreEntity): self._longitude = None self._gps_accuracy = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _parse_source_state(self, state): diff --git a/homeassistant/components/plant/__init__.py b/homeassistant/components/plant/__init__.py index 30542db5e23..c26c3f5e68a 100644 --- a/homeassistant/components/plant/__init__.py +++ b/homeassistant/components/plant/__init__.py @@ -255,7 +255,7 @@ class Plant(Entity): self._state = STATE_OK self._problems = PROBLEM_NONE _LOGGER.debug("New data processed") - self.async_schedule_update_ha_state() + self.async_write_ha_state() def _check_min(self, sensor_name, value, params): """If configured, check the value against the defined minimum value.""" @@ -322,7 +322,7 @@ class Plant(Entity): except ValueError: pass _LOGGER.debug("Initializing from database completed") - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def should_poll(self): diff --git a/homeassistant/components/point/alarm_control_panel.py b/homeassistant/components/point/alarm_control_panel.py index e86b3dd42e8..d84c408e43a 100644 --- a/homeassistant/components/point/alarm_control_panel.py +++ b/homeassistant/components/point/alarm_control_panel.py @@ -72,7 +72,7 @@ class MinutPointAlarmControl(AlarmControlPanel): _LOGGER.debug("Received webhook: %s", _type) self._home["alarm_status"] = _type self._changed_by = _changed_by - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def _home(self): diff --git a/homeassistant/components/point/binary_sensor.py b/homeassistant/components/point/binary_sensor.py index a08f7dbedc4..b417c128913 100644 --- a/homeassistant/components/point/binary_sensor.py +++ b/homeassistant/components/point/binary_sensor.py @@ -95,7 +95,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice): self._is_on = True else: self._is_on = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _webhook_event(self, data, webhook): @@ -111,7 +111,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice): self._is_on = True if _type == self._events[1]: self._is_on = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): diff --git a/homeassistant/components/point/sensor.py b/homeassistant/components/point/sensor.py index 324565aae50..70fe1ef0b6d 100644 --- a/homeassistant/components/point/sensor.py +++ b/homeassistant/components/point/sensor.py @@ -62,7 +62,7 @@ class MinutPointSensor(MinutPointEntity): self.device.sensor, self.device_class ) self._updated = parse_datetime(self.device.last_update) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def icon(self): diff --git a/homeassistant/components/push/camera.py b/homeassistant/components/push/camera.py index f78966253b7..31f2f88dac7 100644 --- a/homeassistant/components/push/camera.py +++ b/homeassistant/components/push/camera.py @@ -144,7 +144,7 @@ class PushCamera(Camera): self._state = STATE_IDLE self._expired_listener = None _LOGGER.debug("Reset state") - self.async_schedule_update_ha_state() + self.async_write_ha_state() if self._expired_listener: self._expired_listener() @@ -153,7 +153,7 @@ class PushCamera(Camera): self.hass, reset_state, dt_util.utcnow() + self._timeout ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_camera_image(self): """Return a still image response.""" diff --git a/homeassistant/components/qwikswitch/__init__.py b/homeassistant/components/qwikswitch/__init__.py index 33392c51be8..c2d938f6ed7 100644 --- a/homeassistant/components/qwikswitch/__init__.py +++ b/homeassistant/components/qwikswitch/__init__.py @@ -87,7 +87,7 @@ class QSEntity(Entity): @callback def update_packet(self, packet): """Receive update packet from QSUSB. Match dispather_send signature.""" - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Listen for updates from QSUSb via dispatcher.""" diff --git a/homeassistant/components/qwikswitch/binary_sensor.py b/homeassistant/components/qwikswitch/binary_sensor.py index 054028b5629..b3635dcb1f4 100644 --- a/homeassistant/components/qwikswitch/binary_sensor.py +++ b/homeassistant/components/qwikswitch/binary_sensor.py @@ -52,7 +52,7 @@ class QSBinarySensor(QSEntity, BinarySensorDevice): ) if val is not None: self._val = bool(val) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): diff --git a/homeassistant/components/qwikswitch/sensor.py b/homeassistant/components/qwikswitch/sensor.py index 4674da420b2..9609af42f65 100644 --- a/homeassistant/components/qwikswitch/sensor.py +++ b/homeassistant/components/qwikswitch/sensor.py @@ -51,7 +51,7 @@ class QSSensor(QSEntity): ) if val is not None: self._val = val - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def state(self): diff --git a/homeassistant/components/rflink/__init__.py b/homeassistant/components/rflink/__init__.py index b8665fae9ef..9ba008a56ef 100644 --- a/homeassistant/components/rflink/__init__.py +++ b/homeassistant/components/rflink/__init__.py @@ -313,7 +313,7 @@ class RflinkDevice(Entity): self._handle_event(event) # Propagate changes through ha - self.async_schedule_update_ha_state() + self.async_write_ha_state() # Put command onto bus for user to subscribe to if self._should_fire_event and identify_event_type(event) == EVENT_KEY_COMMAND: @@ -360,7 +360,7 @@ class RflinkDevice(Entity): def _availability_callback(self, availability): """Update availability state.""" self._available = availability - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Register update callback.""" diff --git a/homeassistant/components/rflink/binary_sensor.py b/homeassistant/components/rflink/binary_sensor.py index 148a7db2b64..ab50e6dcc4b 100644 --- a/homeassistant/components/rflink/binary_sensor.py +++ b/homeassistant/components/rflink/binary_sensor.py @@ -84,7 +84,7 @@ class RflinkBinarySensor(RflinkDevice, BinarySensorDevice): """Switch device off after a delay.""" self._delay_listener = None self._state = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() if self._delay_listener is not None: self._delay_listener() diff --git a/homeassistant/components/ring/light.py b/homeassistant/components/ring/light.py index fa47ac35ee3..3340e0ad603 100644 --- a/homeassistant/components/ring/light.py +++ b/homeassistant/components/ring/light.py @@ -82,7 +82,7 @@ class RingLight(RingEntityMixin, Light): self._light_on = new_state == ON_STATE self._no_updates_until = dt_util.utcnow() + SKIP_UPDATES_DELAY - self.async_schedule_update_ha_state() + self.async_write_ha_state() def turn_on(self, **kwargs): """Turn the light on for 30 seconds.""" diff --git a/homeassistant/components/satel_integra/alarm_control_panel.py b/homeassistant/components/satel_integra/alarm_control_panel.py index d4294788fdd..6034c24e31a 100644 --- a/homeassistant/components/satel_integra/alarm_control_panel.py +++ b/homeassistant/components/satel_integra/alarm_control_panel.py @@ -78,7 +78,7 @@ class SatelIntegraAlarmPanel(alarm.AlarmControlPanel): _LOGGER.debug("Got status update, current status: %s", state) if state != self._state: self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() else: _LOGGER.debug("Ignoring alarm status message, same state") diff --git a/homeassistant/components/satel_integra/binary_sensor.py b/homeassistant/components/satel_integra/binary_sensor.py index cbe760c06bf..5b268266dda 100644 --- a/homeassistant/components/satel_integra/binary_sensor.py +++ b/homeassistant/components/satel_integra/binary_sensor.py @@ -110,4 +110,4 @@ class SatelIntegraBinarySensor(BinarySensorDevice): """Update the zone's state, if needed.""" if self._device_number in zones and self._state != zones[self._device_number]: self._state = zones[self._device_number] - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/satel_integra/switch.py b/homeassistant/components/satel_integra/switch.py index 9233b3d152d..46f4de2784f 100644 --- a/homeassistant/components/satel_integra/switch.py +++ b/homeassistant/components/satel_integra/switch.py @@ -65,13 +65,13 @@ class SatelIntegraSwitch(SwitchDevice): _LOGGER.debug("New state: %s", new_state) if new_state != self._state: self._state = new_state - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self, **kwargs): """Turn the device on.""" _LOGGER.debug("Switch: %s status: %s, turning on", self._name, self._state) await self._satel.set_output(self._code, self._device_number, True) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn the device off.""" @@ -79,7 +79,7 @@ class SatelIntegraSwitch(SwitchDevice): "Switch name: %s status: %s, turning off", self._name, self._state ) await self._satel.set_output(self._code, self._device_number, False) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self): diff --git a/homeassistant/components/serial/sensor.py b/homeassistant/components/serial/sensor.py index a08f9522c4b..bc9ef9f9e79 100644 --- a/homeassistant/components/serial/sensor.py +++ b/homeassistant/components/serial/sensor.py @@ -84,7 +84,7 @@ class SerialSensor(Entity): _LOGGER.debug("Received: %s", line) self._state = line - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def stop_serial_read(self): """Close resources.""" diff --git a/homeassistant/components/sisyphus/light.py b/homeassistant/components/sisyphus/light.py index 7c1b0ece4bf..271db41ac22 100644 --- a/homeassistant/components/sisyphus/light.py +++ b/homeassistant/components/sisyphus/light.py @@ -36,7 +36,7 @@ class SisyphusLight(Light): async def async_added_to_hass(self): """Add listeners after this object has been initialized.""" - self._table.add_listener(lambda: self.async_schedule_update_ha_state(False)) + self._table.add_listener(self.async_write_ha_state) @property def available(self): diff --git a/homeassistant/components/sisyphus/media_player.py b/homeassistant/components/sisyphus/media_player.py index e708504ff7e..103ec694d83 100644 --- a/homeassistant/components/sisyphus/media_player.py +++ b/homeassistant/components/sisyphus/media_player.py @@ -67,7 +67,7 @@ class SisyphusPlayer(MediaPlayerDevice): async def async_added_to_hass(self): """Add listeners after this object has been initialized.""" - self._table.add_listener(lambda: self.async_schedule_update_ha_state(False)) + self._table.add_listener(self.async_write_ha_state) @property def unique_id(self): diff --git a/homeassistant/components/smartthings/climate.py b/homeassistant/components/smartthings/climate.py index 232540ee47b..83a1af981db 100644 --- a/homeassistant/components/smartthings/climate.py +++ b/homeassistant/components/smartthings/climate.py @@ -336,7 +336,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice): await self._device.set_fan_mode(fan_mode, set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_hvac_mode(self, hvac_mode): """Set new target operation mode.""" @@ -355,7 +355,7 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice): await asyncio.gather(*tasks) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_temperature(self, **kwargs): """Set new target temperature.""" @@ -376,21 +376,21 @@ class SmartThingsAirConditioner(SmartThingsEntity, ClimateDevice): await asyncio.gather(*tasks) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self): """Turn device on.""" await self._device.switch_on(set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self): """Turn device off.""" await self._device.switch_off(set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the calculated fields of the AC.""" diff --git a/homeassistant/components/smartthings/fan.py b/homeassistant/components/smartthings/fan.py index aad62aed486..e366f6bb3e3 100644 --- a/homeassistant/components/smartthings/fan.py +++ b/homeassistant/components/smartthings/fan.py @@ -48,7 +48,7 @@ class SmartThingsFan(SmartThingsEntity, FanEntity): await self._device.set_fan_speed(value, set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self, speed: str = None, **kwargs) -> None: """Turn the fan on.""" @@ -59,14 +59,14 @@ class SmartThingsFan(SmartThingsEntity, FanEntity): await self._device.switch_on(set_status=True) # State is set optimistically in the commands above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs) -> None: """Turn the fan off.""" await self._device.switch_off(set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_on(self) -> bool: diff --git a/homeassistant/components/smartthings/lock.py b/homeassistant/components/smartthings/lock.py index 2895bde0bf7..d249cc5ac94 100644 --- a/homeassistant/components/smartthings/lock.py +++ b/homeassistant/components/smartthings/lock.py @@ -44,12 +44,12 @@ class SmartThingsLock(SmartThingsEntity, LockDevice): async def async_lock(self, **kwargs): """Lock the device.""" await self._device.lock(set_status=True) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_unlock(self, **kwargs): """Unlock the device.""" await self._device.unlock(set_status=True) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_locked(self): diff --git a/homeassistant/components/smartthings/switch.py b/homeassistant/components/smartthings/switch.py index ace47a56d2c..eb9c9c90c4b 100644 --- a/homeassistant/components/smartthings/switch.py +++ b/homeassistant/components/smartthings/switch.py @@ -37,14 +37,14 @@ class SmartThingsSwitch(SmartThingsEntity, SwitchDevice): await self._device.switch_off(set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self, **kwargs) -> None: """Turn the switch on.""" await self._device.switch_on(set_status=True) # State is set optimistically in the command above, therefore update # the entity state ahead of receiving the confirming push updates - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def current_power_w(self): diff --git a/homeassistant/components/snapcast/media_player.py b/homeassistant/components/snapcast/media_player.py index c3c9138eb89..004dd36ed4a 100644 --- a/homeassistant/components/snapcast/media_player.py +++ b/homeassistant/components/snapcast/media_player.py @@ -176,17 +176,17 @@ class SnapcastGroupDevice(MediaPlayerDevice): streams = self._group.streams_by_name() if source in streams: await self._group.set_stream(streams[source].identifier) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_mute_volume(self, mute): """Send the mute command.""" await self._group.set_muted(mute) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_volume_level(self, volume): """Set the volume level.""" await self._group.set_volume(round(volume * 100)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() def snapshot(self): """Snapshot the group state.""" @@ -273,17 +273,17 @@ class SnapcastClientDevice(MediaPlayerDevice): streams = self._client.group.streams_by_name() if source in streams: await self._client.group.set_stream(streams[source].identifier) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_mute_volume(self, mute): """Send the mute command.""" await self._client.set_muted(mute) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_volume_level(self, volume): """Set the volume level.""" await self._client.set_volume(round(volume * 100)) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_join(self, master): """Join the group of the master player.""" @@ -293,12 +293,12 @@ class SnapcastClientDevice(MediaPlayerDevice): if master.identifier in group.clients ] await master_group[0].add_client(self._client.identifier) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_unjoin(self): """Unjoin the group the player is currently in.""" await self._client.group.remove_client(self._client.identifier) - self.async_schedule_update_ha_state() + self.async_write_ha_state() def snapshot(self): """Snapshot the client state.""" diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index bb1179bb1e7..d54e6dd968f 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -464,7 +464,7 @@ class SonosEntity(MediaPlayerDevice): self._seen_timer() self.async_unseen() - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def async_unseen(self, now=None): @@ -483,7 +483,7 @@ class SonosEntity(MediaPlayerDevice): self._subscriptions = [] - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def available(self) -> bool: @@ -725,7 +725,7 @@ class SonosEntity(MediaPlayerDevice): self._coordinator = None self._sonos_group = sonos_group - self.async_schedule_update_ha_state() + self.async_write_ha_state() for slave_uid in group[1:]: slave = _get_entity_from_soco_uid(self.hass, slave_uid) diff --git a/homeassistant/components/switcher_kis/switch.py b/homeassistant/components/switcher_kis/switch.py index 8c9c9e1a6fa..4ace2c6eea1 100644 --- a/homeassistant/components/switcher_kis/switch.py +++ b/homeassistant/components/switcher_kis/switch.py @@ -121,7 +121,7 @@ class SwitcherControl(SwitchDevice): else: self._device_data = device_data self._state = self._device_data.state - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_on(self, **kwargs: Dict) -> None: """Turn the entity on.""" @@ -149,4 +149,4 @@ class SwitcherControl(SwitchDevice): if response and response.successful: self._self_initiated = True self._state = SWITCHER_STATE_ON if send_on else SWITCHER_STATE_OFF - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/tellduslive/entry.py b/homeassistant/components/tellduslive/entry.py index 50a219bf7a1..851823385dc 100644 --- a/homeassistant/components/tellduslive/entry.py +++ b/homeassistant/components/tellduslive/entry.py @@ -43,7 +43,7 @@ class TelldusLiveEntity(Entity): """Return the property of the device might have changed.""" if self.device.name: self._name = self.device.name - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def device_id(self): diff --git a/homeassistant/components/template/alarm_control_panel.py b/homeassistant/components/template/alarm_control_panel.py index 45cccef9766..937119ff6d4 100644 --- a/homeassistant/components/template/alarm_control_panel.py +++ b/homeassistant/components/template/alarm_control_panel.py @@ -236,7 +236,7 @@ class AlarmControlPanelTemplate(AlarmControlPanel): _LOGGER.error("No script action defined for %s", state) if optimistic_set: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_alarm_arm_away(self, code=None): """Arm the panel to Away.""" diff --git a/homeassistant/components/template/binary_sensor.py b/homeassistant/components/template/binary_sensor.py index 8991ce4c65b..df918d3dd77 100644 --- a/homeassistant/components/template/binary_sensor.py +++ b/homeassistant/components/template/binary_sensor.py @@ -283,7 +283,7 @@ class BinarySensorTemplate(BinarySensorDevice): def set_state(): """Set state of template binary sensor.""" self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() # state without delay if (state and not self._delay_on) or (not state and not self._delay_off): diff --git a/homeassistant/components/template/cover.py b/homeassistant/components/template/cover.py index 14fc6996378..3e3232f2b91 100644 --- a/homeassistant/components/template/cover.py +++ b/homeassistant/components/template/cover.py @@ -322,7 +322,7 @@ class CoverTemplate(CoverDevice): ) if self._optimistic: self._position = 100 - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_close_cover(self, **kwargs): """Move the cover down.""" @@ -334,7 +334,7 @@ class CoverTemplate(CoverDevice): ) if self._optimistic: self._position = 0 - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_stop_cover(self, **kwargs): """Fire the stop action.""" @@ -348,7 +348,7 @@ class CoverTemplate(CoverDevice): {"position": self._position}, context=self._context ) if self._optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_open_cover_tilt(self, **kwargs): """Tilt the cover open.""" @@ -357,7 +357,7 @@ class CoverTemplate(CoverDevice): {"tilt": self._tilt_value}, context=self._context ) if self._tilt_optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_close_cover_tilt(self, **kwargs): """Tilt the cover closed.""" @@ -366,7 +366,7 @@ class CoverTemplate(CoverDevice): {"tilt": self._tilt_value}, context=self._context ) if self._tilt_optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_set_cover_tilt_position(self, **kwargs): """Move the cover tilt to a specific position.""" @@ -375,7 +375,7 @@ class CoverTemplate(CoverDevice): {"tilt": self._tilt_value}, context=self._context ) if self._tilt_optimistic: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update the state from the template.""" diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index 7948782479b..52560ea2732 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -316,14 +316,14 @@ class LightTemplate(Light): await self._on_script.async_run() if optimistic_set: - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_turn_off(self, **kwargs): """Turn the light off.""" await self._off_script.async_run(context=self._context) if self._template is None: self._state = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_update(self): """Update from templates.""" diff --git a/homeassistant/components/template/lock.py b/homeassistant/components/template/lock.py index f4a6b55dd18..a5caac00123 100644 --- a/homeassistant/components/template/lock.py +++ b/homeassistant/components/template/lock.py @@ -174,12 +174,12 @@ class TemplateLock(LockDevice): """Lock the device.""" if self._optimistic: self._state = True - self.async_schedule_update_ha_state() + self.async_write_ha_state() await self._command_lock.async_run(context=self._context) async def async_unlock(self, **kwargs): """Unlock the device.""" if self._optimistic: self._state = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() await self._command_unlock.async_run(context=self._context) diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py index a5a7f320d93..9e95f3cc05b 100644 --- a/homeassistant/components/tibber/sensor.py +++ b/homeassistant/components/tibber/sensor.py @@ -169,7 +169,7 @@ class TibberSensorRT(TibberSensor): continue self._device_state_attributes[key] = value - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def available(self): diff --git a/homeassistant/components/time_date/sensor.py b/homeassistant/components/time_date/sensor.py index 1deb564133e..6081f1dfca6 100644 --- a/homeassistant/components/time_date/sensor.py +++ b/homeassistant/components/time_date/sensor.py @@ -136,7 +136,7 @@ class TimeDateSensor(Entity): def point_in_time_listener(self, time_date): """Get the latest data and update state.""" self._update_internal_state(time_date) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async_track_point_in_utc_time( self.hass, self.point_in_time_listener, self.get_next_interval() ) diff --git a/homeassistant/components/tod/binary_sensor.py b/homeassistant/components/tod/binary_sensor.py index 72507b3d148..ee9969c9974 100644 --- a/homeassistant/components/tod/binary_sensor.py +++ b/homeassistant/components/tod/binary_sensor.py @@ -234,7 +234,7 @@ class TodSensor(BinarySensorDevice): def _point_in_time_listener(self, now): """Run when the state of the sensor should be updated.""" self._calculate_next_update() - self.async_schedule_update_ha_state() + self.async_write_ha_state() async_track_point_in_utc_time( self.hass, self._point_in_time_listener, self.next_update diff --git a/homeassistant/components/torque/sensor.py b/homeassistant/components/torque/sensor.py index f084c135e47..dbb650a8b48 100644 --- a/homeassistant/components/torque/sensor.py +++ b/homeassistant/components/torque/sensor.py @@ -143,4 +143,4 @@ class TorqueSensor(Entity): def async_on_update(self, value): """Receive an update.""" self._state = value - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/tradfri/base_class.py b/homeassistant/components/tradfri/base_class.py index 358056d7ef6..0850bec6c9b 100644 --- a/homeassistant/components/tradfri/base_class.py +++ b/homeassistant/components/tradfri/base_class.py @@ -33,7 +33,7 @@ class TradfriBaseClass(Entity): def _async_start_observe(self, exc=None): """Start observation of device.""" if exc: - self.async_schedule_update_ha_state() + self.async_write_ha_state() _LOGGER.warning("Observation failed for %s", self._name, exc_info=exc) try: @@ -70,7 +70,7 @@ class TradfriBaseClass(Entity): def _observe_update(self, device): """Receive new state data for this device.""" self._refresh(device) - self.async_schedule_update_ha_state() + self.async_write_ha_state() def _refresh(self, device): """Refresh the device data.""" diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index 07e96a45fce..43494ec485f 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -217,7 +217,7 @@ class UniFiClientTracker(UniFiClient, ScannerEntity): """Scheduled callback for update.""" self.is_disconnected = True self.cancel_scheduled_update = None - self.async_schedule_update_ha_state() + self.async_write_ha_state() if ( not self.is_wired @@ -323,7 +323,7 @@ class UniFiDeviceTracker(ScannerEntity): """Update the sensor's state.""" LOGGER.debug("Updating UniFi tracked device %s", self.entity_id) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def is_connected(self): diff --git a/homeassistant/components/unifi/unifi_client.py b/homeassistant/components/unifi/unifi_client.py index b46771e574b..5efb73c2a01 100644 --- a/homeassistant/components/unifi/unifi_client.py +++ b/homeassistant/components/unifi/unifi_client.py @@ -79,7 +79,7 @@ class UniFiClient(Entity): self.is_blocked = self.client.event.event in CLIENT_BLOCKED LOGGER.debug("Updating client %s %s", self.entity_id, self.client.mac) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def name(self) -> str: diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index ad82cd9e79f..ad1b27f1fe0 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -163,7 +163,7 @@ class UtilityMeterSensor(RestoreEntity): _LOGGER.warning( "Invalid state (%s > %s): %s", old_state.state, new_state.state, err ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def async_tariff_change(self, entity, old_state, new_state): @@ -184,7 +184,7 @@ class UtilityMeterSensor(RestoreEntity): self._sensor_source_id, ) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def _async_reset_meter(self, event): """Determine cycle - Helper function for larger than daily cycles.""" diff --git a/homeassistant/components/w800rf32/binary_sensor.py b/homeassistant/components/w800rf32/binary_sensor.py index 9c83dbce804..16239e0c98c 100644 --- a/homeassistant/components/w800rf32/binary_sensor.py +++ b/homeassistant/components/w800rf32/binary_sensor.py @@ -130,7 +130,7 @@ class W800rf32BinarySensor(BinarySensorDevice): def update_state(self, state): """Update the state of the device.""" self._state = state - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Register update callback.""" diff --git a/homeassistant/components/waterfurnace/sensor.py b/homeassistant/components/waterfurnace/sensor.py index e2c92d07f9c..14f3549b2a3 100644 --- a/homeassistant/components/waterfurnace/sensor.py +++ b/homeassistant/components/waterfurnace/sensor.py @@ -114,4 +114,4 @@ class WaterFurnaceSensor(Entity): """Update state.""" if self.client.data is not None: self._state = getattr(self.client.data, self._attr, None) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index f4d9f97fe42..87f55fd6b2d 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -153,7 +153,7 @@ class LgWebOSMediaPlayerEntity(MediaPlayerDevice): """Update state from WebOsClient.""" self.update_sources() - self.async_schedule_update_ha_state(False) + self.async_write_ha_state() def update_sources(self): """Update list of sources from current source, apps, inputs and configured list.""" diff --git a/homeassistant/components/websocket_api/sensor.py b/homeassistant/components/websocket_api/sensor.py index 4ae39787335..a74381b8a85 100644 --- a/homeassistant/components/websocket_api/sensor.py +++ b/homeassistant/components/websocket_api/sensor.py @@ -54,4 +54,4 @@ class APICount(Entity): @callback def _update_count(self): self.count = self.hass.data.get(DATA_CONNECTIONS, 0) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/wemo/binary_sensor.py b/homeassistant/components/wemo/binary_sensor.py index db1ba60364e..0ca1f950448 100644 --- a/homeassistant/components/wemo/binary_sensor.py +++ b/homeassistant/components/wemo/binary_sensor.py @@ -55,7 +55,7 @@ class WemoBinarySensor(BinarySensorDevice): return await self._async_locked_update(force_update) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Wemo sensor added to Home Assistant.""" diff --git a/homeassistant/components/wemo/fan.py b/homeassistant/components/wemo/fan.py index cec481a2eb4..24ed68c792d 100644 --- a/homeassistant/components/wemo/fan.py +++ b/homeassistant/components/wemo/fan.py @@ -172,7 +172,7 @@ class WemoHumidifier(FanEntity): return await self._async_locked_update(force_update) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def unique_id(self): diff --git a/homeassistant/components/wemo/light.py b/homeassistant/components/wemo/light.py index 5988019e66f..b8c05ead076 100644 --- a/homeassistant/components/wemo/light.py +++ b/homeassistant/components/wemo/light.py @@ -236,7 +236,7 @@ class WemoDimmer(Light): return await self._async_locked_update(force_update) - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Wemo dimmer added to Home Assistant.""" diff --git a/homeassistant/components/wemo/switch.py b/homeassistant/components/wemo/switch.py index ad8ea45ffd6..4b6d99da200 100644 --- a/homeassistant/components/wemo/switch.py +++ b/homeassistant/components/wemo/switch.py @@ -77,7 +77,7 @@ class WemoSwitch(SwitchDevice): return await self._async_locked_update(force_update) - self.async_schedule_update_ha_state() + self.async_write_ha_state() @property def unique_id(self): diff --git a/homeassistant/components/wirelesstag/binary_sensor.py b/homeassistant/components/wirelesstag/binary_sensor.py index 4fcebe73478..07acf6057a1 100644 --- a/homeassistant/components/wirelesstag/binary_sensor.py +++ b/homeassistant/components/wirelesstag/binary_sensor.py @@ -140,4 +140,4 @@ class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorDevice): """Update state from arrived push notification.""" # state should be 'on' or 'off' self._state = event.data.get("state") - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/wirelesstag/sensor.py b/homeassistant/components/wirelesstag/sensor.py index fa72ab184e1..7a41d237781 100644 --- a/homeassistant/components/wirelesstag/sensor.py +++ b/homeassistant/components/wirelesstag/sensor.py @@ -111,4 +111,4 @@ class WirelessTagSensor(WirelessTagBaseSensor): _LOGGER.debug("Entity to update state: %s event data: %s", self, event.data) new_value = self._sensor.value_from_update_event(event.data) self._state = self.decorate_value(new_value) - self.async_schedule_update_ha_state() + self.async_write_ha_state() diff --git a/homeassistant/components/xiaomi_aqara/__init__.py b/homeassistant/components/xiaomi_aqara/__init__.py index ae032a8b35f..533238ac5e7 100644 --- a/homeassistant/components/xiaomi_aqara/__init__.py +++ b/homeassistant/components/xiaomi_aqara/__init__.py @@ -286,7 +286,7 @@ class XiaomiDevice(Entity): """Set state to UNAVAILABLE.""" self._remove_unavailability_tracker = None self._is_available = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() @callback def _async_track_unavailable(self): @@ -308,7 +308,7 @@ class XiaomiDevice(Entity): is_data = self.parse_data(data, raw_data) is_voltage = self.parse_voltage(data) if is_data or is_voltage or was_unavailable: - self.async_schedule_update_ha_state() + self.async_write_ha_state() def parse_voltage(self, data): """Parse battery level data sent by gateway.""" diff --git a/homeassistant/components/xiaomi_aqara/binary_sensor.py b/homeassistant/components/xiaomi_aqara/binary_sensor.py index a7e49f681c4..2c95198f348 100644 --- a/homeassistant/components/xiaomi_aqara/binary_sensor.py +++ b/homeassistant/components/xiaomi_aqara/binary_sensor.py @@ -197,7 +197,7 @@ class XiaomiMotionSensor(XiaomiBinarySensor): """Set state to False.""" self._unsub_set_no_motion = None self._state = False - self.async_schedule_update_ha_state() + self.async_write_ha_state() def parse_data(self, data, raw_data): """Parse data sent by gateway. diff --git a/homeassistant/components/xiaomi_aqara/lock.py b/homeassistant/components/xiaomi_aqara/lock.py index befbfc001ba..ed71e05bf5f 100644 --- a/homeassistant/components/xiaomi_aqara/lock.py +++ b/homeassistant/components/xiaomi_aqara/lock.py @@ -63,7 +63,7 @@ class XiaomiAqaraLock(LockDevice, XiaomiDevice): def clear_unlock_state(self, _): """Clear unlock state automatically.""" self._state = STATE_LOCKED - self.async_schedule_update_ha_state() + self.async_write_ha_state() def parse_data(self, data, raw_data): """Parse data sent by gateway.""" diff --git a/homeassistant/components/yeelight/binary_sensor.py b/homeassistant/components/yeelight/binary_sensor.py index 29e24b510e5..3c06a75fb71 100644 --- a/homeassistant/components/yeelight/binary_sensor.py +++ b/homeassistant/components/yeelight/binary_sensor.py @@ -2,7 +2,6 @@ import logging from homeassistant.components.binary_sensor import BinarySensorDevice -from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from . import DATA_UPDATED, DATA_YEELIGHT @@ -28,19 +27,21 @@ class YeelightNightlightModeSensor(BinarySensorDevice): def __init__(self, device): """Initialize nightlight mode sensor.""" self._device = device - - @callback - def _schedule_immediate_update(self): - self.async_schedule_update_ha_state() + self._unsub_disp = None async def async_added_to_hass(self): """Handle entity which will be added.""" - async_dispatcher_connect( + self._unsub_disp = async_dispatcher_connect( self.hass, DATA_UPDATED.format(self._device.ipaddr), - self._schedule_immediate_update, + self.async_write_ha_state, ) + async def async_will_remove_from_hass(self): + """When entity will be removed from hass.""" + self._unsub_disp() + self._unsub_disp = None + @property def should_poll(self): """No polling needed.""" diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index 1491c10777f..57c4fbe6199 100644 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -1234,7 +1234,7 @@ class ZWaveDeviceEntity(ZWaveBaseEntity): ent_reg.async_update_entity(self.entity_id, new_entity_id=new_entity_id) return # else for the above two ifs, update if not using update_entity - self.async_schedule_update_ha_state() + self.async_write_ha_state() async def async_added_to_hass(self): """Add device to dict.""" diff --git a/homeassistant/components/zwave/node_entity.py b/homeassistant/components/zwave/node_entity.py index 3b94991312a..3fb5491ea62 100644 --- a/homeassistant/components/zwave/node_entity.py +++ b/homeassistant/components/zwave/node_entity.py @@ -273,7 +273,7 @@ class ZWaveNodeEntity(ZWaveBaseEntity): ent_reg.async_update_entity(self.entity_id, new_entity_id=new_entity_id) return # else for the above two ifs, update if not using update_entity - self.async_schedule_update_ha_state() + self.async_write_ha_state() def network_node_event(self, node, value): """Handle a node activated event on the network.""" diff --git a/tests/components/arcam_fmj/conftest.py b/tests/components/arcam_fmj/conftest.py index 6611cbaf9eb..ec9c6bb1f36 100644 --- a/tests/components/arcam_fmj/conftest.py +++ b/tests/components/arcam_fmj/conftest.py @@ -55,5 +55,5 @@ def player_fixture(hass, state): player = ArcamFmj(state, MOCK_NAME, None) player.entity_id = MOCK_ENTITY_ID player.hass = hass - player.async_schedule_update_ha_state = Mock() + player.async_write_ha_state = Mock() return player diff --git a/tests/components/arcam_fmj/test_media_player.py b/tests/components/arcam_fmj/test_media_player.py index 2ff31a8fd4f..a6b36a71d1c 100644 --- a/tests/components/arcam_fmj/test_media_player.py +++ b/tests/components/arcam_fmj/test_media_player.py @@ -126,7 +126,7 @@ async def test_mute_volume(player, state, mute): """Test mute functionality.""" await player.async_mute_volume(mute) state.set_mute.assert_called_with(mute) - player.async_schedule_update_ha_state.assert_called_with() + player.async_write_ha_state.assert_called_with() async def test_name(player): @@ -203,14 +203,14 @@ async def test_volume_up(player, state): """Test mute functionality.""" await player.async_volume_up() state.inc_volume.assert_called_with() - player.async_schedule_update_ha_state.assert_called_with() + player.async_write_ha_state.assert_called_with() async def test_volume_down(player, state): """Test mute functionality.""" await player.async_volume_down() state.dec_volume.assert_called_with() - player.async_schedule_update_ha_state.assert_called_with() + player.async_write_ha_state.assert_called_with() @pytest.mark.parametrize( diff --git a/tests/components/default_config/test_init.py b/tests/components/default_config/test_init.py index 6b9004595bb..2ec3467e0db 100644 --- a/tests/components/default_config/test_init.py +++ b/tests/components/default_config/test_init.py @@ -5,25 +5,6 @@ import pytest from homeassistant.setup import async_setup_component -from tests.common import MockDependency, mock_coro - - -@pytest.fixture(autouse=True) -def zeroconf_mock(): - """Mock zeroconf.""" - with MockDependency("zeroconf") as mocked_zeroconf: - mocked_zeroconf.Zeroconf.return_value.register_service.return_value = mock_coro( - True - ) - yield - - -@pytest.fixture(autouse=True) -def netdisco_mock(): - """Mock netdisco.""" - with MockDependency("netdisco", "discovery"): - yield - @pytest.fixture(autouse=True) def recorder_url_mock(): diff --git a/tests/components/owntracks/test_config_flow.py b/tests/components/owntracks/test_config_flow.py index 21bb5bcf993..ae999afe305 100644 --- a/tests/components/owntracks/test_config_flow.py +++ b/tests/components/owntracks/test_config_flow.py @@ -16,7 +16,7 @@ CONF_WEBHOOK_URL = "webhook_url" BASE_URL = "http://example.com" CLOUDHOOK = False -SECRET = "secret" +SECRET = "test-secret" WEBHOOK_ID = "webhook_id" WEBHOOK_URL = f"{BASE_URL}/api/webhook/webhook_id" @@ -33,7 +33,7 @@ def mock_webhook_id(): @pytest.fixture(name="secret") def mock_secret(): """Mock secret.""" - with patch("binascii.hexlify", return_value=str.encode(SECRET)): + with patch("secrets.token_hex", return_value=SECRET): yield