Skip to content

Commit 3cce512

Browse files
authored
Add aqara relay (#223)
* add aqara relay * update models
1 parent f72b03d commit 3cce512

File tree

2 files changed

+144
-3
lines changed

2 files changed

+144
-3
lines changed

zhaquirks/xiaomi/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ def _parse_aqara_attributes(self, value):
209209
102: PRESSURE_MEASUREMENT,
210210
}
211211
)
212-
elif (
213-
MODEL in self._attr_cache and self._attr_cache[MODEL] == "lumi.plug.maus01"
214-
):
212+
elif MODEL in self._attr_cache and self._attr_cache[MODEL] in [
213+
"lumi.plug.maus01",
214+
"lumi.relay.c2acn01",
215+
]:
215216
attribute_names.update({149: CONSUMPTION, 150: VOLTAGE, 152: POWER})
216217

217218
result = {}

zhaquirks/xiaomi/aqara/relay.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""Xiaomi aqara button sensor."""
2+
import logging
3+
4+
from zigpy.profiles import zha
5+
from zigpy.zcl.clusters.general import (
6+
AnalogInput,
7+
Basic,
8+
BinaryOutput,
9+
DeviceTemperature,
10+
Groups,
11+
Identify,
12+
OnOff,
13+
Ota,
14+
PowerConfiguration,
15+
Scenes,
16+
Time,
17+
)
18+
from zigpy.zcl.clusters.homeautomation import ElectricalMeasurement
19+
20+
from ... import Bus, CustomCluster
21+
from ...const import (
22+
DEVICE_TYPE,
23+
ENDPOINTS,
24+
INPUT_CLUSTERS,
25+
MODELS_INFO,
26+
OUTPUT_CLUSTERS,
27+
PROFILE_ID,
28+
)
29+
from .. import (
30+
LUMI,
31+
POWER_REPORTED,
32+
BasicCluster,
33+
ElectricalMeasurementCluster,
34+
XiaomiCustomDevice,
35+
)
36+
37+
_LOGGER = logging.getLogger(__name__)
38+
39+
40+
class AnalogInputCluster(CustomCluster, AnalogInput):
41+
"""Analog input cluster."""
42+
43+
cluster_id = AnalogInput.cluster_id
44+
45+
def __init__(self, *args, **kwargs):
46+
"""Init."""
47+
self._current_state = {}
48+
super().__init__(*args, **kwargs)
49+
50+
def _update_attribute(self, attrid, value):
51+
super()._update_attribute(attrid, value)
52+
if value is not None and value >= 0:
53+
self.endpoint.device.power_bus.listener_event(POWER_REPORTED, value)
54+
55+
56+
class Relay(XiaomiCustomDevice):
57+
"""lumi.plug.maus01 device."""
58+
59+
def __init__(self, *args, **kwargs):
60+
"""Init."""
61+
self.voltage_bus = Bus()
62+
self.consumption_bus = Bus()
63+
self.power_bus = Bus()
64+
super().__init__(*args, **kwargs)
65+
66+
signature = {
67+
MODELS_INFO: [(LUMI, "lumi.relay.c2acn01")],
68+
ENDPOINTS: {
69+
# <SimpleDescriptor endpoint=1 profile=260 device_type=257
70+
# device_version=2
71+
# input_clusters=[0, 3, 4, 5, 1, 2, 10, 6, 16, 2820, 12]
72+
# output_clusters=[25, 10]>
73+
1: {
74+
PROFILE_ID: zha.PROFILE_ID,
75+
DEVICE_TYPE: zha.DeviceType.DIMMABLE_LIGHT,
76+
INPUT_CLUSTERS: [
77+
Basic.cluster_id,
78+
PowerConfiguration.cluster_id,
79+
DeviceTemperature.cluster_id,
80+
Groups.cluster_id,
81+
Identify.cluster_id,
82+
OnOff.cluster_id,
83+
Scenes.cluster_id,
84+
BinaryOutput.cluster_id,
85+
Time.cluster_id,
86+
ElectricalMeasurement.cluster_id,
87+
AnalogInput.cluster_id,
88+
],
89+
OUTPUT_CLUSTERS: [Ota.cluster_id, Time.cluster_id],
90+
},
91+
# <SimpleDescriptor endpoint=2 profile=260 device_type=257
92+
# device_version=2
93+
# input_clusters=[6, 16, 4, 5]
94+
# output_clusters=[]>
95+
2: {
96+
PROFILE_ID: zha.PROFILE_ID,
97+
DEVICE_TYPE: zha.DeviceType.DIMMABLE_LIGHT,
98+
INPUT_CLUSTERS: [
99+
OnOff.cluster_id,
100+
BinaryOutput.cluster_id,
101+
Groups.cluster_id,
102+
Scenes.cluster_id,
103+
],
104+
OUTPUT_CLUSTERS: [],
105+
},
106+
},
107+
}
108+
replacement = {
109+
ENDPOINTS: {
110+
1: {
111+
PROFILE_ID: zha.PROFILE_ID,
112+
DEVICE_TYPE: zha.DeviceType.DIMMABLE_LIGHT,
113+
INPUT_CLUSTERS: [
114+
BasicCluster,
115+
PowerConfiguration.cluster_id,
116+
DeviceTemperature.cluster_id,
117+
Groups.cluster_id,
118+
Identify.cluster_id,
119+
OnOff.cluster_id,
120+
Scenes.cluster_id,
121+
BinaryOutput.cluster_id,
122+
Time.cluster_id,
123+
ElectricalMeasurementCluster,
124+
AnalogInputCluster,
125+
],
126+
OUTPUT_CLUSTERS: [Ota.cluster_id, Time.cluster_id],
127+
},
128+
2: {
129+
PROFILE_ID: zha.PROFILE_ID,
130+
DEVICE_TYPE: zha.DeviceType.DIMMABLE_LIGHT,
131+
INPUT_CLUSTERS: [
132+
OnOff.cluster_id,
133+
BinaryOutput.cluster_id,
134+
Groups.cluster_id,
135+
Scenes.cluster_id,
136+
],
137+
OUTPUT_CLUSTERS: [],
138+
},
139+
}
140+
}

0 commit comments

Comments
 (0)