1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00

Add support for zha custom cluster mappings (#16714)

* Add support for custom cluster mappings

* Refactor sub_component mapping
This commit is contained in:
damarco 2018-10-09 12:53:02 +02:00 committed by Paulus Schoutsen
parent 6bf3f9e748
commit 5167658a1d
3 changed files with 23 additions and 3 deletions

View File

@ -36,7 +36,9 @@ async def make_sensor(discovery_info):
from zigpy.zcl.clusters.smartenergy import Metering
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
in_clusters = discovery_info['in_clusters']
if RelativeHumidity.cluster_id in in_clusters:
if 'sub_component' in discovery_info:
sensor = discovery_info['sub_component'](**discovery_info)
elif RelativeHumidity.cluster_id in in_clusters:
sensor = RelativeHumiditySensor(**discovery_info)
elif TemperatureMeasurement.cluster_id in in_clusters:
sensor = TemperatureSensor(**discovery_info)

View File

@ -276,15 +276,23 @@ class ApplicationListener:
device_classes, discovery_attr,
is_new_join):
"""Try to set up an entity from a "bare" cluster."""
import homeassistant.components.zha.const as zha_const
if cluster.cluster_id in profile_clusters:
return
component = None
component = sub_component = None
for cluster_type, candidate_component in device_classes.items():
if isinstance(cluster, cluster_type):
component = candidate_component
break
for signature, comp in zha_const.CUSTOM_CLUSTER_MAPPINGS.items():
if (isinstance(endpoint.device, signature[0]) and
cluster.cluster_id == signature[1]):
component = comp[0]
sub_component = comp[1]
break
if component is None:
return
@ -301,6 +309,8 @@ class ApplicationListener:
'entity_suffix': '_{}'.format(cluster.cluster_id),
}
discovery_info[discovery_attr] = {cluster.cluster_id: cluster}
if sub_component:
discovery_info.update({'sub_component': sub_component})
self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info
await discovery.async_load_platform(

View File

@ -3,6 +3,7 @@
DEVICE_CLASS = {}
SINGLE_INPUT_CLUSTER_DEVICE_CLASS = {}
SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS = {}
CUSTOM_CLUSTER_MAPPINGS = {}
COMPONENT_CLUSTERS = {}
@ -12,8 +13,9 @@ def populate_data():
These cannot be module level, as importing bellows must be done in a
in a function.
"""
from zigpy import zcl
from zigpy import zcl, quirks
from zigpy.profiles import PROFILES, zha, zll
from homeassistant.components.sensor import zha as sensor_zha
DEVICE_CLASS[zha.PROFILE_ID] = {
zha.DeviceType.ON_OFF_SWITCH: 'binary_sensor',
@ -58,6 +60,12 @@ def populate_data():
zcl.clusters.general.OnOff: 'binary_sensor',
})
# A map of device/cluster to component/sub-component
CUSTOM_CLUSTER_MAPPINGS.update({
(quirks.smartthings.SmartthingsTemperatureHumiditySensor, 64581):
('sensor', sensor_zha.RelativeHumiditySensor)
})
# A map of hass components to all Zigbee clusters it could use
for profile_id, classes in DEVICE_CLASS.items():
profile = PROFILES[profile_id]