Add support for zha custom cluster mappings (#16714)
* Add support for custom cluster mappings * Refactor sub_component mappingpull/17278/head
parent
6bf3f9e748
commit
5167658a1d
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue