Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
DATA_ZHA_CONFIG, DATA_ZHA_CORE_COMPONENT, DATA_ZHA_DISPATCHERS,
DATA_ZHA_RADIO, DEFAULT_BAUDRATE, DEFAULT_DATABASE_NAME,
DEFAULT_RADIO_TYPE, DOMAIN, ZHA_DISCOVERY_NEW, RadioType,
EVENTABLE_CLUSTERS, DATA_ZHA_CORE_EVENTS, ENABLE_QUIRKS)
EVENTABLE_CLUSTERS, DATA_ZHA_CORE_EVENTS, ENABLE_QUIRKS,
APPLICATION_CONTROLLER)

REQUIREMENTS = [
'bellows==0.7.0',
Expand Down Expand Up @@ -76,7 +77,6 @@
CENTICELSIUS = 'C-100'

# Internal definitions
APPLICATION_CONTROLLER = None
_LOGGER = logging.getLogger(__name__)


Expand All @@ -89,6 +89,7 @@ async def async_setup(hass, config):

conf = config[DOMAIN]
hass.data[DATA_ZHA][DATA_ZHA_CONFIG] = conf
hass.data[DATA_ZHA][APPLICATION_CONTROLLER] = None
Comment thread
dmulcahey marked this conversation as resolved.
Outdated

if not hass.config_entries.async_entries(DOMAIN):
hass.async_create_task(hass.config_entries.flow.async_init(
Expand All @@ -114,8 +115,6 @@ async def async_setup_entry(hass, config_entry):
# pylint: disable=W0611, W0612
import zhaquirks # noqa

global APPLICATION_CONTROLLER

hass.data[DATA_ZHA] = hass.data.get(DATA_ZHA, {})
hass.data[DATA_ZHA][DATA_ZHA_DISPATCHERS] = []

Expand Down Expand Up @@ -155,27 +154,28 @@ def zha_send_event(self, cluster, command, args):
ClusterPersistingListener
)

APPLICATION_CONTROLLER = ControllerApplication(radio, database)
application_controller = ControllerApplication(radio, database)
hass.data[DATA_ZHA][APPLICATION_CONTROLLER] = application_controller
listener = ApplicationListener(hass, config)
APPLICATION_CONTROLLER.add_listener(listener)
await APPLICATION_CONTROLLER.startup(auto_form=True)
application_controller.add_listener(listener)
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(
listener.async_device_initialized(device, False))

device_registry = await \
hass.helpers.device_registry.async_get_registry()
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_ZIGBEE, str(APPLICATION_CONTROLLER.ieee))},
identifiers={(DOMAIN, str(APPLICATION_CONTROLLER.ieee))},
connections={(CONNECTION_ZIGBEE, str(application_controller.ieee))},
identifiers={(DOMAIN, str(application_controller.ieee))},
name="Zigbee Coordinator",
manufacturer="ZHA",
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:
hass.async_create_task(
Expand All @@ -187,7 +187,7 @@ async def permit(service):
"""Allow devices to join this network."""
duration = service.data.get(ATTR_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,
schema=SERVICE_SCHEMAS[SERVICE_PERMIT])
Expand All @@ -198,7 +198,7 @@ async def remove(service):
ieee = service.data.get(ATTR_IEEE)
ieee = EmberEUI64([uint8_t(p, base=16) for p in ieee.split(':')])
_LOGGER.info("Removing node %s", ieee)
await APPLICATION_CONTROLLER.remove(ieee)
await application_controller.remove(ieee)

hass.services.async_register(DOMAIN, SERVICE_REMOVE, remove,
schema=SERVICE_SCHEMAS[SERVICE_REMOVE])
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/zha/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DATA_ZHA_CORE_COMPONENT = 'zha_core_component'
DATA_ZHA_CORE_EVENTS = 'zha_core_events'
ZHA_DISCOVERY_NEW = 'zha_discovery_new_{}'
APPLICATION_CONTROLLER = 'application_controller'

COMPONENTS = [
'binary_sensor',
Expand Down