Use async_on_unload from config entry in ZHA (#61015)

* remove DATA_ZHA_DISPATCHERS

* update typing information

* fix rebase
This commit is contained in:
David F. Mulcahey 2021-12-11 11:50:03 -05:00 committed by GitHub
parent 0abfc90870
commit f6ac856b8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 99 additions and 58 deletions

View file

@ -12,9 +12,11 @@ from homeassistant.components.binary_sensor import (
DEVICE_CLASS_VIBRATION,
BinarySensorEntity,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import STATE_ON, Platform
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .core import discovery
from .core.const import (
@ -24,7 +26,6 @@ from .core.const import (
CHANNEL_ON_OFF,
CHANNEL_ZONE,
DATA_ZHA,
DATA_ZHA_DISPATCHERS,
SIGNAL_ADD_ENTITIES,
SIGNAL_ATTR_UPDATED,
)
@ -44,7 +45,11 @@ CLASS_MAPPING = {
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.BINARY_SENSOR)
async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
):
"""Set up the Zigbee Home Automation binary sensor from config entry."""
entities_to_create = hass.data[DATA_ZHA][Platform.BINARY_SENSOR]
@ -55,7 +60,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
discovery.async_add_entities, async_add_entities, entities_to_create
),
)
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
config_entry.async_on_unload(unsub)
class BinarySensor(ZhaEntity, BinarySensorEntity):