mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Remove global from ZHA application controller (#19557)
* remove global from application controller per request * remove unneeded line * don't store controller application in hass.data - review comment
This commit is contained in:
parent
e0f50a9e54
commit
bef85ecd2e
@ -76,7 +76,6 @@ SERVICE_SCHEMAS = {
|
|||||||
CENTICELSIUS = 'C-100'
|
CENTICELSIUS = 'C-100'
|
||||||
|
|
||||||
# Internal definitions
|
# Internal definitions
|
||||||
APPLICATION_CONTROLLER = None
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@ -114,8 +113,6 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
# pylint: disable=W0611, W0612
|
# pylint: disable=W0611, W0612
|
||||||
import zhaquirks # noqa
|
import zhaquirks # noqa
|
||||||
|
|
||||||
global APPLICATION_CONTROLLER
|
|
||||||
|
|
||||||
hass.data[DATA_ZHA] = hass.data.get(DATA_ZHA, {})
|
hass.data[DATA_ZHA] = hass.data.get(DATA_ZHA, {})
|
||||||
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS] = []
|
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS] = []
|
||||||
|
|
||||||
@ -155,12 +152,12 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
ClusterPersistingListener
|
ClusterPersistingListener
|
||||||
)
|
)
|
||||||
|
|
||||||
APPLICATION_CONTROLLER = ControllerApplication(radio, database)
|
application_controller = ControllerApplication(radio, database)
|
||||||
listener = ApplicationListener(hass, config)
|
listener = ApplicationListener(hass, config)
|
||||||
APPLICATION_CONTROLLER.add_listener(listener)
|
application_controller.add_listener(listener)
|
||||||
await APPLICATION_CONTROLLER.startup(auto_form=True)
|
await application_controller.startup(auto_form=True)
|
||||||
|
|
||||||
for device in APPLICATION_CONTROLLER.devices.values():
|
for device in application_controller.devices.values():
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
listener.async_device_initialized(device, False))
|
listener.async_device_initialized(device, False))
|
||||||
|
|
||||||
@ -168,14 +165,14 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
hass.helpers.device_registry.async_get_registry()
|
hass.helpers.device_registry.async_get_registry()
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=config_entry.entry_id,
|
config_entry_id=config_entry.entry_id,
|
||||||
connections={(CONNECTION_ZIGBEE, str(APPLICATION_CONTROLLER.ieee))},
|
connections={(CONNECTION_ZIGBEE, str(application_controller.ieee))},
|
||||||
identifiers={(DOMAIN, str(APPLICATION_CONTROLLER.ieee))},
|
identifiers={(DOMAIN, str(application_controller.ieee))},
|
||||||
name="Zigbee Coordinator",
|
name="Zigbee Coordinator",
|
||||||
manufacturer="ZHA",
|
manufacturer="ZHA",
|
||||||
model=radio_description,
|
model=radio_description,
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(APPLICATION_CONTROLLER.ieee)
|
hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(application_controller.ieee)
|
||||||
|
|
||||||
for component in COMPONENTS:
|
for component in COMPONENTS:
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
@ -187,7 +184,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
"""Allow devices to join this network."""
|
"""Allow devices to join this network."""
|
||||||
duration = service.data.get(ATTR_DURATION)
|
duration = service.data.get(ATTR_DURATION)
|
||||||
_LOGGER.info("Permitting joins for %ss", duration)
|
_LOGGER.info("Permitting joins for %ss", duration)
|
||||||
await APPLICATION_CONTROLLER.permit(duration)
|
await application_controller.permit(duration)
|
||||||
|
|
||||||
hass.services.async_register(DOMAIN, SERVICE_PERMIT, permit,
|
hass.services.async_register(DOMAIN, SERVICE_PERMIT, permit,
|
||||||
schema=SERVICE_SCHEMAS[SERVICE_PERMIT])
|
schema=SERVICE_SCHEMAS[SERVICE_PERMIT])
|
||||||
@ -198,7 +195,7 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
ieee = service.data.get(ATTR_IEEE)
|
ieee = service.data.get(ATTR_IEEE)
|
||||||
ieee = EmberEUI64([uint8_t(p, base=16) for p in ieee.split(':')])
|
ieee = EmberEUI64([uint8_t(p, base=16) for p in ieee.split(':')])
|
||||||
_LOGGER.info("Removing node %s", ieee)
|
_LOGGER.info("Removing node %s", ieee)
|
||||||
await APPLICATION_CONTROLLER.remove(ieee)
|
await application_controller.remove(ieee)
|
||||||
|
|
||||||
hass.services.async_register(DOMAIN, SERVICE_REMOVE, remove,
|
hass.services.async_register(DOMAIN, SERVICE_REMOVE, remove,
|
||||||
schema=SERVICE_SCHEMAS[SERVICE_REMOVE])
|
schema=SERVICE_SCHEMAS[SERVICE_REMOVE])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user