2017-04-30 05:04:49 +00:00
|
|
|
"""All constants related to the ZHA component."""
|
2018-11-27 20:21:25 +00:00
|
|
|
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'
|
2018-12-10 15:59:50 +00:00
|
|
|
DATA_ZHA_CORE_EVENTS = 'zha_core_events'
|
2018-11-27 20:21:25 +00:00
|
|
|
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'
|
2018-12-12 16:06:22 +00:00
|
|
|
ENABLE_QUIRKS = 'enable_quirks'
|
2018-11-27 20:21:25 +00:00
|
|
|
|
|
|
|
DEFAULT_RADIO_TYPE = 'ezsp'
|
|
|
|
DEFAULT_BAUDRATE = 57600
|
|
|
|
DEFAULT_DATABASE_NAME = 'zigbee.db'
|
|
|
|
|
|
|
|
|
|
|
|
class RadioType(enum.Enum):
|
|
|
|
"""Possible options for radio type."""
|
|
|
|
|
|
|
|
ezsp = 'ezsp'
|
|
|
|
xbee = 'xbee'
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def list(cls):
|
|
|
|
"""Return list of enum's values."""
|
|
|
|
return [e.value for e in RadioType]
|
|
|
|
|
2017-04-25 05:24:57 +00:00
|
|
|
|
2018-11-22 18:00:46 +00:00
|
|
|
DISCOVERY_KEY = 'zha_discovery_info'
|
2017-04-25 05:24:57 +00:00
|
|
|
DEVICE_CLASS = {}
|
2018-04-30 06:31:27 +00:00
|
|
|
SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {}
|
|
|
|
SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {}
|
2018-10-09 10:53:02 +00:00
|
|
|
CUSTOM_CLUSTER_MAPPINGS = {}
|
2017-04-25 05:24:57 +00:00
|
|
|
COMPONENT_CLUSTERS = {}
|
2018-12-10 15:59:50 +00:00
|
|
|
EVENTABLE_CLUSTERS = []
|
2017-04-25 05:24:57 +00:00
|
|
|
|
2018-12-19 13:52:20 +00:00
|
|
|
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)
|
|
|
|
|
2017-04-25 05:24:57 +00:00
|
|
|
|
|
|
|
def populate_data():
|
|
|
|
"""Populate data using constants from bellows.
|
|
|
|
|
|
|
|
These cannot be module level, as importing bellows must be done in a
|
|
|
|
in a function.
|
|
|
|
"""
|
2018-10-09 10:53:02 +00:00
|
|
|
from zigpy import zcl, quirks
|
2018-02-06 00:05:19 +00:00
|
|
|
from zigpy.profiles import PROFILES, zha, zll
|
2018-10-09 10:53:02 +00:00
|
|
|
from homeassistant.components.sensor import zha as sensor_zha
|
2017-04-25 05:24:57 +00:00
|
|
|
|
2018-11-22 18:00:46 +00:00
|
|
|
if zha.PROFILE_ID not in DEVICE_CLASS:
|
|
|
|
DEVICE_CLASS[zha.PROFILE_ID] = {}
|
|
|
|
if zll.PROFILE_ID not in DEVICE_CLASS:
|
|
|
|
DEVICE_CLASS[zll.PROFILE_ID] = {}
|
|
|
|
|
2018-12-10 15:59:50 +00:00
|
|
|
EVENTABLE_CLUSTERS.append(zcl.clusters.general.AnalogInput.cluster_id)
|
|
|
|
EVENTABLE_CLUSTERS.append(zcl.clusters.general.LevelControl.cluster_id)
|
|
|
|
EVENTABLE_CLUSTERS.append(zcl.clusters.general.MultistateInput.cluster_id)
|
|
|
|
EVENTABLE_CLUSTERS.append(zcl.clusters.general.OnOff.cluster_id)
|
|
|
|
|
2018-11-22 18:00:46 +00:00
|
|
|
DEVICE_CLASS[zha.PROFILE_ID].update({
|
2018-04-30 06:31:27 +00:00
|
|
|
zha.DeviceType.ON_OFF_SWITCH: 'binary_sensor',
|
|
|
|
zha.DeviceType.LEVEL_CONTROL_SWITCH: 'binary_sensor',
|
|
|
|
zha.DeviceType.REMOTE_CONTROL: 'binary_sensor',
|
2017-04-25 05:24:57 +00:00
|
|
|
zha.DeviceType.SMART_PLUG: 'switch',
|
2018-11-03 21:25:05 +00:00
|
|
|
zha.DeviceType.LEVEL_CONTROLLABLE_OUTPUT: 'light',
|
2017-04-25 05:24:57 +00:00
|
|
|
zha.DeviceType.ON_OFF_LIGHT: 'light',
|
|
|
|
zha.DeviceType.DIMMABLE_LIGHT: 'light',
|
|
|
|
zha.DeviceType.COLOR_DIMMABLE_LIGHT: 'light',
|
2018-04-30 06:31:27 +00:00
|
|
|
zha.DeviceType.ON_OFF_LIGHT_SWITCH: 'binary_sensor',
|
|
|
|
zha.DeviceType.DIMMER_SWITCH: 'binary_sensor',
|
|
|
|
zha.DeviceType.COLOR_DIMMER_SWITCH: 'binary_sensor',
|
2018-11-22 18:00:46 +00:00
|
|
|
})
|
|
|
|
DEVICE_CLASS[zll.PROFILE_ID].update({
|
2017-04-25 05:24:57 +00:00
|
|
|
zll.DeviceType.ON_OFF_LIGHT: 'light',
|
|
|
|
zll.DeviceType.ON_OFF_PLUGIN_UNIT: 'switch',
|
|
|
|
zll.DeviceType.DIMMABLE_LIGHT: 'light',
|
|
|
|
zll.DeviceType.DIMMABLE_PLUGIN_UNIT: 'light',
|
|
|
|
zll.DeviceType.COLOR_LIGHT: 'light',
|
|
|
|
zll.DeviceType.EXTENDED_COLOR_LIGHT: 'light',
|
|
|
|
zll.DeviceType.COLOR_TEMPERATURE_LIGHT: 'light',
|
2018-04-30 06:31:27 +00:00
|
|
|
zll.DeviceType.COLOR_CONTROLLER: 'binary_sensor',
|
|
|
|
zll.DeviceType.COLOR_SCENE_CONTROLLER: 'binary_sensor',
|
|
|
|
zll.DeviceType.CONTROLLER: 'binary_sensor',
|
|
|
|
zll.DeviceType.SCENE_CONTROLLER: 'binary_sensor',
|
|
|
|
zll.DeviceType.ON_OFF_SENSOR: 'binary_sensor',
|
2018-11-22 18:00:46 +00:00
|
|
|
})
|
2017-04-25 05:24:57 +00:00
|
|
|
|
2018-04-30 06:31:27 +00:00
|
|
|
SINGLE_INPUT_CLUSTER_DEVICE_CLASS.update({
|
2017-04-25 05:24:57 +00:00
|
|
|
zcl.clusters.general.OnOff: 'switch',
|
2018-02-18 23:03:18 +00:00
|
|
|
zcl.clusters.measurement.RelativeHumidity: 'sensor',
|
2017-04-25 05:24:57 +00:00
|
|
|
zcl.clusters.measurement.TemperatureMeasurement: 'sensor',
|
2018-05-10 21:55:32 +00:00
|
|
|
zcl.clusters.measurement.PressureMeasurement: 'sensor',
|
2018-05-21 04:56:41 +00:00
|
|
|
zcl.clusters.measurement.IlluminanceMeasurement: 'sensor',
|
2018-05-20 23:01:56 +00:00
|
|
|
zcl.clusters.smartenergy.Metering: 'sensor',
|
2018-05-26 20:50:05 +00:00
|
|
|
zcl.clusters.homeautomation.ElectricalMeasurement: 'sensor',
|
2018-12-22 08:11:33 +00:00
|
|
|
zcl.clusters.general.PowerConfiguration: 'sensor',
|
2017-04-25 05:24:57 +00:00
|
|
|
zcl.clusters.security.IasZone: 'binary_sensor',
|
2018-12-22 19:53:15 +00:00
|
|
|
zcl.clusters.measurement.OccupancySensing: 'binary_sensor',
|
2018-03-18 16:17:56 +00:00
|
|
|
zcl.clusters.hvac.Fan: 'fan',
|
2017-04-25 05:24:57 +00:00
|
|
|
})
|
2018-04-30 06:31:27 +00:00
|
|
|
SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS.update({
|
|
|
|
zcl.clusters.general.OnOff: 'binary_sensor',
|
|
|
|
})
|
2017-04-25 05:24:57 +00:00
|
|
|
|
2018-10-09 10:53:02 +00:00
|
|
|
# A map of device/cluster to component/sub-component
|
|
|
|
CUSTOM_CLUSTER_MAPPINGS.update({
|
|
|
|
(quirks.smartthings.SmartthingsTemperatureHumiditySensor, 64581):
|
|
|
|
('sensor', sensor_zha.RelativeHumiditySensor)
|
|
|
|
})
|
|
|
|
|
2017-04-25 05:24:57 +00:00
|
|
|
# A map of hass components to all Zigbee clusters it could use
|
|
|
|
for profile_id, classes in DEVICE_CLASS.items():
|
|
|
|
profile = PROFILES[profile_id]
|
|
|
|
for device_type, component in classes.items():
|
|
|
|
if component not in COMPONENT_CLUSTERS:
|
2017-07-11 04:16:44 +00:00
|
|
|
COMPONENT_CLUSTERS[component] = (set(), set())
|
2017-04-25 05:24:57 +00:00
|
|
|
clusters = profile.CLUSTERS[device_type]
|
2017-07-11 04:16:44 +00:00
|
|
|
COMPONENT_CLUSTERS[component][0].update(clusters[0])
|
|
|
|
COMPONENT_CLUSTERS[component][1].update(clusters[1])
|