diff --git a/homeassistant/components/mysensors/__init__.py b/homeassistant/components/mysensors/__init__.py index 3f36d6e96cc..068fd9361fa 100644 --- a/homeassistant/components/mysensors/__init__.py +++ b/homeassistant/components/mysensors/__init__.py @@ -218,7 +218,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass_config=hass.data[DOMAIN][DATA_HASS_CONFIG], ) - await on_unload( + on_unload( hass, entry.entry_id, async_dispatcher_connect( diff --git a/homeassistant/components/mysensors/binary_sensor.py b/homeassistant/components/mysensors/binary_sensor.py index 2077f38c758..8358c3b2ecf 100644 --- a/homeassistant/components/mysensors/binary_sensor.py +++ b/homeassistant/components/mysensors/binary_sensor.py @@ -10,7 +10,6 @@ from homeassistant.components.binary_sensor import ( DOMAIN, BinarySensorEntity, ) -from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_ON @@ -18,6 +17,8 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback +from .helpers import on_unload + SENSORS = { "S_DOOR": "door", "S_MOTION": DEVICE_CLASS_MOTION, @@ -48,9 +49,9 @@ async def async_setup_entry( async_add_entities=async_add_entities, ) - await on_unload( + on_unload( hass, - config_entry, + config_entry.entry_id, async_dispatcher_connect( hass, MYSENSORS_DISCOVERY.format(config_entry.entry_id, DOMAIN), diff --git a/homeassistant/components/mysensors/climate.py b/homeassistant/components/mysensors/climate.py index f958f2274e0..797fcfafcc7 100644 --- a/homeassistant/components/mysensors/climate.py +++ b/homeassistant/components/mysensors/climate.py @@ -13,7 +13,6 @@ from homeassistant.components.climate.const import ( SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, ) -from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT @@ -21,6 +20,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback +from .helpers import on_unload + DICT_HA_TO_MYS = { HVAC_MODE_AUTO: "AutoChangeOver", HVAC_MODE_COOL: "CoolOn", @@ -55,9 +56,9 @@ async def async_setup_entry( async_add_entities=async_add_entities, ) - await on_unload( + on_unload( hass, - config_entry, + config_entry.entry_id, async_dispatcher_connect( hass, MYSENSORS_DISCOVERY.format(config_entry.entry_id, DOMAIN), diff --git a/homeassistant/components/mysensors/cover.py b/homeassistant/components/mysensors/cover.py index 031efc97209..2d852ef05b4 100644 --- a/homeassistant/components/mysensors/cover.py +++ b/homeassistant/components/mysensors/cover.py @@ -4,7 +4,6 @@ import logging from homeassistant.components import mysensors from homeassistant.components.cover import ATTR_POSITION, DOMAIN, CoverEntity -from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_ON @@ -12,6 +11,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback +from .helpers import on_unload + _LOGGER = logging.getLogger(__name__) @@ -42,7 +43,7 @@ async def async_setup_entry( async_add_entities=async_add_entities, ) - await on_unload( + on_unload( hass, config_entry.entry_id, async_dispatcher_connect( diff --git a/homeassistant/components/mysensors/device_tracker.py b/homeassistant/components/mysensors/device_tracker.py index 45416ff7ae7..6297f8344fc 100644 --- a/homeassistant/components/mysensors/device_tracker.py +++ b/homeassistant/components/mysensors/device_tracker.py @@ -1,12 +1,14 @@ """Support for tracking MySensors devices.""" from homeassistant.components import mysensors from homeassistant.components.device_tracker import DOMAIN -from homeassistant.components.mysensors import DevId, on_unload +from homeassistant.components.mysensors import DevId from homeassistant.components.mysensors.const import ATTR_GATEWAY_ID, GatewayId from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.util import slugify +from .helpers import on_unload + async def async_setup_scanner( hass: HomeAssistant, config, async_see, discovery_info=None @@ -28,7 +30,7 @@ async def async_setup_scanner( for device in new_devices: gateway_id: GatewayId = discovery_info[ATTR_GATEWAY_ID] dev_id: DevId = (gateway_id, device.node_id, device.child_id, device.value_type) - await on_unload( + on_unload( hass, gateway_id, async_dispatcher_connect( @@ -37,7 +39,7 @@ async def async_setup_scanner( device.async_update_callback, ), ) - await on_unload( + on_unload( hass, gateway_id, async_dispatcher_connect( diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index c0a91fbdb08..424f80df729 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -292,7 +292,7 @@ async def _gw_start(hass: HomeAssistant, entry: ConfigEntry, gateway: BaseAsyncG async def stop_this_gw(_: Event): await gw_stop(hass, entry, gateway) - await on_unload( + on_unload( hass, entry.entry_id, hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_this_gw), diff --git a/homeassistant/components/mysensors/helpers.py b/homeassistant/components/mysensors/helpers.py index 54f173de3e3..5bc0a0d0839 100644 --- a/homeassistant/components/mysensors/helpers.py +++ b/homeassistant/components/mysensors/helpers.py @@ -10,7 +10,6 @@ from mysensors import BaseAsyncGateway, Message from mysensors.sensor import ChildSensor import voluptuous as vol -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv @@ -35,18 +34,13 @@ _LOGGER = logging.getLogger(__name__) SCHEMAS = Registry() -async def on_unload( - hass: HomeAssistant, entry: ConfigEntry | GatewayId, fnct: Callable -) -> None: +@callback +def on_unload(hass: HomeAssistant, gateway_id: GatewayId, fnct: Callable) -> None: """Register a callback to be called when entry is unloaded. This function is used by platforms to cleanup after themselves. """ - if isinstance(entry, GatewayId): - uniqueid = entry - else: - uniqueid = entry.entry_id - key = MYSENSORS_ON_UNLOAD.format(uniqueid) + key = MYSENSORS_ON_UNLOAD.format(gateway_id) if key not in hass.data[DOMAIN]: hass.data[DOMAIN][key] = [] hass.data[DOMAIN][key].append(fnct) diff --git a/homeassistant/components/mysensors/light.py b/homeassistant/components/mysensors/light.py index aea99e3ee35..b9fbc139e4f 100644 --- a/homeassistant/components/mysensors/light.py +++ b/homeassistant/components/mysensors/light.py @@ -10,7 +10,6 @@ from homeassistant.components.light import ( SUPPORT_WHITE_VALUE, LightEntity, ) -from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_OFF, STATE_ON @@ -20,6 +19,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback import homeassistant.util.color as color_util from homeassistant.util.color import rgb_hex_to_rgb_list +from .helpers import on_unload + SUPPORT_MYSENSORS_RGBW = SUPPORT_COLOR | SUPPORT_WHITE_VALUE @@ -45,9 +46,9 @@ async def async_setup_entry( async_add_entities=async_add_entities, ) - await on_unload( + on_unload( hass, - config_entry, + config_entry.entry_id, async_dispatcher_connect( hass, MYSENSORS_DISCOVERY.format(config_entry.entry_id, DOMAIN), diff --git a/homeassistant/components/mysensors/sensor.py b/homeassistant/components/mysensors/sensor.py index 48ab6e5d3a2..abbfa66ab8e 100644 --- a/homeassistant/components/mysensors/sensor.py +++ b/homeassistant/components/mysensors/sensor.py @@ -2,7 +2,6 @@ from awesomeversion import AwesomeVersion from homeassistant.components import mysensors -from homeassistant.components.mysensors import on_unload from homeassistant.components.mysensors.const import MYSENSORS_DISCOVERY from homeassistant.components.sensor import DOMAIN, SensorEntity from homeassistant.config_entries import ConfigEntry @@ -27,6 +26,8 @@ from homeassistant.core import HomeAssistant from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback +from .helpers import on_unload + SENSORS = { "V_TEMP": [None, "mdi:thermometer"], "V_HUM": [PERCENTAGE, "mdi:water-percent"], @@ -79,9 +80,9 @@ async def async_setup_entry( async_add_entities=async_add_entities, ) - await on_unload( + on_unload( hass, - config_entry, + config_entry.entry_id, async_dispatcher_connect( hass, MYSENSORS_DISCOVERY.format(config_entry.entry_id, DOMAIN), diff --git a/homeassistant/components/mysensors/switch.py b/homeassistant/components/mysensors/switch.py index 32a6a9a1202..3910df55eec 100644 --- a/homeassistant/components/mysensors/switch.py +++ b/homeassistant/components/mysensors/switch.py @@ -8,10 +8,10 @@ from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback -from . import on_unload from ...config_entries import ConfigEntry from ...helpers.dispatcher import async_dispatcher_connect from .const import DOMAIN as MYSENSORS_DOMAIN, MYSENSORS_DISCOVERY, SERVICE_SEND_IR_CODE +from .helpers import on_unload ATTR_IR_CODE = "V_IR_SEND" @@ -83,9 +83,9 @@ async def async_setup_entry( schema=SEND_IR_CODE_SERVICE_SCHEMA, ) - await on_unload( + on_unload( hass, - config_entry, + config_entry.entry_id, async_dispatcher_connect( hass, MYSENSORS_DISCOVERY.format(config_entry.entry_id, DOMAIN),