diff --git a/homeassistant/components/aftership/sensor.py b/homeassistant/components/aftership/sensor.py index 62d138d21236..d816afa3b17d 100644 --- a/homeassistant/components/aftership/sensor.py +++ b/homeassistant/components/aftership/sensor.py @@ -15,7 +15,10 @@ from homeassistant.const import CONF_API_KEY, CONF_NAME from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.dispatcher import async_dispatcher_send +from homeassistant.helpers.dispatcher import ( + async_dispatcher_connect, + async_dispatcher_send, +) from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import Throttle @@ -128,9 +131,7 @@ class AfterShipSensor(SensorEntity): async def async_added_to_hass(self) -> None: """Register callbacks.""" self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - UPDATE_TOPIC, self._force_update - ) + async_dispatcher_connect(self.hass, UPDATE_TOPIC, self._force_update) ) async def _force_update(self) -> None: diff --git a/homeassistant/components/alarmdecoder/alarm_control_panel.py b/homeassistant/components/alarmdecoder/alarm_control_panel.py index 4d7b55db991b..b16490357d1f 100644 --- a/homeassistant/components/alarmdecoder/alarm_control_panel.py +++ b/homeassistant/components/alarmdecoder/alarm_control_panel.py @@ -22,6 +22,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ( @@ -95,8 +96,8 @@ class AlarmDecoderAlarmPanel(AlarmControlPanelEntity): 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 + async_dispatcher_connect( + self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback ) ) diff --git a/homeassistant/components/alarmdecoder/binary_sensor.py b/homeassistant/components/alarmdecoder/binary_sensor.py index 87b6c86fc332..24eeffde691f 100644 --- a/homeassistant/components/alarmdecoder/binary_sensor.py +++ b/homeassistant/components/alarmdecoder/binary_sensor.py @@ -4,6 +4,7 @@ import logging from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ( @@ -90,26 +91,24 @@ class AlarmDecoderBinarySensor(BinarySensorEntity): 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 + async_dispatcher_connect(self.hass, SIGNAL_ZONE_FAULT, self._fault_callback) + ) + + self.async_on_remove( + async_dispatcher_connect( + self.hass, SIGNAL_ZONE_RESTORE, self._restore_callback ) ) self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_ZONE_RESTORE, self._restore_callback + async_dispatcher_connect( + self.hass, 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.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_REL_MESSAGE, self._rel_message_callback + async_dispatcher_connect( + self.hass, SIGNAL_REL_MESSAGE, self._rel_message_callback ) ) diff --git a/homeassistant/components/alarmdecoder/sensor.py b/homeassistant/components/alarmdecoder/sensor.py index 897348f13863..90d0606d6816 100644 --- a/homeassistant/components/alarmdecoder/sensor.py +++ b/homeassistant/components/alarmdecoder/sensor.py @@ -2,6 +2,7 @@ from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import SIGNAL_PANEL_MESSAGE @@ -26,8 +27,8 @@ class AlarmDecoderSensor(SensorEntity): 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 + async_dispatcher_connect( + self.hass, SIGNAL_PANEL_MESSAGE, self._message_callback ) ) diff --git a/homeassistant/components/aqualogic/sensor.py b/homeassistant/components/aqualogic/sensor.py index 3337e9c40a2b..5e6e35cce76d 100644 --- a/homeassistant/components/aqualogic/sensor.py +++ b/homeassistant/components/aqualogic/sensor.py @@ -20,6 +20,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -146,8 +147,8 @@ class AquaLogicSensor(SensorEntity): 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 + async_dispatcher_connect( + self.hass, UPDATE_TOPIC, self.async_update_callback ) ) diff --git a/homeassistant/components/aqualogic/switch.py b/homeassistant/components/aqualogic/switch.py index 54a37056187e..953b0c9b527d 100644 --- a/homeassistant/components/aqualogic/switch.py +++ b/homeassistant/components/aqualogic/switch.py @@ -8,6 +8,7 @@ from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity from homeassistant.const import CONF_MONITORED_CONDITIONS from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -96,7 +97,5 @@ class AquaLogicSwitch(SwitchEntity): async def async_added_to_hass(self): """Register callbacks.""" self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - UPDATE_TOPIC, self.async_write_ha_state - ) + async_dispatcher_connect(self.hass, UPDATE_TOPIC, self.async_write_ha_state) ) diff --git a/homeassistant/components/econet/__init__.py b/homeassistant/components/econet/__init__.py index 100b58b107d5..a706ceb8e7ed 100644 --- a/homeassistant/components/econet/__init__.py +++ b/homeassistant/components/econet/__init__.py @@ -16,7 +16,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, TEMP_FAHRENHEIT, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers.dispatcher import dispatcher_send +from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.event import async_track_time_interval from homeassistant.helpers.typing import ConfigType @@ -119,9 +119,7 @@ class EcoNetEntity(Entity): """Subscribe to device events.""" await super().async_added_to_hass() self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - PUSH_UPDATE, self.on_update_received - ) + async_dispatcher_connect(self.hass, PUSH_UPDATE, self.on_update_received) ) @callback diff --git a/homeassistant/components/enocean/device.py b/homeassistant/components/enocean/device.py index 36477d21cffa..b57b053f4a77 100644 --- a/homeassistant/components/enocean/device.py +++ b/homeassistant/components/enocean/device.py @@ -2,6 +2,7 @@ from enocean.protocol.packet import Packet from enocean.utils import combine_hex +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity from .const import SIGNAL_RECEIVE_MESSAGE, SIGNAL_SEND_MESSAGE @@ -18,8 +19,8 @@ class EnOceanEntity(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 + async_dispatcher_connect( + self.hass, SIGNAL_RECEIVE_MESSAGE, self._message_received_callback ) ) diff --git a/homeassistant/components/homekit_controller/__init__.py b/homeassistant/components/homekit_controller/__init__.py index e4f8f715bc8a..6b538658b23b 100644 --- a/homeassistant/components/homekit_controller/__init__.py +++ b/homeassistant/components/homekit_controller/__init__.py @@ -18,6 +18,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import Event, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.typing import ConfigType @@ -65,8 +66,10 @@ class HomeKitEntity(Entity): async def async_added_to_hass(self) -> None: """Entity added to hass.""" self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - self._accessory.signal_state_updated, self.async_write_ha_state + async_dispatcher_connect( + self.hass, + self._accessory.signal_state_updated, + self.async_write_ha_state, ) ) diff --git a/homeassistant/components/mobile_app/device_tracker.py b/homeassistant/components/mobile_app/device_tracker.py index 5e2ae23af165..0f6f0835c3b0 100644 --- a/homeassistant/components/mobile_app/device_tracker.py +++ b/homeassistant/components/mobile_app/device_tracker.py @@ -15,6 +15,7 @@ from homeassistant.const import ( ATTR_LONGITUDE, ) from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity @@ -114,8 +115,10 @@ class MobileAppEntity(TrackerEntity, RestoreEntity): async def async_added_to_hass(self): """Call when entity about to be added to Home Assistant.""" await super().async_added_to_hass() - self._dispatch_unsub = self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_LOCATION_UPDATE.format(self._entry.entry_id), self.update_data + self._dispatch_unsub = async_dispatcher_connect( + self.hass, + SIGNAL_LOCATION_UPDATE.format(self._entry.entry_id), + self.update_data, ) # Don't restore if we got set up with data. diff --git a/homeassistant/components/owntracks/__init__.py b/homeassistant/components/owntracks/__init__.py index 1ac454d0c8ce..a9f89d26238f 100644 --- a/homeassistant/components/owntracks/__init__.py +++ b/homeassistant/components/owntracks/__init__.py @@ -18,6 +18,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.typing import ConfigType from homeassistant.setup import async_when_setup @@ -101,8 +102,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.config_entries.async_setup_platforms(entry, PLATFORMS) - hass.data[DOMAIN]["unsub"] = hass.helpers.dispatcher.async_dispatcher_connect( - DOMAIN, async_handle_message + hass.data[DOMAIN]["unsub"] = async_dispatcher_connect( + hass, DOMAIN, async_handle_message ) return True diff --git a/homeassistant/components/plaato/entity.py b/homeassistant/components/plaato/entity.py index b0297ec3024d..33ac5d910aaa 100644 --- a/homeassistant/components/plaato/entity.py +++ b/homeassistant/components/plaato/entity.py @@ -2,6 +2,7 @@ from pyplaato.models.device import PlaatoDevice from homeassistant.helpers import entity +from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import ( DEVICE, @@ -95,7 +96,8 @@ class PlaatoEntity(entity.Entity): ) else: self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( + async_dispatcher_connect( + self.hass, SENSOR_SIGNAL % (self._device_id, self._sensor_type), self.async_write_ha_state, ) diff --git a/homeassistant/components/qwikswitch/__init__.py b/homeassistant/components/qwikswitch/__init__.py index ecf7720b2834..e529483d0cc0 100644 --- a/homeassistant/components/qwikswitch/__init__.py +++ b/homeassistant/components/qwikswitch/__init__.py @@ -21,6 +21,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import load_platform +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import ConfigType @@ -96,9 +97,7 @@ 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 - ) + async_dispatcher_connect(self.hass, self.qsid, self.update_packet) ) diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index ba4cb9eb2261..c10075bbb79c 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -30,6 +30,7 @@ from homeassistant.helpers.device_registry import ( DeviceEntry, DeviceRegistry, ) +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.restore_state import RestoreEntity @@ -334,7 +335,7 @@ async def async_setup_platform_entry( async_add_entities(constructor(event, event, device_id, {})) config_entry.async_on_unload( - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_EVENT, _update) + async_dispatcher_connect(hass, SIGNAL_EVENT, _update) ) @@ -484,9 +485,7 @@ class RfxtrxEntity(RestoreEntity): self._apply_event(self._event) self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_EVENT, self._handle_event - ) + async_dispatcher_connect(self.hass, SIGNAL_EVENT, self._handle_event) ) @property diff --git a/homeassistant/components/tellstick/__init__.py b/homeassistant/components/tellstick/__init__.py index b95928c01b44..8611c99b6549 100644 --- a/homeassistant/components/tellstick/__init__.py +++ b/homeassistant/components/tellstick/__init__.py @@ -17,6 +17,7 @@ from homeassistant.const import CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import discovery import homeassistant.helpers.config_validation as cv +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import ConfigType @@ -188,8 +189,8 @@ 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 + async_dispatcher_connect( + self.hass, SIGNAL_TELLCORE_CALLBACK, self.update_from_callback ) ) diff --git a/homeassistant/components/waterfurnace/sensor.py b/homeassistant/components/waterfurnace/sensor.py index 15f3f64c9ba9..8418992ac5de 100644 --- a/homeassistant/components/waterfurnace/sensor.py +++ b/homeassistant/components/waterfurnace/sensor.py @@ -8,6 +8,7 @@ from homeassistant.components.sensor import ( ) from homeassistant.const import PERCENTAGE, POWER_WATT, TEMP_FAHRENHEIT from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.util import slugify @@ -138,8 +139,8 @@ class WaterFurnaceSensor(SensorEntity): 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 + async_dispatcher_connect( + self.hass, UPDATE_TOPIC, self.async_update_callback ) ) diff --git a/homeassistant/components/websocket_api/sensor.py b/homeassistant/components/websocket_api/sensor.py index 29cc2f4a44de..9377fcefd92e 100644 --- a/homeassistant/components/websocket_api/sensor.py +++ b/homeassistant/components/websocket_api/sensor.py @@ -3,6 +3,7 @@ from __future__ import annotations from homeassistant.components.sensor import SensorEntity from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType @@ -35,13 +36,13 @@ class APICount(SensorEntity): async def async_added_to_hass(self) -> None: """Added to hass.""" self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_WEBSOCKET_CONNECTED, self._update_count + async_dispatcher_connect( + self.hass, SIGNAL_WEBSOCKET_CONNECTED, self._update_count ) ) self.async_on_remove( - self.hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_WEBSOCKET_DISCONNECTED, self._update_count + async_dispatcher_connect( + self.hass, SIGNAL_WEBSOCKET_DISCONNECTED, self._update_count ) ) diff --git a/tests/common.py b/tests/common.py index 55878f76da7b..5968a21cddb5 100644 --- a/tests/common.py +++ b/tests/common.py @@ -55,6 +55,7 @@ from homeassistant.helpers import ( restore_state, storage, ) +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.json import JSONEncoder from homeassistant.setup import async_setup_component, setup_component from homeassistant.util.async_ import run_callback_threadsafe @@ -1208,7 +1209,7 @@ def async_mock_signal(hass, signal): """Mock service call.""" calls.append(args) - hass.helpers.dispatcher.async_dispatcher_connect(signal, mock_signal_handler) + async_dispatcher_connect(hass, signal, mock_signal_handler) return calls diff --git a/tests/components/heos/test_media_player.py b/tests/components/heos/test_media_player.py index d134840d652c..ee75793df8e4 100644 --- a/tests/components/heos/test_media_player.py +++ b/tests/components/heos/test_media_player.py @@ -58,6 +58,7 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) from homeassistant.helpers import device_registry as dr, entity_registry as er +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.setup import async_setup_component @@ -155,7 +156,7 @@ async def test_updates_from_connection_event( async def set_signal(): event.set() - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_HEOS_UPDATED, set_signal) + async_dispatcher_connect(hass, SIGNAL_HEOS_UPDATED, set_signal) # Connected player.available = True @@ -201,7 +202,7 @@ async def test_updates_from_sources_updated( async def set_signal(): event.set() - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_HEOS_UPDATED, set_signal) + async_dispatcher_connect(hass, SIGNAL_HEOS_UPDATED, set_signal) input_sources.clear() player.heos.dispatcher.send( @@ -225,7 +226,7 @@ async def test_updates_from_players_changed( async def set_signal(): event.set() - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_HEOS_UPDATED, set_signal) + async_dispatcher_connect(hass, SIGNAL_HEOS_UPDATED, set_signal) assert hass.states.get("media_player.test_player").state == STATE_IDLE player.state = const.PLAY_STATE_PLAY @@ -259,7 +260,7 @@ async def test_updates_from_players_changed_new_ids( async def set_signal(): event.set() - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_HEOS_UPDATED, set_signal) + async_dispatcher_connect(hass, SIGNAL_HEOS_UPDATED, set_signal) player.heos.dispatcher.send( const.SIGNAL_CONTROLLER_EVENT, const.EVENT_PLAYERS_CHANGED, @@ -287,7 +288,7 @@ async def test_updates_from_user_changed(hass, config_entry, config, controller) async def set_signal(): event.set() - hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_HEOS_UPDATED, set_signal) + async_dispatcher_connect(hass, SIGNAL_HEOS_UPDATED, set_signal) controller.is_signed_in = False controller.signed_in_username = None diff --git a/tests/components/websocket_api/test_auth.py b/tests/components/websocket_api/test_auth.py index 7834474470ca..6591bd58dfdf 100644 --- a/tests/components/websocket_api/test_auth.py +++ b/tests/components/websocket_api/test_auth.py @@ -16,6 +16,7 @@ from homeassistant.components.websocket_api.const import ( URL, ) from homeassistant.core import callback +from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.setup import async_setup_component from tests.common import mock_coro @@ -30,18 +31,14 @@ def track_connected(hass): def track_connected(): connected_evt.append(1) - hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_WEBSOCKET_CONNECTED, track_connected - ) + async_dispatcher_connect(hass, SIGNAL_WEBSOCKET_CONNECTED, track_connected) disconnected_evt = [] @callback def track_disconnected(): disconnected_evt.append(1) - hass.helpers.dispatcher.async_dispatcher_connect( - SIGNAL_WEBSOCKET_DISCONNECTED, track_disconnected - ) + async_dispatcher_connect(hass, SIGNAL_WEBSOCKET_DISCONNECTED, track_disconnected) return {"connected": connected_evt, "disconnected": disconnected_evt}