From 89c96279ce54950b8078775535c32266cc3cf5b9 Mon Sep 17 00:00:00 2001 From: "David F. Mulcahey" Date: Thu, 14 Mar 2019 21:00:49 -0400 Subject: [PATCH] Cleanup remaining constants stuff in ZHA (#22050) * clean up constants * fix quirks until it can be upgradded --- homeassistant/components/zha/const.py | 1 + .../components/zha/core/channels/__init__.py | 5 ++-- .../components/zha/core/channels/general.py | 6 ++--- homeassistant/components/zha/core/const.py | 12 ---------- .../components/zha/core/discovery.py | 23 ++++++++++--------- homeassistant/components/zha/core/gateway.py | 11 +++++---- homeassistant/components/zha/core/helpers.py | 4 +++- .../components/zha/core/registries.py | 23 +++++++++++++------ 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/homeassistant/components/zha/const.py b/homeassistant/components/zha/const.py index abcd17a0461..e7cf424990b 100644 --- a/homeassistant/components/zha/const.py +++ b/homeassistant/components/zha/const.py @@ -6,3 +6,4 @@ at https://home-assistant.io/components/fan.zha/ """ # pylint: disable=W0614,W0401 from .core.const import * # noqa: F401,F403 +from .core.registries import * # noqa: F401,F403 diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 92518bd33ff..ef3ef71477f 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -17,9 +17,10 @@ from ..helpers import ( bind_configure_reporting, construct_unique_id, safe_read, get_attr_id_by_name) from ..const import ( - CLUSTER_REPORT_CONFIGS, REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, - ATTRIBUTE_CHANNEL, EVENT_RELAY_CHANNEL, ZDO_CHANNEL + REPORT_CONFIG_DEFAULT, SIGNAL_ATTR_UPDATED, ATTRIBUTE_CHANNEL, + EVENT_RELAY_CHANNEL, ZDO_CHANNEL ) +from ..registries import CLUSTER_REPORT_CONFIGS NODE_DESCRIPTOR_REQUEST = 0x0002 MAINS_POWERED = 1 diff --git a/homeassistant/components/zha/core/channels/general.py b/homeassistant/components/zha/core/channels/general.py index cd16fe5d22e..c0b0367be99 100644 --- a/homeassistant/components/zha/core/channels/general.py +++ b/homeassistant/components/zha/core/channels/general.py @@ -10,9 +10,9 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send from . import ZigbeeChannel, parse_and_log_command from ..helpers import get_attr_id_by_name from ..const import ( - SIGNAL_ATTR_UPDATED, - SIGNAL_MOVE_LEVEL, SIGNAL_SET_LEVEL, SIGNAL_STATE_ATTR, BASIC_CHANNEL, - ON_OFF_CHANNEL, LEVEL_CHANNEL, POWER_CONFIGURATION_CHANNEL + SIGNAL_ATTR_UPDATED, SIGNAL_MOVE_LEVEL, SIGNAL_SET_LEVEL, + SIGNAL_STATE_ATTR, BASIC_CHANNEL, ON_OFF_CHANNEL, LEVEL_CHANNEL, + POWER_CONFIGURATION_CHANNEL ) _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py index 521bd529e30..c5837cc33e7 100644 --- a/homeassistant/components/zha/core/const.py +++ b/homeassistant/components/zha/core/const.py @@ -121,18 +121,6 @@ class RadioType(enum.Enum): DISCOVERY_KEY = 'zha_discovery_info' -DEVICE_CLASS = {} -SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {} -SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {} -SENSOR_TYPES = {} -RADIO_TYPES = {} -BINARY_SENSOR_TYPES = {} -CLUSTER_REPORT_CONFIGS = {} -CUSTOM_CLUSTER_MAPPINGS = {} -COMPONENT_CLUSTERS = {} -EVENT_RELAY_CLUSTERS = [] -NO_SENSOR_CLUSTERS = [] -BINDABLE_CLUSTERS = [] REPORT_CONFIG_MAX_INT = 900 REPORT_CONFIG_MAX_INT_BATTERY_SAVE = 10800 diff --git a/homeassistant/components/zha/core/discovery.py b/homeassistant/components/zha/core/discovery.py index 6d35fa24615..f5bd6ee99f2 100644 --- a/homeassistant/components/zha/core/discovery.py +++ b/homeassistant/components/zha/core/discovery.py @@ -10,16 +10,18 @@ import logging from homeassistant import const as ha_const from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send -from . import const as zha_const from .channels import ( AttributeListeningChannel, EventRelayChannel, ZDOChannel ) from .channels.registry import ZIGBEE_CHANNEL_REGISTRY from .const import ( CONF_DEVICE_CONFIG, COMPONENTS, ZHA_DISCOVERY_NEW, DATA_ZHA, - SENSOR_TYPE, UNKNOWN, BINARY_SENSOR_TYPES, NO_SENSOR_CLUSTERS, - EVENT_RELAY_CLUSTERS, SENSOR_TYPES, GENERIC, - POWER_CONFIGURATION_CHANNEL + SENSOR_TYPE, UNKNOWN, GENERIC, POWER_CONFIGURATION_CHANNEL +) +from .registries import ( + BINARY_SENSOR_TYPES, NO_SENSOR_CLUSTERS, EVENT_RELAY_CLUSTERS, + SENSOR_TYPES, DEVICE_CLASS, COMPONENT_CLUSTERS, + SINGLE_INPUT_CLUSTER_DEVICE_CLASS, SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS ) from ..device_entity import ZhaDeviceEntity @@ -53,16 +55,15 @@ def async_process_endpoint( if endpoint.profile_id in zigpy.profiles.PROFILES: profile = zigpy.profiles.PROFILES[endpoint.profile_id] - if zha_const.DEVICE_CLASS.get(endpoint.profile_id, - {}).get(endpoint.device_type, - None): + if DEVICE_CLASS.get(endpoint.profile_id, {}).get( + endpoint.device_type, None): profile_clusters = profile.CLUSTERS[endpoint.device_type] - profile_info = zha_const.DEVICE_CLASS[endpoint.profile_id] + profile_info = DEVICE_CLASS[endpoint.profile_id] component = profile_info[endpoint.device_type] if ha_const.CONF_TYPE in node_config: component = node_config[ha_const.CONF_TYPE] - profile_clusters = zha_const.COMPONENT_CLUSTERS[component] + profile_clusters = COMPONENT_CLUSTERS[component] if component and component in COMPONENTS: profile_match = _async_handle_profile_match( @@ -179,7 +180,7 @@ def _async_handle_single_cluster_matches(hass, endpoint, zha_device, zha_device, cluster, device_key, - zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS, + SINGLE_INPUT_CLUSTER_DEVICE_CLASS, is_new_join, )) @@ -190,7 +191,7 @@ def _async_handle_single_cluster_matches(hass, endpoint, zha_device, zha_device, cluster, device_key, - zha_const.SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS, + SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS, is_new_join, )) diff --git a/homeassistant/components/zha/core/gateway.py b/homeassistant/components/zha/core/gateway.py index 89b2d9b77a6..adaab0e6616 100644 --- a/homeassistant/components/zha/core/gateway.py +++ b/homeassistant/components/zha/core/gateway.py @@ -15,11 +15,11 @@ from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.entity_component import EntityComponent from .const import ( - DATA_ZHA, DATA_ZHA_CORE_COMPONENT, DOMAIN, - SIGNAL_REMOVE, DATA_ZHA_GATEWAY, CONF_USB_PATH, CONF_BAUDRATE, - DEFAULT_BAUDRATE, CONF_RADIO_TYPE, DATA_ZHA_RADIO, CONF_DATABASE, - DEFAULT_DATABASE_NAME, DATA_ZHA_BRIDGE_ID, RADIO_TYPES, - RADIO, CONTROLLER, RADIO_DESCRIPTION) + DATA_ZHA, DATA_ZHA_CORE_COMPONENT, DOMAIN, SIGNAL_REMOVE, DATA_ZHA_GATEWAY, + CONF_USB_PATH, CONF_BAUDRATE, DEFAULT_BAUDRATE, CONF_RADIO_TYPE, + DATA_ZHA_RADIO, CONF_DATABASE, DEFAULT_DATABASE_NAME, DATA_ZHA_BRIDGE_ID, + RADIO, CONTROLLER, RADIO_DESCRIPTION +) from .device import ZHADevice, DeviceStatus from .channels import ( ZDOChannel, MAINS_POWERED @@ -31,6 +31,7 @@ from .discovery import ( ) from .store import async_get_registry from .patches import apply_application_controller_patch +from .registries import RADIO_TYPES _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/core/helpers.py b/homeassistant/components/zha/core/helpers.py index d6e9cc32338..b00626031ed 100644 --- a/homeassistant/components/zha/core/helpers.py +++ b/homeassistant/components/zha/core/helpers.py @@ -11,7 +11,9 @@ from concurrent.futures import TimeoutError as Timeout from homeassistant.core import callback from .const import ( DEFAULT_BAUDRATE, REPORT_CONFIG_MAX_INT, REPORT_CONFIG_MIN_INT, - REPORT_CONFIG_RPT_CHANGE, RadioType, IN, OUT, BINDABLE_CLUSTERS) + REPORT_CONFIG_RPT_CHANGE, RadioType, IN, OUT +) +from .registries import BINDABLE_CLUSTERS _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/core/registries.py b/homeassistant/components/zha/core/registries.py index 4d6b1faba00..3cbd31aa304 100644 --- a/homeassistant/components/zha/core/registries.py +++ b/homeassistant/components/zha/core/registries.py @@ -6,21 +6,30 @@ https://home-assistant.io/components/zha/ """ from .const import ( - DEVICE_CLASS, SINGLE_INPUT_CLUSTER_DEVICE_CLASS, - SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS, COMPONENT_CLUSTERS, HUMIDITY, + HUMIDITY, TEMPERATURE, ILLUMINANCE, PRESSURE, METERING, ELECTRICAL_MEASUREMENT, - EVENT_RELAY_CLUSTERS, OPENING, ZONE, - OCCUPANCY, CLUSTER_REPORT_CONFIGS, REPORT_CONFIG_IMMEDIATE, + OCCUPANCY, REPORT_CONFIG_IMMEDIATE, OPENING, ZONE, RADIO_DESCRIPTION, REPORT_CONFIG_ASAP, REPORT_CONFIG_DEFAULT, REPORT_CONFIG_MIN_INT, - REPORT_CONFIG_MAX_INT, REPORT_CONFIG_OP, - NO_SENSOR_CLUSTERS, BINDABLE_CLUSTERS, ACCELERATION, SENSOR_TYPES, - BINARY_SENSOR_TYPES, RADIO_TYPES, RadioType, RADIO, RADIO_DESCRIPTION, + REPORT_CONFIG_MAX_INT, REPORT_CONFIG_OP, ACCELERATION, RadioType, RADIO, CONTROLLER ) SMARTTHINGS_HUMIDITY_CLUSTER = 64581 SMARTTHINGS_ACCELERATION_CLUSTER = 64514 +DEVICE_CLASS = {} +SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {} +SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {} +SENSOR_TYPES = {} +RADIO_TYPES = {} +BINARY_SENSOR_TYPES = {} +CLUSTER_REPORT_CONFIGS = {} +CUSTOM_CLUSTER_MAPPINGS = {} +COMPONENT_CLUSTERS = {} +EVENT_RELAY_CLUSTERS = [] +NO_SENSOR_CLUSTERS = [] +BINDABLE_CLUSTERS = [] + def establish_device_mappings(): """Establish mappings between ZCL objects and HA ZHA objects.