Unsub dispatcher when removing entity from hass (#33510)
* Unsub dispatcher when removing entity from hass * Update homeassistant/components/plaato/sensor.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/volvooncall/__init__.py Co-Authored-By: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
314bc07cee
commit
4ebbabcdd1
71 changed files with 355 additions and 209 deletions
|
@ -48,7 +48,7 @@ class AbodeCamera(AbodeDevice, Camera):
|
|||
)
|
||||
|
||||
signal = f"abode_camera_capture_{self.entity_id}"
|
||||
async_dispatcher_connect(self.hass, signal, self.capture)
|
||||
self.async_on_remove(async_dispatcher_connect(self.hass, signal, self.capture))
|
||||
|
||||
def capture(self):
|
||||
"""Request a new image capture."""
|
||||
|
|
|
@ -53,7 +53,7 @@ class AbodeAutomationSwitch(AbodeAutomation, SwitchDevice):
|
|||
await super().async_added_to_hass()
|
||||
|
||||
signal = f"abode_trigger_automation_{self.entity_id}"
|
||||
async_dispatcher_connect(self.hass, signal, self.trigger)
|
||||
self.async_on_remove(async_dispatcher_connect(self.hass, signal, self.trigger))
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Enable the automation."""
|
||||
|
|
|
@ -145,9 +145,11 @@ class AfterShipSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, self._force_update
|
||||
)
|
||||
)
|
||||
|
||||
async def _force_update(self):
|
||||
"""Force update of data."""
|
||||
|
|
|
@ -96,9 +96,11 @@ class AlarmDecoderAlarmPanel(AlarmControlPanel):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_PANEL_MESSAGE, self._message_callback
|
||||
)
|
||||
)
|
||||
|
||||
def _message_callback(self, message):
|
||||
"""Handle received messages."""
|
||||
|
|
|
@ -79,21 +79,29 @@ class AlarmDecoderBinarySensor(BinarySensorDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_ZONE_FAULT, self._fault_callback
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_ZONE_RESTORE, self._restore_callback
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_RFX_MESSAGE, self._rfx_message_callback
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_REL_MESSAGE, self._rel_message_callback
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -29,9 +29,11 @@ class AlarmDecoderSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_PANEL_MESSAGE, self._message_callback
|
||||
)
|
||||
)
|
||||
|
||||
def _message_callback(self, message):
|
||||
if self._display != message.text:
|
||||
|
|
|
@ -309,7 +309,9 @@ class AndroidIPCamEntity(Entity):
|
|||
return
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_DATA, async_ipcam_update)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
|
@ -99,9 +99,11 @@ class AquaLogicSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, self.async_update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_callback(self):
|
||||
|
|
|
@ -64,7 +64,6 @@ class AquaLogicSwitch(SwitchDevice):
|
|||
"aux_6": States.AUX_6,
|
||||
"aux_7": States.AUX_7,
|
||||
}[switch_type]
|
||||
self._unsub_disp = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
@ -101,11 +100,8 @@ class AquaLogicSwitch(SwitchDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self._unsub_disp = self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, 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
|
||||
)
|
||||
|
|
|
@ -142,15 +142,23 @@ class ArcamFmj(MediaPlayerDevice):
|
|||
if host == self._state.client.host:
|
||||
self.async_schedule_update_ha_state(force_refresh=True)
|
||||
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_CLIENT_DATA, _data)
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_CLIENT_DATA, _data
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_CLIENT_STARTED, _started
|
||||
)
|
||||
)
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_CLIENT_STOPPED, _stopped
|
||||
)
|
||||
)
|
||||
|
||||
async def async_update(self):
|
||||
"""Force update of state."""
|
||||
|
|
|
@ -84,7 +84,11 @@ class ArloBaseStation(AlarmControlPanel):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_ARLO, self._update_callback)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -61,7 +61,6 @@ 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,14 +68,11 @@ class ArloCam(Camera):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self._unsub_disp = async_dispatcher_connect(
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_ARLO, 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
|
||||
)
|
||||
|
||||
async def handle_async_mjpeg_stream(self, request):
|
||||
"""Generate an HTTP MJPEG stream from the camera."""
|
||||
|
|
|
@ -92,7 +92,11 @@ class ArloSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_ARLO, self._update_callback)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -13,21 +13,15 @@ class AxisEntityBase(Entity):
|
|||
def __init__(self, device):
|
||||
"""Initialize the Axis event."""
|
||||
self.device = device
|
||||
self.unsub_dispatcher = []
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe device events."""
|
||||
self.unsub_dispatcher.append(
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self.device.event_reachable, self.update_callback
|
||||
)
|
||||
)
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
"""Unsubscribe device events when removed."""
|
||||
for unsub_dispatcher in self.unsub_dispatcher:
|
||||
unsub_dispatcher()
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if device is available."""
|
||||
|
|
|
@ -57,7 +57,7 @@ class AxisCamera(AxisEntityBase, MjpegCamera):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe camera events."""
|
||||
self.unsub_dispatcher.append(
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self.device.event_new_address, self._new_address
|
||||
)
|
||||
|
|
|
@ -44,11 +44,13 @@ class ComfoConnectFan(FanEntity):
|
|||
async def async_added_to_hass(self):
|
||||
"""Register for sensor updates."""
|
||||
_LOGGER.debug("Registering for fan speed")
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(SENSOR_FAN_SPEED_MODE),
|
||||
self._handle_update,
|
||||
)
|
||||
)
|
||||
await self.hass.async_add_executor_job(
|
||||
self._ccb.comfoconnect.register_sensor, SENSOR_FAN_SPEED_MODE
|
||||
)
|
||||
|
|
|
@ -234,11 +234,13 @@ class ComfoConnectSensor(Entity):
|
|||
_LOGGER.debug(
|
||||
"Registering for sensor %s (%d)", self._sensor_type, self._sensor_id
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(self._sensor_id),
|
||||
self._handle_update,
|
||||
)
|
||||
)
|
||||
await self.hass.async_add_executor_job(
|
||||
self._ccb.comfoconnect.register_sensor, self._sensor_id
|
||||
)
|
||||
|
|
|
@ -197,7 +197,9 @@ class DenonDevice(MediaPlayerDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register signal handler."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, DOMAIN, self.signal_handler)
|
||||
)
|
||||
|
||||
def signal_handler(self, data):
|
||||
"""Handle domain-specific signal by calling appropriate method."""
|
||||
|
|
|
@ -214,7 +214,11 @@ class EightSleepUserEntity(Entity):
|
|||
"""Update callback."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_USER, async_eight_user_update)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_USER, async_eight_user_update
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
@ -237,7 +241,11 @@ class EightSleepHeatEntity(Entity):
|
|||
"""Update callback."""
|
||||
self.async_schedule_update_ha_state(True)
|
||||
|
||||
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_HEAT, async_eight_heat_update)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_HEAT, async_eight_heat_update
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
|
@ -71,9 +71,11 @@ class EnOceanDevice(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_RECEIVE_MESSAGE, self._message_received_callback
|
||||
)
|
||||
)
|
||||
|
||||
def _message_received_callback(self, packet):
|
||||
"""Handle incoming packets."""
|
||||
|
|
|
@ -112,10 +112,16 @@ class EnvisalinkAlarm(EnvisalinkDevice, AlarmControlPanel):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
async_dispatcher_connect(self.hass, SIGNAL_KEYPAD_UPDATE, self._update_callback)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_KEYPAD_UPDATE, self._update_callback
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_PARTITION_UPDATE, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self, partition):
|
||||
|
|
|
@ -55,15 +55,18 @@ class SpeedtestSensor(RestoreEntity):
|
|||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
)
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
if not state:
|
||||
return
|
||||
self._state = state.state
|
||||
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and update the states."""
|
||||
data = self.speedtest_client.data
|
||||
|
|
|
@ -140,13 +140,21 @@ class FFmpegBase(Entity):
|
|||
|
||||
This method is a coroutine.
|
||||
"""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_FFMPEG_START, self._async_start_ffmpeg
|
||||
)
|
||||
async_dispatcher_connect(self.hass, SIGNAL_FFMPEG_STOP, self._async_stop_ffmpeg)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_FFMPEG_STOP, self._async_stop_ffmpeg
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_FFMPEG_RESTART, self._async_restart_ffmpeg
|
||||
)
|
||||
)
|
||||
|
||||
# register start/stop
|
||||
self._async_register_events()
|
||||
|
|
|
@ -204,7 +204,7 @@ class GeniusEntity(Entity):
|
|||
|
||||
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._refresh)
|
||||
self.async_on_remove(async_dispatcher_connect(self.hass, DOMAIN, self._refresh))
|
||||
|
||||
async def _refresh(self, payload: Optional[dict] = None) -> None:
|
||||
"""Process any signals."""
|
||||
|
|
|
@ -182,17 +182,11 @@ 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."""
|
||||
self._unsub_disp = async_dispatcher_connect(
|
||||
self.hass, DOMAIN, self.async_write_ha_state
|
||||
self.async_on_remove(
|
||||
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
|
||||
|
||||
async def async_will_remove_from_hass(self):
|
||||
"""When entity will be removed from hass."""
|
||||
self._unsub_disp()
|
||||
self._unsub_disp = None
|
||||
|
|
|
@ -164,8 +164,10 @@ class SW16Device(Entity):
|
|||
self.handle_event_callback, self._device_port
|
||||
)
|
||||
self._is_on = await self._client.status(self._device_port)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
f"hlk_sw16_device_available_{self._device_id}",
|
||||
self._availability_callback,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -42,7 +42,9 @@ class HomeworksLight(HomeworksDevice, Light):
|
|||
"""Call when entity is added to hass."""
|
||||
signal = f"homeworks_entity_{self._addr}"
|
||||
_LOGGER.debug("connecting %s", signal)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, signal, self._update_callback)
|
||||
)
|
||||
self._controller.request_dimmer_level(self._addr)
|
||||
|
||||
@property
|
||||
|
|
|
@ -127,9 +127,11 @@ class HydrawiseEntity(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_HYDRAWISE, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -202,19 +202,13 @@ 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."""
|
||||
self._unsub_disp = async_dispatcher_connect(
|
||||
self.hass, DOMAIN, self.async_write_ha_state
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, DOMAIN, 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) -> bool:
|
||||
"""Return False as entities shouldn't be polled.
|
||||
|
|
|
@ -83,7 +83,7 @@ class IncomfortChild(IncomfortEntity):
|
|||
|
||||
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._refresh)
|
||||
self.async_on_remove(async_dispatcher_connect(self.hass, DOMAIN, self._refresh))
|
||||
|
||||
@callback
|
||||
def _refresh(self) -> None:
|
||||
|
|
|
@ -93,9 +93,13 @@ class InsteonEntity(Entity):
|
|||
self._insteon_device_state.register_updates(self.async_entity_update)
|
||||
self.hass.data[DOMAIN][INSTEON_ENTITIES].add(self.entity_id)
|
||||
load_signal = f"{self.entity_id}_{SIGNAL_LOAD_ALDB}"
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, load_signal, self._load_aldb)
|
||||
)
|
||||
print_signal = f"{self.entity_id}_{SIGNAL_PRINT_ALDB}"
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, print_signal, self._print_aldb)
|
||||
)
|
||||
|
||||
def _load_aldb(self, reload=False):
|
||||
"""Load the device All-Link Database."""
|
||||
|
|
|
@ -73,15 +73,18 @@ class Iperf3Sensor(RestoreEntity):
|
|||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
)
|
||||
|
||||
state = await self.async_get_last_state()
|
||||
if not state:
|
||||
return
|
||||
self._state = state.state
|
||||
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and update the states."""
|
||||
data = self._iperf3_data.data.get(self._sensor_type)
|
||||
|
|
|
@ -113,6 +113,8 @@ class KaiterraAirQuality(AirQualityEntity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callback."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_KAITERRA, self.async_write_ha_state
|
||||
)
|
||||
)
|
||||
|
|
|
@ -88,6 +88,8 @@ class KaiterraSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callback."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_KAITERRA, self.async_write_ha_state
|
||||
)
|
||||
)
|
||||
|
|
|
@ -79,9 +79,11 @@ class KonnectedBinarySensor(BinarySensorDevice):
|
|||
async def async_added_to_hass(self):
|
||||
"""Store entity_id and register state change callback."""
|
||||
self._data[ATTR_ENTITY_ID] = self.entity_id
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, f"konnected.{self.entity_id}.update", self.async_set_state
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_set_state(self, state):
|
||||
|
|
|
@ -178,7 +178,11 @@ class MediaroomDevice(MediaPlayerDevice):
|
|||
self._available = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async_dispatcher_connect(self.hass, SIGNAL_STB_NOTIFY, async_notify_received)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_STB_NOTIFY, async_notify_received
|
||||
)
|
||||
)
|
||||
|
||||
async def async_play_media(self, media_type, media_id, **kwargs):
|
||||
"""Play media."""
|
||||
|
|
|
@ -64,9 +64,11 @@ class EVBinarySensor(BinarySensorDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, self.async_update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_callback(self):
|
||||
|
|
|
@ -58,11 +58,17 @@ class MyChevyStatus(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, self.success
|
||||
)
|
||||
)
|
||||
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(ERROR_TOPIC, self.error)
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
ERROR_TOPIC, self.error
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def success(self):
|
||||
|
|
|
@ -137,11 +137,15 @@ class MySensorsEntity(MySensorsDevice, Entity):
|
|||
"""Register update callback."""
|
||||
gateway_id = id(self.gateway)
|
||||
dev_id = gateway_id, self.node_id, self.child_id, self.value_type
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, CHILD_CALLBACK.format(*dev_id), self.async_update_callback
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
NODE_CALLBACK.format(gateway_id, self.node_id),
|
||||
self.async_update_callback,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -45,9 +45,11 @@ class NessAlarmPanel(alarm.AlarmControlPanel):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_ARMING_STATE_CHANGED, self._handle_arming_state_change
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -50,9 +50,11 @@ class NessZoneBinarySensor(BinarySensorDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_ZONE_CHANGED, self._handle_zone_change
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -437,4 +437,6 @@ class NestSensorDevice(Entity):
|
|||
"""Update sensor state."""
|
||||
await self.async_update_ha_state(True)
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, SIGNAL_NEST_UPDATE, async_update_state)
|
||||
)
|
||||
|
|
|
@ -151,7 +151,9 @@ class NestThermostat(ClimateDevice):
|
|||
"""Update device state."""
|
||||
await self.async_update_ha_state(True)
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, SIGNAL_NEST_UPDATE, async_update_state)
|
||||
)
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
|
|
|
@ -352,9 +352,11 @@ class LTEEntity(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callback."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_NETGEAR_LTE, self.async_write_ha_state
|
||||
)
|
||||
)
|
||||
|
||||
async def async_update(self):
|
||||
"""Force update of state."""
|
||||
|
|
|
@ -467,9 +467,11 @@ class LeafEntity(Entity):
|
|||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.log_registration()
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.car.hass, SIGNAL_UPDATE_LEAF, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -89,9 +89,11 @@ class NZBGetSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _schedule_immediate_update(self):
|
||||
|
|
|
@ -157,6 +157,8 @@ class PlaatoSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
f"{PLAATO_DOMAIN}_{self.unique_id}", self.async_schedule_update_ha_state
|
||||
f"{PLAATO_DOMAIN}_{self.unique_id}", self.async_write_ha_state
|
||||
)
|
||||
)
|
||||
|
|
|
@ -91,9 +91,11 @@ class QSEntity(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Listen for updates from QSUSb via dispatcher."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
self.qsid, self.update_packet
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class QSToggleEntity(QSEntity):
|
||||
|
|
|
@ -167,9 +167,11 @@ class RachioStandbySwitch(RachioSwitch):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_RACHIO_CONTROLLER_UPDATE, self._handle_any_update
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class RachioZone(RachioSwitch):
|
||||
|
|
|
@ -152,9 +152,11 @@ class RainCloudEntity(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_RAINCLOUD, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
def _update_callback(self):
|
||||
"""Call update method."""
|
||||
|
|
|
@ -102,7 +102,9 @@ class RepetierSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Connect update callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(self.hass, UPDATE_SIGNAL, self.update_callback)
|
||||
)
|
||||
|
||||
def _get_data(self):
|
||||
"""Return new data from the api cache."""
|
||||
|
|
|
@ -404,14 +404,18 @@ class RflinkDevice(Entity):
|
|||
self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND][_id].append(
|
||||
self.entity_id
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_AVAILABILITY, self._availability_callback
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_HANDLE_EVENT.format(self.entity_id),
|
||||
self.handle_event_callback,
|
||||
)
|
||||
)
|
||||
|
||||
# Process the initial event now that the entity is created
|
||||
if self._initial_event:
|
||||
|
|
|
@ -139,14 +139,18 @@ class RflinkSensor(RflinkDevice):
|
|||
self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][_id].append(
|
||||
self.entity_id
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_AVAILABILITY, self._availability_callback
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_HANDLE_EVENT.format(self.entity_id),
|
||||
self.handle_event_callback,
|
||||
)
|
||||
)
|
||||
|
||||
# Process the initial event now that the entity is created
|
||||
if self._initial_event:
|
||||
|
|
|
@ -37,7 +37,11 @@ class SabnzbdSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call when entity about to be added to hass."""
|
||||
async_dispatcher_connect(self.hass, SIGNAL_SABNZBD_UPDATED, self.update_state)
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_SABNZBD_UPDATED, self.update_state
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -67,9 +67,11 @@ class SatelIntegraAlarmPanel(alarm.AlarmControlPanel):
|
|||
"""Update alarm status and register callbacks for future updates."""
|
||||
_LOGGER.debug("Starts listening for panel messages")
|
||||
self._update_alarm_status()
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_PANEL_MESSAGE, self._update_alarm_status
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_alarm_status(self):
|
||||
|
|
|
@ -75,9 +75,11 @@ class SatelIntegraBinarySensor(BinarySensorDevice):
|
|||
self._state = 1
|
||||
else:
|
||||
self._state = 0
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, self._react_to_signal, self._devices_updated
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
|
|
|
@ -57,8 +57,12 @@ class SpcAlarm(alarm.AlarmControlPanel):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call for adding new entities."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_ALARM.format(self._area.id), self._update_callback
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_ALARM.format(self._area.id),
|
||||
self._update_callback,
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -46,8 +46,12 @@ class SpcBinarySensor(BinarySensorDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call for adding new entities."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_UPDATE_SENSOR.format(self._zone.id), self._update_callback
|
||||
self.hass,
|
||||
SIGNAL_UPDATE_SENSOR.format(self._zone.id),
|
||||
self._update_callback,
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
|
|
|
@ -91,9 +91,11 @@ class SpeedtestSensor(RestoreEntity):
|
|||
return
|
||||
self._state = state.state
|
||||
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, DATA_UPDATED, self._schedule_immediate_update
|
||||
)
|
||||
)
|
||||
|
||||
def update(self):
|
||||
"""Get the latest data and update the states."""
|
||||
|
|
|
@ -109,9 +109,11 @@ class SwitcherControl(SwitchDevice):
|
|||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Run when entity about to be added to hass."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_SWITCHER_DEVICE_UPDATE, self.async_update_data
|
||||
)
|
||||
)
|
||||
|
||||
async def async_update_data(self, device_data: "SwitcherV2Device") -> None:
|
||||
"""Update the entity data."""
|
||||
|
|
|
@ -182,9 +182,11 @@ class TellstickDevice(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_TELLCORE_CALLBACK, self.update_from_callback
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
|
@ -82,9 +82,11 @@ class UpnpSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to sensors events."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_REMOVE_SENSOR, self._upnp_remove_sensor
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _upnp_remove_sensor(self, device):
|
||||
|
|
|
@ -93,9 +93,11 @@ class ValloxFan(FanEntity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call to update."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_VALLOX_STATE_UPDATE, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -149,9 +149,11 @@ class ValloxSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call to update."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_VALLOX_STATE_UPDATE, self._update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def _update_callback(self):
|
||||
|
|
|
@ -230,8 +230,10 @@ class VolvoEntity(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register update dispatcher."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass, SIGNAL_STATE_UPDATED, self.async_schedule_update_ha_state
|
||||
self.hass, SIGNAL_STATE_UPDATED, self.async_write_ha_state
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -105,9 +105,11 @@ class WaterFurnaceSensor(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
UPDATE_TOPIC, self.async_update_callback
|
||||
)
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_update_callback(self):
|
||||
|
|
|
@ -28,12 +28,16 @@ class APICount(Entity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Added to hass."""
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_WEBSOCKET_CONNECTED, self._update_count
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_WEBSOCKET_DISCONNECTED, self._update_count
|
||||
)
|
||||
)
|
||||
self._update_count()
|
||||
|
||||
@property
|
||||
|
|
|
@ -102,11 +102,13 @@ class WirelessTagBinarySensor(WirelessTagBaseSensor, BinarySensorDevice):
|
|||
tag_id = self.tag_id
|
||||
event_type = self.device_class
|
||||
mac = self.tag_manager_mac
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_BINARY_EVENT_UPDATE.format(tag_id, event_type, mac),
|
||||
self._on_binary_event_callback,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
|
|
@ -64,11 +64,13 @@ class WirelessTagSensor(WirelessTagBaseSensor):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callbacks."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
SIGNAL_TAG_UPDATE.format(self.tag_id, self.tag_manager_mac),
|
||||
self._update_tag_info_callback,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def entity_id(self):
|
||||
|
|
|
@ -27,20 +27,16 @@ class YeelightNightlightModeSensor(BinarySensorDevice):
|
|||
def __init__(self, device):
|
||||
"""Initialize nightlight mode sensor."""
|
||||
self._device = device
|
||||
self._unsub_disp = None
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
self._unsub_disp = async_dispatcher_connect(
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
DATA_UPDATED.format(self._device.ipaddr),
|
||||
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):
|
||||
|
|
|
@ -456,11 +456,13 @@ class YeelightGenericLight(Light):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Handle entity which will be added."""
|
||||
self.async_on_remove(
|
||||
async_dispatcher_connect(
|
||||
self.hass,
|
||||
DATA_UPDATED.format(self._device.ipaddr),
|
||||
self._schedule_immediate_update,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue