Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/abode/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def async_added_to_hass(self):
)

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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/abode/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def async_added_to_hass(self):
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."""
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/aftership/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ def icon(self):

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self._force_update
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self._force_update
)
)

async def _force_update(self):
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/alarmdecoder/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ def __init__(self, auto_bypass, code_arm_required):

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_PANEL_MESSAGE, self._message_callback
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_PANEL_MESSAGE, self._message_callback
)
)

def _message_callback(self, message):
Expand Down
24 changes: 16 additions & 8 deletions homeassistant/components/alarmdecoder/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,28 @@ def __init__(

async def async_added_to_hass(self):
"""Register callbacks."""
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_FAULT, self._fault_callback
)
)

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_ZONE_RESTORE, self._restore_callback
)
)

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_RFX_MESSAGE, self._rfx_message_callback
)
)

self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_REL_MESSAGE, self._rel_message_callback
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_REL_MESSAGE, self._rel_message_callback
)
)

@property
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/alarmdecoder/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ def __init__(self, hass):

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_PANEL_MESSAGE, self._message_callback
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_PANEL_MESSAGE, self._message_callback
)
)

def _message_callback(self, message):
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/android_ip_webcam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ def async_ipcam_update(host):
return
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
def should_poll(self):
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/aqualogic/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def icon(self):

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self.async_update_callback
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self.async_update_callback
)
)

@callback
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/aqualogic/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def __init__(self, processor, switch_type):
"aux_6": States.AUX_6,
"aux_7": States.AUX_7,
}[switch_type]
self._unsub_disp = None

@property
def name(self):
Expand Down Expand Up @@ -101,11 +100,8 @@ def turn_off(self, **kwargs):

async def async_added_to_hass(self):
"""Register callbacks."""
self._unsub_disp = self.hass.helpers.dispatcher.async_dispatcher_connect(
UPDATE_TOPIC, self.async_write_ha_state
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
18 changes: 13 additions & 5 deletions homeassistant/components/arcam_fmj/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,22 @@ def _stopped(host):
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.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STARTED, _started
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STARTED, _started
)
)

self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STOPPED, _stopped
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_CLIENT_STOPPED, _stopped
)
)

async def async_update(self):
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/arlo/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def icon(self):

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):
Expand Down
12 changes: 4 additions & 8 deletions homeassistant/components/arlo/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,19 @@ def __init__(self, hass, camera, device_info):
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."""
return self._camera.last_image_from_cache

async def async_added_to_hass(self):
"""Register callbacks."""
self._unsub_disp = async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_ARLO, self.async_write_ha_state
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."""
video = await self.hass.async_add_executor_job(
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/arlo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def name(self):

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):
Expand Down
8 changes: 1 addition & 7 deletions homeassistant/components/axis/axis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/axis/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, config, device):

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
)
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/comfoconnect/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ def __init__(self, name, ccb: ComfoConnectBridge) -> None:
async def async_added_to_hass(self):
"""Register for sensor updates."""
_LOGGER.debug("Registering for fan speed")
async_dispatcher_connect(
self.hass,
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(SENSOR_FAN_SPEED_MODE),
self._handle_update,
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
Expand Down
10 changes: 6 additions & 4 deletions homeassistant/components/comfoconnect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ async def async_added_to_hass(self):
_LOGGER.debug(
"Registering for sensor %s (%d)", self._sensor_type, self._sensor_id
)
async_dispatcher_connect(
self.hass,
SIGNAL_COMFOCONNECT_UPDATE_RECEIVED.format(self._sensor_id),
self._handle_update,
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
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/denonavr/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def __init__(self, receiver):

async def async_added_to_hass(self):
"""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):
"""Handle domain-specific signal by calling appropriate method."""
Expand Down
12 changes: 10 additions & 2 deletions homeassistant/components/eight_sleep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ def async_eight_user_update():
"""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):
Expand All @@ -237,7 +241,11 @@ def async_eight_heat_update():
"""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):
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/enocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ def __init__(self, dev_id, dev_name="EnOcean device"):

async def async_added_to_hass(self):
"""Register callbacks."""
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_RECEIVE_MESSAGE, self._message_received_callback
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_RECEIVE_MESSAGE, self._message_received_callback
)
)

def _message_received_callback(self, packet):
Expand Down
12 changes: 9 additions & 3 deletions homeassistant/components/envisalink/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,15 @@ def __init__(

async def async_added_to_hass(self):
"""Register callbacks."""
async_dispatcher_connect(self.hass, SIGNAL_KEYPAD_UPDATE, self._update_callback)
async_dispatcher_connect(
self.hass, SIGNAL_PARTITION_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
Expand Down
11 changes: 7 additions & 4 deletions homeassistant/components/fastdotcom/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ def should_poll(self):
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
Expand Down
Loading