From 5b0255525579060c2bcb25ca404390667d723b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20RAMAGE?= Date: Tue, 6 Aug 2019 00:05:07 +0200 Subject: [PATCH] Add zigate support to zha (#25552) * Add zigpy-zigate support * update requirements * fix * update * fix flake8 * update requirements * fix * update * add test to make codecov happy * fix flake8 * Try to add test * add test * remove unneeded test * exclude registries.py from coverage exclude homeassistant/components/zha/core/registries.py since untestable * Fix merge: black formatting and flake8. --- .coveragerc | 1 + homeassistant/components/zha/core/const.py | 3 ++ homeassistant/components/zha/core/gateway.py | 5 +++ homeassistant/components/zha/core/helpers.py | 5 +++ .../components/zha/core/registries.py | 36 +++++++++++++------ homeassistant/components/zha/manifest.json | 3 +- requirements_all.txt | 3 ++ 7 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.coveragerc b/.coveragerc index abd29a8614b..75b97e8f5e1 100644 --- a/.coveragerc +++ b/.coveragerc @@ -741,6 +741,7 @@ omit = homeassistant/components/zha/core/device.py homeassistant/components/zha/core/gateway.py homeassistant/components/zha/core/helpers.py + homeassistant/components/zha/core/registries.py homeassistant/components/zha/device_entity.py homeassistant/components/zha/entity.py homeassistant/components/zha/light.py diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py index 7a4f5f94897..c35cb168fdf 100644 --- a/homeassistant/components/zha/core/const.py +++ b/homeassistant/components/zha/core/const.py @@ -79,6 +79,7 @@ DEBUG_COMP_ZHA = "homeassistant.components.zha" DEBUG_COMP_ZIGPY = "zigpy" DEBUG_COMP_ZIGPY_DECONZ = "zigpy_deconz" DEBUG_COMP_ZIGPY_XBEE = "zigpy_xbee" +DEBUG_COMP_ZIGPY_ZIGATE = "zigpy_zigate" DEBUG_LEVEL_CURRENT = "current" DEBUG_LEVEL_ORIGINAL = "original" DEBUG_LEVELS = { @@ -87,6 +88,7 @@ DEBUG_LEVELS = { DEBUG_COMP_ZIGPY: logging.DEBUG, DEBUG_COMP_ZIGPY_XBEE: logging.DEBUG, DEBUG_COMP_ZIGPY_DECONZ: logging.DEBUG, + DEBUG_COMP_ZIGPY_ZIGATE: logging.DEBUG, } DEBUG_RELAY_LOGGERS = [DEBUG_COMP_ZHA, DEBUG_COMP_ZIGPY] @@ -109,6 +111,7 @@ class RadioType(enum.Enum): ezsp = "ezsp" xbee = "xbee" deconz = "deconz" + zigate = "zigate" @classmethod def list(cls): diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 7eff3ebcf3b..7adceb13f54 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -41,6 +41,7 @@ from .const import ( DEBUG_COMP_ZIGPY, DEBUG_COMP_ZIGPY_DECONZ, DEBUG_COMP_ZIGPY_XBEE, + DEBUG_COMP_ZIGPY_ZIGATE, DEBUG_LEVEL_CURRENT, DEBUG_LEVEL_ORIGINAL, DEBUG_LEVELS, @@ -412,6 +413,9 @@ def async_capture_log_levels(): DEBUG_COMP_ZIGPY_DECONZ: logging.getLogger( DEBUG_COMP_ZIGPY_DECONZ ).getEffectiveLevel(), + DEBUG_COMP_ZIGPY_ZIGATE: logging.getLogger( + DEBUG_COMP_ZIGPY_ZIGATE + ).getEffectiveLevel(), } @@ -423,6 +427,7 @@ def async_set_logger_levels(levels): logging.getLogger(DEBUG_COMP_ZIGPY).setLevel(levels[DEBUG_COMP_ZIGPY]) logging.getLogger(DEBUG_COMP_ZIGPY_XBEE).setLevel(levels[DEBUG_COMP_ZIGPY_XBEE]) logging.getLogger(DEBUG_COMP_ZIGPY_DECONZ).setLevel(levels[DEBUG_COMP_ZIGPY_DECONZ]) + logging.getLogger(DEBUG_COMP_ZIGPY_ZIGATE).setLevel(levels[DEBUG_COMP_ZIGPY_ZIGATE]) class LogRelayHandler(logging.Handler): diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index 7a1791adc56..3899d601017 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -56,6 +56,11 @@ async def check_zigpy_connection(usb_path, radio_type, database_path): from zigpy_deconz.zigbee.application import ControllerApplication radio = zigpy_deconz.api.Deconz() + elif radio_type == RadioType.zigate.name: + import zigpy_zigate.api + from zigpy_zigate.zigbee.application import ControllerApplication + + radio = zigpy_zigate.api.ZiGate() try: await radio.connect(usb_path, DEFAULT_BAUDRATE) controller = ControllerApplication(radio, database_path) diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 1e1d111fa3e..757a6c3e43f 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -93,17 +93,6 @@ def establish_device_mappings(): ZHA_GW_RADIO_DESCRIPTION: "EZSP", } - def get_xbee_radio(): - import zigpy_xbee.api - from zigpy_xbee.zigbee.application import ControllerApplication - - return {ZHA_GW_RADIO: zigpy_xbee.api.XBee(), CONTROLLER: ControllerApplication} - - RADIO_TYPES[RadioType.xbee.name] = { - ZHA_GW_RADIO: get_xbee_radio, - ZHA_GW_RADIO_DESCRIPTION: "XBee", - } - def get_deconz_radio(): import zigpy_deconz.api from zigpy_deconz.zigbee.application import ControllerApplication @@ -118,6 +107,31 @@ def establish_device_mappings(): ZHA_GW_RADIO_DESCRIPTION: "Deconz", } + def get_xbee_radio(): + import zigpy_xbee.api + from zigpy_xbee.zigbee.application import ControllerApplication + + return {ZHA_GW_RADIO: zigpy_xbee.api.XBee(), CONTROLLER: ControllerApplication} + + RADIO_TYPES[RadioType.xbee.name] = { + ZHA_GW_RADIO: get_xbee_radio, + ZHA_GW_RADIO_DESCRIPTION: "XBee", + } + + def get_zigate_radio(): + import zigpy_zigate.api + from zigpy_zigate.zigbee.application import ControllerApplication + + return { + ZHA_GW_RADIO: zigpy_zigate.api.ZiGate(), + CONTROLLER: ControllerApplication, + } + + RADIO_TYPES[RadioType.zigate.name] = { + ZHA_GW_RADIO: get_zigate_radio, + ZHA_GW_RADIO_DESCRIPTION: "ZiGate", + } + BINARY_SENSOR_CLUSTERS.add(SMARTTHINGS_ACCELERATION_CLUSTER) BINARY_SENSOR_CLUSTERS.add(zcl.clusters.general.OnOff.cluster_id) BINARY_SENSOR_CLUSTERS.add(zcl.clusters.measurement.OccupancySensing.cluster_id) diff --git a/homeassistant/components/zha/manifest.json b/homeassistant/components/zha/manifest.json index 88c5f171116..081c77362b9 100644 --- a/homeassistant/components/zha/manifest.json +++ b/homeassistant/components/zha/manifest.json @@ -8,7 +8,8 @@ "zha-quirks==0.0.20", "zigpy-deconz==0.2.1", "zigpy-homeassistant==0.7.0", - "zigpy-xbee-homeassistant==0.4.0" + "zigpy-xbee-homeassistant==0.4.0", + "zigpy-zigate==0.1.0" ], "dependencies": [], "codeowners": ["@dmulcahey", "@adminiuga"] diff --git a/requirements_all.txt b/requirements_all.txt index 402bba48314..4019393cf16 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1985,5 +1985,8 @@ zigpy-homeassistant==0.7.0 # homeassistant.components.zha zigpy-xbee-homeassistant==0.4.0 +# homeassistant.components.zha +zigpy-zigate==0.1.0 + # homeassistant.components.zoneminder zm-py==0.3.3