Use async_on_unload from config entry in ZHA (#61015)
* remove DATA_ZHA_DISPATCHERS * update typing information * fix rebase
This commit is contained in:
parent
0abfc90870
commit
f6ac856b8d
13 changed files with 99 additions and 58 deletions
|
@ -12,6 +12,7 @@ from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
|
from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import api
|
from . import api
|
||||||
from .core import ZHAGateway
|
from .core import ZHAGateway
|
||||||
|
@ -27,7 +28,6 @@ from .core.const import (
|
||||||
CONF_ZIGPY,
|
CONF_ZIGPY,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_CONFIG,
|
DATA_ZHA_CONFIG,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
DATA_ZHA_GATEWAY,
|
DATA_ZHA_GATEWAY,
|
||||||
DATA_ZHA_PLATFORM_LOADED,
|
DATA_ZHA_PLATFORM_LOADED,
|
||||||
DATA_ZHA_SHUTDOWN_TASK,
|
DATA_ZHA_SHUTDOWN_TASK,
|
||||||
|
@ -72,7 +72,7 @@ CENTICELSIUS = "C-100"
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||||
"""Set up ZHA from config."""
|
"""Set up ZHA from config."""
|
||||||
hass.data[DATA_ZHA] = {}
|
hass.data[DATA_ZHA] = {}
|
||||||
|
|
||||||
|
@ -83,7 +83,9 @@ async def async_setup(hass, config):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, config_entry: config_entries.ConfigEntry
|
||||||
|
):
|
||||||
"""Set up ZHA.
|
"""Set up ZHA.
|
||||||
|
|
||||||
Will automatically load components to support devices found on the network.
|
Will automatically load components to support devices found on the network.
|
||||||
|
@ -101,7 +103,6 @@ async def async_setup_entry(hass, config_entry):
|
||||||
zha_gateway = ZHAGateway(hass, config, config_entry)
|
zha_gateway = ZHAGateway(hass, config, config_entry)
|
||||||
await zha_gateway.async_initialize()
|
await zha_gateway.async_initialize()
|
||||||
|
|
||||||
zha_data[DATA_ZHA_DISPATCHERS] = []
|
|
||||||
zha_data[DATA_ZHA_PLATFORM_LOADED] = []
|
zha_data[DATA_ZHA_PLATFORM_LOADED] = []
|
||||||
for platform in PLATFORMS:
|
for platform in PLATFORMS:
|
||||||
coro = hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
coro = hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
||||||
|
@ -131,7 +132,9 @@ async def async_setup_entry(hass, config_entry):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass, config_entry):
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, config_entry: config_entries.ConfigEntry
|
||||||
|
):
|
||||||
"""Unload ZHA config entry."""
|
"""Unload ZHA config entry."""
|
||||||
await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].shutdown()
|
await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].shutdown()
|
||||||
await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].async_update_device_storage()
|
await hass.data[DATA_ZHA][DATA_ZHA_GATEWAY].async_update_device_storage()
|
||||||
|
@ -139,10 +142,6 @@ async def async_unload_entry(hass, config_entry):
|
||||||
GROUP_PROBE.cleanup()
|
GROUP_PROBE.cleanup()
|
||||||
api.async_unload_api(hass)
|
api.async_unload_api(hass)
|
||||||
|
|
||||||
dispatchers = hass.data[DATA_ZHA].get(DATA_ZHA_DISPATCHERS, [])
|
|
||||||
for unsub_dispatcher in dispatchers:
|
|
||||||
unsub_dispatcher()
|
|
||||||
|
|
||||||
# our components don't have unload methods so no need to look at return values
|
# our components don't have unload methods so no need to look at return values
|
||||||
await asyncio.gather(
|
await asyncio.gather(
|
||||||
*(
|
*(
|
||||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.alarm_control_panel import (
|
||||||
AlarmControlPanelEntity,
|
AlarmControlPanelEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.components.zha.core.typing import ZhaDeviceType
|
from homeassistant.components.zha.core.typing import ZhaDeviceType
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ALARM_ARMED_AWAY,
|
STATE_ALARM_ARMED_AWAY,
|
||||||
STATE_ALARM_ARMED_HOME,
|
STATE_ALARM_ARMED_HOME,
|
||||||
|
@ -20,8 +21,9 @@ from homeassistant.const import (
|
||||||
STATE_ALARM_TRIGGERED,
|
STATE_ALARM_TRIGGERED,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.channels.security import (
|
from .core.channels.security import (
|
||||||
|
@ -35,7 +37,6 @@ from .core.const import (
|
||||||
CONF_ALARM_FAILED_TRIES,
|
CONF_ALARM_FAILED_TRIES,
|
||||||
CONF_ALARM_MASTER_CODE,
|
CONF_ALARM_MASTER_CODE,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
ZHA_ALARM_OPTIONS,
|
ZHA_ALARM_OPTIONS,
|
||||||
)
|
)
|
||||||
|
@ -56,7 +57,11 @@ IAS_ACE_STATE_MAP = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 alarm control panel from config entry."""
|
"""Set up the Zigbee Home Automation alarm control panel from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.ALARM_CONTROL_PANEL]
|
entities_to_create = hass.data[DATA_ZHA][Platform.ALARM_CONTROL_PANEL]
|
||||||
|
|
||||||
|
@ -67,7 +72,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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)
|
||||||
|
|
||||||
|
|
||||||
@STRICT_MATCH(channel_names=CHANNEL_IAS_ACE)
|
@STRICT_MATCH(channel_names=CHANNEL_IAS_ACE)
|
||||||
|
|
|
@ -12,9 +12,11 @@ from homeassistant.components.binary_sensor import (
|
||||||
DEVICE_CLASS_VIBRATION,
|
DEVICE_CLASS_VIBRATION,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import STATE_ON, Platform
|
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.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
|
@ -24,7 +26,6 @@ from .core.const import (
|
||||||
CHANNEL_ON_OFF,
|
CHANNEL_ON_OFF,
|
||||||
CHANNEL_ZONE,
|
CHANNEL_ZONE,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -44,7 +45,11 @@ CLASS_MAPPING = {
|
||||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.BINARY_SENSOR)
|
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."""
|
"""Set up the Zigbee Home Automation binary sensor from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.BINARY_SENSOR]
|
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
|
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):
|
class BinarySensor(ZhaEntity, BinarySensorEntity):
|
||||||
|
|
|
@ -39,14 +39,16 @@ from homeassistant.components.climate.const import (
|
||||||
SUPPORT_TARGET_TEMPERATURE,
|
SUPPORT_TARGET_TEMPERATURE,
|
||||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PRECISION_TENTHS,
|
PRECISION_TENTHS,
|
||||||
TEMP_CELSIUS,
|
TEMP_CELSIUS,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
|
@ -55,7 +57,6 @@ from .core.const import (
|
||||||
CHANNEL_FAN,
|
CHANNEL_FAN,
|
||||||
CHANNEL_THERMOSTAT,
|
CHANNEL_THERMOSTAT,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
PRESET_COMPLEX,
|
PRESET_COMPLEX,
|
||||||
PRESET_SCHEDULE,
|
PRESET_SCHEDULE,
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
|
@ -154,7 +155,11 @@ SYSTEM_MODE_2_HVAC = {
|
||||||
ZCL_TEMP = 100
|
ZCL_TEMP = 100
|
||||||
|
|
||||||
|
|
||||||
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 sensor from config entry."""
|
"""Set up the Zigbee Home Automation sensor from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.CLIMATE]
|
entities_to_create = hass.data[DATA_ZHA][Platform.CLIMATE]
|
||||||
unsub = async_dispatcher_connect(
|
unsub = async_dispatcher_connect(
|
||||||
|
@ -164,7 +169,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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)
|
||||||
|
|
||||||
|
|
||||||
@MULTI_MATCH(channel_names=CHANNEL_THERMOSTAT, aux_channels=CHANNEL_FAN)
|
@MULTI_MATCH(channel_names=CHANNEL_THERMOSTAT, aux_channels=CHANNEL_FAN)
|
||||||
|
|
|
@ -165,7 +165,6 @@ DATA_ZHA = "zha"
|
||||||
DATA_ZHA_CONFIG = "config"
|
DATA_ZHA_CONFIG = "config"
|
||||||
DATA_ZHA_BRIDGE_ID = "zha_bridge_id"
|
DATA_ZHA_BRIDGE_ID = "zha_bridge_id"
|
||||||
DATA_ZHA_CORE_EVENTS = "zha_core_events"
|
DATA_ZHA_CORE_EVENTS = "zha_core_events"
|
||||||
DATA_ZHA_DISPATCHERS = "zha_dispatchers"
|
|
||||||
DATA_ZHA_GATEWAY = "zha_gateway"
|
DATA_ZHA_GATEWAY = "zha_gateway"
|
||||||
DATA_ZHA_PLATFORM_LOADED = "platform_loaded"
|
DATA_ZHA_PLATFORM_LOADED = "platform_loaded"
|
||||||
DATA_ZHA_SHUTDOWN_TASK = "zha_shutdown_task"
|
DATA_ZHA_SHUTDOWN_TASK = "zha_shutdown_task"
|
||||||
|
|
|
@ -14,6 +14,7 @@ from homeassistant.components.cover import (
|
||||||
DEVICE_CLASS_SHADE,
|
DEVICE_CLASS_SHADE,
|
||||||
CoverEntity,
|
CoverEntity,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_CLOSED,
|
STATE_CLOSED,
|
||||||
STATE_CLOSING,
|
STATE_CLOSING,
|
||||||
|
@ -21,8 +22,9 @@ from homeassistant.const import (
|
||||||
STATE_OPENING,
|
STATE_OPENING,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
|
@ -31,7 +33,6 @@ from .core.const import (
|
||||||
CHANNEL_ON_OFF,
|
CHANNEL_ON_OFF,
|
||||||
CHANNEL_SHADE,
|
CHANNEL_SHADE,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
SIGNAL_SET_LEVEL,
|
SIGNAL_SET_LEVEL,
|
||||||
|
@ -45,7 +46,11 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.COVER)
|
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.COVER)
|
||||||
|
|
||||||
|
|
||||||
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 cover from config entry."""
|
"""Set up the Zigbee Home Automation cover from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.COVER]
|
entities_to_create = hass.data[DATA_ZHA][Platform.COVER]
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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)
|
||||||
|
|
||||||
|
|
||||||
@STRICT_MATCH(channel_names=CHANNEL_COVER)
|
@STRICT_MATCH(channel_names=CHANNEL_COVER)
|
||||||
|
|
|
@ -4,15 +4,16 @@ import time
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
|
from homeassistant.components.device_tracker import SOURCE_TYPE_ROUTER
|
||||||
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
from homeassistant.components.device_tracker.config_entry import ScannerEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
CHANNEL_POWER_CONFIGURATION,
|
CHANNEL_POWER_CONFIGURATION,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -23,7 +24,11 @@ from .sensor import Battery
|
||||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.DEVICE_TRACKER)
|
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.DEVICE_TRACKER)
|
||||||
|
|
||||||
|
|
||||||
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 device tracker from config entry."""
|
"""Set up the Zigbee Home Automation device tracker from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.DEVICE_TRACKER]
|
entities_to_create = hass.data[DATA_ZHA][Platform.DEVICE_TRACKER]
|
||||||
|
|
||||||
|
@ -34,7 +39,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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)
|
||||||
|
|
||||||
|
|
||||||
@STRICT_MATCH(channel_names=CHANNEL_POWER_CONFIGURATION)
|
@STRICT_MATCH(channel_names=CHANNEL_POWER_CONFIGURATION)
|
||||||
|
|
|
@ -15,9 +15,11 @@ from homeassistant.components.fan import (
|
||||||
FanEntity,
|
FanEntity,
|
||||||
NotValidPresetModeError,
|
NotValidPresetModeError,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
from homeassistant.const import STATE_UNAVAILABLE, Platform
|
||||||
from homeassistant.core import State, callback
|
from homeassistant.core import HomeAssistant, State, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.percentage import (
|
from homeassistant.util.percentage import (
|
||||||
int_states_in_range,
|
int_states_in_range,
|
||||||
percentage_to_ranged_value,
|
percentage_to_ranged_value,
|
||||||
|
@ -25,13 +27,7 @@ from homeassistant.util.percentage import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import CHANNEL_FAN, DATA_ZHA, SIGNAL_ADD_ENTITIES, SIGNAL_ATTR_UPDATED
|
||||||
CHANNEL_FAN,
|
|
||||||
DATA_ZHA,
|
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
|
||||||
SIGNAL_ATTR_UPDATED,
|
|
||||||
)
|
|
||||||
from .core.registries import ZHA_ENTITIES
|
from .core.registries import ZHA_ENTITIES
|
||||||
from .entity import ZhaEntity, ZhaGroupEntity
|
from .entity import ZhaEntity, ZhaGroupEntity
|
||||||
|
|
||||||
|
@ -56,7 +52,11 @@ STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.FAN)
|
||||||
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.FAN)
|
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.FAN)
|
||||||
|
|
||||||
|
|
||||||
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 fan from config entry."""
|
"""Set up the Zigbee Home Automation fan from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.FAN]
|
entities_to_create = hass.data[DATA_ZHA][Platform.FAN]
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
update_before_add=False,
|
update_before_add=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
|
config_entry.async_on_unload(unsub)
|
||||||
|
|
||||||
|
|
||||||
class BaseFan(FanEntity):
|
class BaseFan(FanEntity):
|
||||||
|
|
|
@ -30,18 +30,20 @@ from homeassistant.components.light import (
|
||||||
SUPPORT_FLASH,
|
SUPPORT_FLASH,
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
)
|
)
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import State, callback
|
from homeassistant.core import HomeAssistant, State, callback
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.dispatcher import (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
import homeassistant.util.color as color_util
|
import homeassistant.util.color as color_util
|
||||||
|
|
||||||
|
@ -52,7 +54,6 @@ from .core.const import (
|
||||||
CHANNEL_ON_OFF,
|
CHANNEL_ON_OFF,
|
||||||
CONF_DEFAULT_LIGHT_TRANSITION,
|
CONF_DEFAULT_LIGHT_TRANSITION,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
EFFECT_BLINK,
|
EFFECT_BLINK,
|
||||||
EFFECT_BREATHE,
|
EFFECT_BREATHE,
|
||||||
EFFECT_DEFAULT_VARIANT,
|
EFFECT_DEFAULT_VARIANT,
|
||||||
|
@ -105,7 +106,11 @@ class LightColorMode(enum.IntEnum):
|
||||||
COLOR_TEMP = 0x02
|
COLOR_TEMP = 0x02
|
||||||
|
|
||||||
|
|
||||||
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 light from config entry."""
|
"""Set up the Zigbee Home Automation light from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.LIGHT]
|
entities_to_create = hass.data[DATA_ZHA][Platform.LIGHT]
|
||||||
|
|
||||||
|
@ -116,7 +121,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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 BaseLight(LogMixin, light.LightEntity):
|
class BaseLight(LogMixin, light.LightEntity):
|
||||||
|
|
|
@ -5,8 +5,9 @@ import voluptuous as vol
|
||||||
from zigpy.zcl.foundation import Status
|
from zigpy.zcl.foundation import Status
|
||||||
|
|
||||||
from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED, LockEntity
|
from homeassistant.components.lock import STATE_LOCKED, STATE_UNLOCKED, LockEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
|
@ -14,7 +15,6 @@ from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
CHANNEL_DOORLOCK,
|
CHANNEL_DOORLOCK,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,11 @@ SERVICE_DISABLE_LOCK_USER_CODE = "disable_lock_user_code"
|
||||||
SERVICE_CLEAR_LOCK_USER_CODE = "clear_lock_user_code"
|
SERVICE_CLEAR_LOCK_USER_CODE = "clear_lock_user_code"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: entity_platform.AddEntitiesCallback,
|
||||||
|
):
|
||||||
"""Set up the Zigbee Home Automation Door Lock from config entry."""
|
"""Set up the Zigbee Home Automation Door Lock from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.LOCK]
|
entities_to_create = hass.data[DATA_ZHA][Platform.LOCK]
|
||||||
|
|
||||||
|
@ -44,7 +48,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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)
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,16 @@ import functools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.number import NumberEntity
|
from homeassistant.components.number import NumberEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
CHANNEL_ANALOG_OUTPUT,
|
CHANNEL_ANALOG_OUTPUT,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -234,7 +235,11 @@ ICONS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 Analog Output from config entry."""
|
"""Set up the Zigbee Home Automation Analog Output from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.NUMBER]
|
entities_to_create = hass.data[DATA_ZHA][Platform.NUMBER]
|
||||||
|
|
||||||
|
@ -248,7 +253,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
update_before_add=False,
|
update_before_add=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
|
config_entry.async_on_unload(unsub)
|
||||||
|
|
||||||
|
|
||||||
@STRICT_MATCH(channel_names=CHANNEL_ANALOG_OUTPUT)
|
@STRICT_MATCH(channel_names=CHANNEL_ANALOG_OUTPUT)
|
||||||
|
|
|
@ -72,7 +72,6 @@ from .core.const import (
|
||||||
CHANNEL_TEMPERATURE,
|
CHANNEL_TEMPERATURE,
|
||||||
CHANNEL_THERMOSTAT,
|
CHANNEL_THERMOSTAT,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -121,7 +120,7 @@ async def async_setup_entry(
|
||||||
update_before_add=False,
|
update_before_add=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS].append(unsub)
|
config_entry.async_on_unload(unsub)
|
||||||
|
|
||||||
|
|
||||||
class Sensor(ZhaEntity, SensorEntity):
|
class Sensor(ZhaEntity, SensorEntity):
|
||||||
|
|
|
@ -8,15 +8,16 @@ from zigpy.zcl.clusters.general import OnOff
|
||||||
from zigpy.zcl.foundation import Status
|
from zigpy.zcl.foundation import Status
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, Platform
|
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, Platform
|
||||||
from homeassistant.core import State, callback
|
from homeassistant.core import HomeAssistant, State, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .core import discovery
|
from .core import discovery
|
||||||
from .core.const import (
|
from .core.const import (
|
||||||
CHANNEL_ON_OFF,
|
CHANNEL_ON_OFF,
|
||||||
DATA_ZHA,
|
DATA_ZHA,
|
||||||
DATA_ZHA_DISPATCHERS,
|
|
||||||
SIGNAL_ADD_ENTITIES,
|
SIGNAL_ADD_ENTITIES,
|
||||||
SIGNAL_ATTR_UPDATED,
|
SIGNAL_ATTR_UPDATED,
|
||||||
)
|
)
|
||||||
|
@ -27,7 +28,11 @@ STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SWITCH)
|
||||||
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH)
|
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH)
|
||||||
|
|
||||||
|
|
||||||
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 switch from config entry."""
|
"""Set up the Zigbee Home Automation switch from config entry."""
|
||||||
entities_to_create = hass.data[DATA_ZHA][Platform.SWITCH]
|
entities_to_create = hass.data[DATA_ZHA][Platform.SWITCH]
|
||||||
|
|
||||||
|
@ -38,7 +43,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
discovery.async_add_entities, async_add_entities, entities_to_create
|
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 BaseSwitch(SwitchEntity):
|
class BaseSwitch(SwitchEntity):
|
||||||
|
|
Loading…
Add table
Reference in a new issue