diff --git a/.coveragerc b/.coveragerc index e6a1c752f87..161b62c1896 100644 --- a/.coveragerc +++ b/.coveragerc @@ -448,8 +448,11 @@ omit = homeassistant/components/zha/sensor.py homeassistant/components/zha/switch.py homeassistant/components/zha/api.py - homeassistant/components/zha/entities/* - homeassistant/components/zha/helpers.py + homeassistant/components/zha/entity.py + homeassistant/components/zha/device_entity.py + homeassistant/components/zha/core/helpers.py + homeassistant/components/zha/core/const.py + homeassistant/components/zha/core/listeners.py homeassistant/components/*/zha.py homeassistant/components/zigbee.py diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 335295b2c2c..486274a4163 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -22,8 +22,8 @@ from . import config_flow # noqa # pylint: disable=unused-import from . import const as zha_const from .event import ZhaEvent, ZhaRelayEvent from . import api -from .helpers import convert_ieee -from .entities import ZhaDeviceEntity +from .core.helpers import convert_ieee +from .device_entity import ZhaDeviceEntity from .const import ( COMPONENTS, CONF_BAUDRATE, CONF_DATABASE, CONF_DEVICE_CONFIG, CONF_RADIO_TYPE, CONF_USB_PATH, DATA_ZHA, DATA_ZHA_BRIDGE_ID, diff --git a/homeassistant/components/zha/api.py b/homeassistant/components/zha/api.py index 308c221bf2f..0312a40967f 100644 --- a/homeassistant/components/zha/api.py +++ b/homeassistant/components/zha/api.py @@ -11,7 +11,7 @@ import voluptuous as vol from homeassistant.components import websocket_api from homeassistant.const import ATTR_ENTITY_ID import homeassistant.helpers.config_validation as cv -from .entities import ZhaDeviceEntity +from .device_entity import ZhaDeviceEntity from .const import ( DOMAIN, ATTR_CLUSTER_ID, ATTR_CLUSTER_TYPE, ATTR_ATTRIBUTE, ATTR_VALUE, ATTR_MANUFACTURER, ATTR_COMMAND, ATTR_COMMAND_TYPE, ATTR_ARGS, IN, OUT, diff --git a/homeassistant/components/zha/binary_sensor.py b/homeassistant/components/zha/binary_sensor.py index fce9376700e..d0f23ff3dd2 100644 --- a/homeassistant/components/zha/binary_sensor.py +++ b/homeassistant/components/zha/binary_sensor.py @@ -10,11 +10,11 @@ from homeassistant.components.binary_sensor import DOMAIN, BinarySensorDevice from homeassistant.const import STATE_ON from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.restore_state import RestoreEntity -from . import helpers -from .const import ( +from .core import helpers +from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, REPORT_CONFIG_IMMEDIATE, ZHA_DISCOVERY_NEW) -from .entities import ZhaEntity -from .entities.listeners import ( +from .entity import ZhaEntity +from .core.listeners import ( OnOffListener, LevelListener ) diff --git a/homeassistant/components/zha/config_flow.py b/homeassistant/components/zha/config_flow.py index 1c903ec3056..d995a2179fe 100644 --- a/homeassistant/components/zha/config_flow.py +++ b/homeassistant/components/zha/config_flow.py @@ -6,9 +6,9 @@ import voluptuous as vol from homeassistant import config_entries -from .const import ( +from .core.const import ( CONF_RADIO_TYPE, CONF_USB_PATH, DEFAULT_DATABASE_NAME, DOMAIN, RadioType) -from .helpers import check_zigpy_connection +from .core.helpers import check_zigpy_connection @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/zha/const.py b/homeassistant/components/zha/const.py index 47c3982c5d6..abcd17a0461 100644 --- a/homeassistant/components/zha/const.py +++ b/homeassistant/components/zha/const.py @@ -1,95 +1,8 @@ -"""All constants related to the ZHA component.""" -import enum +""" +Backwards compatible constants bridge. -DOMAIN = 'zha' - -BAUD_RATES = [ - 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, 256000 -] - -DATA_ZHA = 'zha' -DATA_ZHA_CONFIG = 'config' -DATA_ZHA_BRIDGE_ID = 'zha_bridge_id' -DATA_ZHA_RADIO = 'zha_radio' -DATA_ZHA_DISPATCHERS = 'zha_dispatchers' -DATA_ZHA_CORE_COMPONENT = 'zha_core_component' -DATA_ZHA_CORE_EVENTS = 'zha_core_events' -ZHA_DISCOVERY_NEW = 'zha_discovery_new_{}' - -COMPONENTS = [ - 'binary_sensor', - 'fan', - 'light', - 'sensor', - 'switch', -] - -CONF_BAUDRATE = 'baudrate' -CONF_DATABASE = 'database_path' -CONF_DEVICE_CONFIG = 'device_config' -CONF_RADIO_TYPE = 'radio_type' -CONF_USB_PATH = 'usb_path' -DATA_DEVICE_CONFIG = 'zha_device_config' -ENABLE_QUIRKS = 'enable_quirks' - -DEFAULT_RADIO_TYPE = 'ezsp' -DEFAULT_BAUDRATE = 57600 -DEFAULT_DATABASE_NAME = 'zigbee.db' - -ATTR_CLUSTER_ID = 'cluster_id' -ATTR_CLUSTER_TYPE = 'cluster_type' -ATTR_ATTRIBUTE = 'attribute' -ATTR_VALUE = 'value' -ATTR_MANUFACTURER = 'manufacturer' -ATTR_COMMAND = 'command' -ATTR_COMMAND_TYPE = 'command_type' -ATTR_ARGS = 'args' - -IN = 'in' -OUT = 'out' -CLIENT_COMMANDS = 'client_commands' -SERVER_COMMANDS = 'server_commands' -SERVER = 'server' - - -class RadioType(enum.Enum): - """Possible options for radio type.""" - - ezsp = 'ezsp' - xbee = 'xbee' - deconz = 'deconz' - - @classmethod - def list(cls): - """Return list of enum's values.""" - return [e.value for e in RadioType] - - -DISCOVERY_KEY = 'zha_discovery_info' -DEVICE_CLASS = {} -SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {} -SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {} -CUSTOM_CLUSTER_MAPPINGS = {} -COMPONENT_CLUSTERS = {} -EVENTABLE_CLUSTERS = [] - -REPORT_CONFIG_MAX_INT = 900 -REPORT_CONFIG_MAX_INT_BATTERY_SAVE = 10800 -REPORT_CONFIG_MIN_INT = 30 -REPORT_CONFIG_MIN_INT_ASAP = 1 -REPORT_CONFIG_MIN_INT_IMMEDIATE = 0 -REPORT_CONFIG_MIN_INT_OP = 5 -REPORT_CONFIG_MIN_INT_BATTERY_SAVE = 3600 -REPORT_CONFIG_RPT_CHANGE = 1 -REPORT_CONFIG_DEFAULT = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, - REPORT_CONFIG_RPT_CHANGE) -REPORT_CONFIG_ASAP = (REPORT_CONFIG_MIN_INT_ASAP, REPORT_CONFIG_MAX_INT, - REPORT_CONFIG_RPT_CHANGE) -REPORT_CONFIG_BATTERY_SAVE = (REPORT_CONFIG_MIN_INT_BATTERY_SAVE, - REPORT_CONFIG_MAX_INT, - REPORT_CONFIG_RPT_CHANGE) -REPORT_CONFIG_IMMEDIATE = (REPORT_CONFIG_MIN_INT_IMMEDIATE, - REPORT_CONFIG_MAX_INT, - REPORT_CONFIG_RPT_CHANGE) -REPORT_CONFIG_OP = (REPORT_CONFIG_MIN_INT_OP, REPORT_CONFIG_MAX_INT, - REPORT_CONFIG_RPT_CHANGE) +For more details on this platform, please refer to the documentation +at https://home-assistant.io/components/fan.zha/ +""" +# pylint: disable=W0614,W0401 +from .core.const import * # noqa: F401,F403 diff --git a/homeassistant/components/zha/entities/__init__.py b/homeassistant/components/zha/core/__init__.py similarity index 50% rename from homeassistant/components/zha/entities/__init__.py rename to homeassistant/components/zha/core/__init__.py index c3c3ea163ed..47e6ed2b0ee 100644 --- a/homeassistant/components/zha/entities/__init__.py +++ b/homeassistant/components/zha/core/__init__.py @@ -1,10 +1,6 @@ """ -Entities for Zigbee Home Automation. +Core module for Zigbee Home Automation. For more details about this component, please refer to the documentation at https://home-assistant.io/components/zha/ """ - -# flake8: noqa -from .device_entity import ZhaDeviceEntity -from .entity import ZhaEntity diff --git a/homeassistant/components/zha/core/const.py b/homeassistant/components/zha/core/const.py new file mode 100644 index 00000000000..47c3982c5d6 --- /dev/null +++ b/homeassistant/components/zha/core/const.py @@ -0,0 +1,95 @@ +"""All constants related to the ZHA component.""" +import enum + +DOMAIN = 'zha' + +BAUD_RATES = [ + 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, 256000 +] + +DATA_ZHA = 'zha' +DATA_ZHA_CONFIG = 'config' +DATA_ZHA_BRIDGE_ID = 'zha_bridge_id' +DATA_ZHA_RADIO = 'zha_radio' +DATA_ZHA_DISPATCHERS = 'zha_dispatchers' +DATA_ZHA_CORE_COMPONENT = 'zha_core_component' +DATA_ZHA_CORE_EVENTS = 'zha_core_events' +ZHA_DISCOVERY_NEW = 'zha_discovery_new_{}' + +COMPONENTS = [ + 'binary_sensor', + 'fan', + 'light', + 'sensor', + 'switch', +] + +CONF_BAUDRATE = 'baudrate' +CONF_DATABASE = 'database_path' +CONF_DEVICE_CONFIG = 'device_config' +CONF_RADIO_TYPE = 'radio_type' +CONF_USB_PATH = 'usb_path' +DATA_DEVICE_CONFIG = 'zha_device_config' +ENABLE_QUIRKS = 'enable_quirks' + +DEFAULT_RADIO_TYPE = 'ezsp' +DEFAULT_BAUDRATE = 57600 +DEFAULT_DATABASE_NAME = 'zigbee.db' + +ATTR_CLUSTER_ID = 'cluster_id' +ATTR_CLUSTER_TYPE = 'cluster_type' +ATTR_ATTRIBUTE = 'attribute' +ATTR_VALUE = 'value' +ATTR_MANUFACTURER = 'manufacturer' +ATTR_COMMAND = 'command' +ATTR_COMMAND_TYPE = 'command_type' +ATTR_ARGS = 'args' + +IN = 'in' +OUT = 'out' +CLIENT_COMMANDS = 'client_commands' +SERVER_COMMANDS = 'server_commands' +SERVER = 'server' + + +class RadioType(enum.Enum): + """Possible options for radio type.""" + + ezsp = 'ezsp' + xbee = 'xbee' + deconz = 'deconz' + + @classmethod + def list(cls): + """Return list of enum's values.""" + return [e.value for e in RadioType] + + +DISCOVERY_KEY = 'zha_discovery_info' +DEVICE_CLASS = {} +SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {} +SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {} +CUSTOM_CLUSTER_MAPPINGS = {} +COMPONENT_CLUSTERS = {} +EVENTABLE_CLUSTERS = [] + +REPORT_CONFIG_MAX_INT = 900 +REPORT_CONFIG_MAX_INT_BATTERY_SAVE = 10800 +REPORT_CONFIG_MIN_INT = 30 +REPORT_CONFIG_MIN_INT_ASAP = 1 +REPORT_CONFIG_MIN_INT_IMMEDIATE = 0 +REPORT_CONFIG_MIN_INT_OP = 5 +REPORT_CONFIG_MIN_INT_BATTERY_SAVE = 3600 +REPORT_CONFIG_RPT_CHANGE = 1 +REPORT_CONFIG_DEFAULT = (REPORT_CONFIG_MIN_INT, REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_RPT_CHANGE) +REPORT_CONFIG_ASAP = (REPORT_CONFIG_MIN_INT_ASAP, REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_RPT_CHANGE) +REPORT_CONFIG_BATTERY_SAVE = (REPORT_CONFIG_MIN_INT_BATTERY_SAVE, + REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_RPT_CHANGE) +REPORT_CONFIG_IMMEDIATE = (REPORT_CONFIG_MIN_INT_IMMEDIATE, + REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_RPT_CHANGE) +REPORT_CONFIG_OP = (REPORT_CONFIG_MIN_INT_OP, REPORT_CONFIG_MAX_INT, + REPORT_CONFIG_RPT_CHANGE) diff --git a/homeassistant/components/zha/helpers.py b/homeassistant/components/zha/core/helpers.py similarity index 100% rename from homeassistant/components/zha/helpers.py rename to homeassistant/components/zha/core/helpers.py diff --git a/homeassistant/components/zha/entities/listeners.py b/homeassistant/components/zha/core/listeners.py similarity index 100% rename from homeassistant/components/zha/entities/listeners.py rename to homeassistant/components/zha/core/listeners.py diff --git a/homeassistant/components/zha/entities/device_entity.py b/homeassistant/components/zha/device_entity.py similarity index 100% rename from homeassistant/components/zha/entities/device_entity.py rename to homeassistant/components/zha/device_entity.py diff --git a/homeassistant/components/zha/entities/entity.py b/homeassistant/components/zha/entity.py similarity index 99% rename from homeassistant/components/zha/entities/entity.py rename to homeassistant/components/zha/entity.py index 8f8c8e58e05..e112e32d592 100644 --- a/homeassistant/components/zha/entities/entity.py +++ b/homeassistant/components/zha/entity.py @@ -13,11 +13,11 @@ from homeassistant.core import callback from homeassistant.helpers import entity from homeassistant.helpers.device_registry import CONNECTION_ZIGBEE from homeassistant.util import slugify -from ..const import ( +from .core.const import ( DATA_ZHA, DATA_ZHA_BRIDGE_ID, DOMAIN, ATTR_CLUSTER_ID, ATTR_ATTRIBUTE, ATTR_VALUE, ATTR_MANUFACTURER, ATTR_COMMAND, SERVER, ATTR_COMMAND_TYPE, ATTR_ARGS, IN, OUT, CLIENT_COMMANDS, SERVER_COMMANDS) -from ..helpers import bind_configure_reporting +from .core.helpers import bind_configure_reporting _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 630ab3f7bb9..f6dbef50923 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -10,10 +10,10 @@ from homeassistant.components.fan import ( DOMAIN, SPEED_HIGH, SPEED_LOW, SPEED_MEDIUM, SPEED_OFF, SUPPORT_SET_SPEED, FanEntity) from homeassistant.helpers.dispatcher import async_dispatcher_connect -from . import helpers -from .const import ( +from .core import helpers +from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, REPORT_CONFIG_OP, ZHA_DISCOVERY_NEW) -from .entities import ZhaEntity +from .entity import ZhaEntity DEPENDENCIES = ['zha'] diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 766608b35b1..49a09112b31 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -9,12 +9,12 @@ import logging from homeassistant.components import light from homeassistant.helpers.dispatcher import async_dispatcher_connect import homeassistant.util.color as color_util -from . import helpers -from .const import ( +from .core import helpers +from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, REPORT_CONFIG_ASAP, REPORT_CONFIG_DEFAULT, REPORT_CONFIG_IMMEDIATE, ZHA_DISCOVERY_NEW) -from .entities import ZhaEntity -from .entities.listeners import ( +from .entity import ZhaEntity +from .core.listeners import ( OnOffListener, LevelListener ) diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index dabbcb79815..ae45fad0826 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -10,11 +10,11 @@ from homeassistant.components.sensor import DOMAIN from homeassistant.const import TEMP_CELSIUS from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.util.temperature import convert as convert_temperature -from . import helpers -from .const import ( +from .core import helpers +from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, REPORT_CONFIG_MAX_INT, REPORT_CONFIG_MIN_INT, REPORT_CONFIG_RPT_CHANGE, ZHA_DISCOVERY_NEW) -from .entities import ZhaEntity +from .entity import ZhaEntity _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/zha/switch.py b/homeassistant/components/zha/switch.py index 793da4e1e3a..09c20acd088 100644 --- a/homeassistant/components/zha/switch.py +++ b/homeassistant/components/zha/switch.py @@ -8,10 +8,10 @@ import logging from homeassistant.components.switch import DOMAIN, SwitchDevice from homeassistant.helpers.dispatcher import async_dispatcher_connect -from . import helpers -from .const import ( +from .core import helpers +from .core.const import ( DATA_ZHA, DATA_ZHA_DISPATCHERS, REPORT_CONFIG_IMMEDIATE, ZHA_DISCOVERY_NEW) -from .entities import ZhaEntity +from .entity import ZhaEntity _LOGGER = logging.getLogger(__name__)