Skip to content

Commit

Permalink
Merge fe518ee into 208f1a4
Browse files Browse the repository at this point in the history
  • Loading branch information
dmulcahey committed Feb 6, 2019
2 parents 208f1a4 + fe518ee commit a299c48
Show file tree
Hide file tree
Showing 22 changed files with 1,744 additions and 1,561 deletions.
4 changes: 0 additions & 4 deletions .coveragerc
Expand Up @@ -658,7 +658,6 @@ omit =
homeassistant/components/zeroconf/*
homeassistant/components/zha/__init__.py
homeassistant/components/zha/api.py
homeassistant/components/zha/binary_sensor.py
homeassistant/components/zha/const.py
homeassistant/components/zha/core/const.py
homeassistant/components/zha/core/device.py
Expand All @@ -667,11 +666,8 @@ omit =
homeassistant/components/zha/core/listeners.py
homeassistant/components/zha/device_entity.py
homeassistant/components/zha/entity.py
homeassistant/components/zha/event.py
homeassistant/components/zha/fan.py
homeassistant/components/zha/light.py
homeassistant/components/zha/sensor.py
homeassistant/components/zha/switch.py
homeassistant/components/zigbee/*
homeassistant/components/zoneminder/*
homeassistant/components/zwave/util.py
Expand Down
45 changes: 35 additions & 10 deletions homeassistant/components/zha/__init__.py
Expand Up @@ -4,6 +4,7 @@
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/zha/
"""
import asyncio
import logging
import os
import types
Expand All @@ -17,14 +18,15 @@
# Loading the config flow file will register the flow
from . import config_flow # noqa # pylint: disable=unused-import
from . import api
from .core.gateway import ZHAGateway
from .const import (
from .core import ZHAGateway
from .core.const import (
COMPONENTS, CONF_BAUDRATE, CONF_DATABASE, CONF_DEVICE_CONFIG,
CONF_RADIO_TYPE, CONF_USB_PATH, DATA_ZHA, DATA_ZHA_BRIDGE_ID,
DATA_ZHA_CONFIG, DATA_ZHA_CORE_COMPONENT, DATA_ZHA_DISPATCHERS,
DATA_ZHA_RADIO, DEFAULT_BAUDRATE, DEFAULT_DATABASE_NAME,
DEFAULT_RADIO_TYPE, DOMAIN, RadioType, DATA_ZHA_CORE_EVENTS,
ENABLE_QUIRKS)
DEFAULT_RADIO_TYPE, DOMAIN, RadioType, DATA_ZHA_CORE_EVENTS, ENABLE_QUIRKS)
from .core.gateway import establish_device_mappings
from .core.listeners import populate_listener_registry

REQUIREMENTS = [
'bellows==0.7.0',
Expand Down Expand Up @@ -87,9 +89,16 @@ async def async_setup_entry(hass, config_entry):
Will automatically load components to support devices found on the network.
"""
establish_device_mappings()
populate_listener_registry()

for component in COMPONENTS:
hass.data[DATA_ZHA][component] = (
hass.data[DATA_ZHA].get(component, {})
)

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

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

if config.get(ENABLE_QUIRKS, True):
Expand Down Expand Up @@ -137,14 +146,32 @@ def zha_send_event(self, cluster, command, args):
ClusterPersistingListener
)

application_controller = ControllerApplication(radio, database)
zha_gateway = ZHAGateway(hass, config)
hass.bus.async_listen_once(
ha_const.EVENT_HOMEASSISTANT_START, zha_gateway.accept_zigbee_messages)

# Patch handle_message until zigpy can provide an event here
def handle_message(sender, is_reply, profile, cluster,
src_ep, dst_ep, tsn, command_id, args):
"""Handle message from a device."""
if sender.last_seen is None and not sender.initializing:
if sender.ieee in zha_gateway.devices:
device = zha_gateway.devices[sender.ieee]
device.update_available(True)
return sender.handle_message(
is_reply, profile, cluster, src_ep, dst_ep, tsn, command_id, args)

application_controller = ControllerApplication(radio, database)
application_controller.handle_message = handle_message
application_controller.add_listener(zha_gateway)
await application_controller.startup(auto_form=True)

hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(application_controller.ieee)

init_tasks = []
for device in application_controller.devices.values():
hass.async_create_task(
zha_gateway.async_device_initialized(device, False))
init_tasks.append(zha_gateway.async_device_initialized(device, False))
await asyncio.gather(*init_tasks)

device_registry = await \
hass.helpers.device_registry.async_get_registry()
Expand All @@ -157,8 +184,6 @@ def zha_send_event(self, cluster, command, args):
model=radio_description,
)

hass.data[DATA_ZHA][DATA_ZHA_BRIDGE_ID] = str(application_controller.ieee)

for component in COMPONENTS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(
Expand Down

0 comments on commit a299c48

Please sign in to comment.