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