-
Notifications
You must be signed in to change notification settings - Fork 624
/
ts0601_trv_sas.py
323 lines (278 loc) · 10.9 KB
/
ts0601_trv_sas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
"""Saswell (Tuya whitelabel) 88teujp thermostat valve quirk."""
import logging
from zigpy.profiles import zha
import zigpy.types as t
from zigpy.zcl import foundation
from zigpy.zcl.clusters.general import (
AnalogOutput,
Basic,
Groups,
Identify,
Ota,
Scenes,
Time,
)
from zigpy.zcl.clusters.hvac import Thermostat
from zhaquirks import Bus, LocalDataCluster
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
from zhaquirks.tuya import (
TuyaManufClusterAttributes,
TuyaPowerConfigurationCluster,
TuyaThermostat,
TuyaThermostatCluster,
)
_LOGGER = logging.getLogger(__name__)
SASWELL_HEATING_SETPOINT_ATTR = 0x0267
SASWELL_STATE_ATTR = 0x0165
SASWELL_LOCAL_TEMP_ATTR = 0x0266
SASWELL_BATTERY_LOW_ATTR = 0x0569
SASWELL_SCHEDULE_ENABLE_ATTR = 0x016C
SASWELL_TEMPERATURE_CALIBRATION_ATTR = 0x021B # temperature calibration in degrees
CTRL_SEQ_OF_OPER_ATTR = 0x001B
MIN_HEAT_SETPOINT_ATTR = 0x0015
MAX_HEAT_SETPOINT_ATTR = 0x0016
class ManufacturerThermostatCluster(TuyaManufClusterAttributes):
"""Tuya manufacturer specific cluster."""
class State(t.enum8):
"""State option."""
Off = 0x00
On = 0x01
class BatteryState(t.enum8):
"""Battery state option."""
Normal = 0x00
Low = 0x01
class ScheduleState(t.enum8):
"""Schedule state option."""
Disabled = 0x00
Enabled = 0x01
attributes = TuyaManufClusterAttributes.attributes.copy()
attributes.update(
{
SASWELL_STATE_ATTR: ("state", State, True),
SASWELL_HEATING_SETPOINT_ATTR: ("heating_setpoint", t.uint32_t, True),
SASWELL_LOCAL_TEMP_ATTR: ("local_temperature", t.uint32_t, True),
SASWELL_BATTERY_LOW_ATTR: ("battery_state", BatteryState, True),
SASWELL_SCHEDULE_ENABLE_ATTR: ("schedule_enabled", ScheduleState, True),
SASWELL_TEMPERATURE_CALIBRATION_ATTR: (
"temperature_calibration",
t.int32s,
True,
),
}
)
TEMPERATURE_ATTRS = {
SASWELL_HEATING_SETPOINT_ATTR: "occupied_heating_setpoint",
SASWELL_LOCAL_TEMP_ATTR: "local_temperature",
}
def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
if attrid in self.TEMPERATURE_ATTRS:
self.endpoint.device.thermostat_bus.listener_event(
"temperature_change",
self.TEMPERATURE_ATTRS[attrid],
value * 10,
)
elif attrid == SASWELL_STATE_ATTR:
self.endpoint.device.thermostat_bus.listener_event(
"system_mode_reported", value
)
elif attrid == SASWELL_BATTERY_LOW_ATTR:
# this device doesn't have battery level reporting, only battery low alert
# when the alert is active (1) we report 0% and 100% otherwise (0)
self.endpoint.device.battery_bus.listener_event(
"battery_change", 0 if value == 1 else 100
)
elif attrid == (SASWELL_TEMPERATURE_CALIBRATION_ATTR):
self.endpoint.device.temperature_calibration_bus.listener_event(
"set_value", value
)
class ThermostatCluster(TuyaThermostatCluster):
"""Thermostat cluster."""
cluster_id = Thermostat.cluster_id
_CONSTANT_ATTRIBUTES = {
MIN_HEAT_SETPOINT_ATTR: 500,
MAX_HEAT_SETPOINT_ATTR: 3000,
CTRL_SEQ_OF_OPER_ATTR: Thermostat.ControlSequenceOfOperation.Heating_Only, # the device supports heating mode
}
def system_mode_reported(self, value):
"""Handle reported system mode."""
if value == 1:
self._update_attribute(
self.attributes_by_name["system_mode"].id, Thermostat.SystemMode.Heat
)
self._update_attribute(
self.attributes_by_name["running_mode"].id, Thermostat.RunningMode.Heat
)
_LOGGER.debug("reported system_mode: heat")
else:
self._update_attribute(
self.attributes_by_name["system_mode"].id, Thermostat.SystemMode.Off
)
self._update_attribute(
self.attributes_by_name["running_mode"].id, Thermostat.RunningMode.Off
)
_LOGGER.debug("reported system_mode: off")
def map_attribute(self, attribute, value):
"""Map standardized attribute value to dict of manufacturer values."""
if attribute == "occupied_heating_setpoint":
# centidegree to decidegree
return {SASWELL_HEATING_SETPOINT_ATTR: round(value / 10)}
if attribute == "system_mode":
# this quirk does not support programmig modes so we force the schedule mode to be always off
# more details: https://github.com/zigpy/zha-device-handlers/issues/1815
if value == self.SystemMode.Off:
return {SASWELL_STATE_ATTR: 0, SASWELL_SCHEDULE_ENABLE_ATTR: 0}
if value == self.SystemMode.Heat:
return {SASWELL_STATE_ATTR: 1, SASWELL_SCHEDULE_ENABLE_ATTR: 0}
class TuyaTemperatureOffset(LocalDataCluster, AnalogOutput):
"""AnalogOutput cluster for setting temperature offset."""
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.endpoint.device.temperature_calibration_bus.add_listener(self)
self._update_attribute(
self.attributes_by_name["description"].id, "Temperature Offset"
)
self._update_attribute(self.attributes_by_name["max_present_value"].id, 6)
self._update_attribute(self.attributes_by_name["min_present_value"].id, -6)
self._update_attribute(self.attributes_by_name["resolution"].id, 1)
self._update_attribute(self.attributes_by_name["application_type"].id, 0x0009)
self._update_attribute(self.attributes_by_name["engineering_units"].id, 62)
def set_value(self, value):
"""Set new temperature offset value."""
self._update_attribute(self.attributes_by_name["present_value"].id, value)
def get_value(self):
"""Get current temperature offset value."""
return self._attr_cache.get(self.attributes_by_name["present_value"].id)
async def write_attributes(self, attributes, manufacturer=None):
"""Modify value before passing it to the set_data tuya command."""
for attrid, value in attributes.items():
if isinstance(attrid, str):
attrid = self.attributes_by_name[attrid].id
if attrid not in self.attributes:
self.error("%d is not a valid attribute id", attrid)
continue
self._update_attribute(attrid, value)
if attrid == 0x0055: # `present_value`
await self.endpoint.tuya_manufacturer.write_attributes(
{SASWELL_TEMPERATURE_CALIBRATION_ATTR: value}, manufacturer=None
)
return ([foundation.WriteAttributesStatusRecord(foundation.Status.SUCCESS)],)
class Thermostat_TYST11_c88teujp(TuyaThermostat):
"""Saswell 88teujp thermostat valve."""
def __init__(self, *args, **kwargs):
"""Init device."""
self.temperature_calibration_bus = Bus()
super().__init__(*args, **kwargs)
signature = {
MODELS_INFO: [
("_TYST11_KGbxAXL2", "GbxAXL2"),
("_TYST11_c88teujp", "88teujp"),
("_TYST11_azqp6ssj", "zqp6ssj"),
("_TYST11_yw7cahqs", "w7cahqs"),
("_TYST11_9gvruqf5", "gvruqf5"),
("_TYST11_zuhszj9s", "uhszj9s"),
("_TYST11_caj4jz0i", "aj4jz0i"),
],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=0
# device_version=0
# input_clusters=[0, 3]
# output_clusters=[3, 25]>
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.ON_OFF_SWITCH,
INPUT_CLUSTERS: [
Basic.cluster_id,
Identify.cluster_id,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Ota.cluster_id,
],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.THERMOSTAT,
INPUT_CLUSTERS: [
Basic.cluster_id,
TuyaPowerConfigurationCluster,
Identify.cluster_id,
ThermostatCluster,
ManufacturerThermostatCluster,
TuyaTemperatureOffset,
],
OUTPUT_CLUSTERS: [
Identify.cluster_id,
Ota.cluster_id,
],
}
},
}
class Thermostat_TZE200_c88teujp(TuyaThermostat):
"""Saswell 88teujp thermostat valve."""
def __init__(self, *args, **kwargs):
"""Init device."""
self.temperature_calibration_bus = Bus()
super().__init__(*args, **kwargs)
signature = {
MODELS_INFO: [
("_TZE200_c88teujp", "TS0601"),
("_TZE200_azqp6ssj", "TS0601"),
("_TZE200_yw7cahqs", "TS0601"),
("_TZE200_9gvruqf5", "TS0601"),
("_TZE200_zuhszj9s", "TS0601"),
("_TZE200_zr9c0day", "TS0601"),
("_TZE200_0dvm9mva", "TS0601"),
("_TZE200_h4cgnbzg", "TS0601"),
("_TZE200_exfrnlow", "TS0601"),
("_TZE200_9m4kmbfu", "TS0601"),
("_TZE200_3yp57tby", "TS0601"),
],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=81
# device_version=0
# input_clusters=[0, 4, 5, 61184]
# output_clusters=[10, 25]>
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.SMART_PLUG,
INPUT_CLUSTERS: [
Basic.cluster_id,
Groups.cluster_id,
Scenes.cluster_id,
TuyaManufClusterAttributes.cluster_id,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: zha.DeviceType.THERMOSTAT,
INPUT_CLUSTERS: [
Basic.cluster_id,
TuyaPowerConfigurationCluster,
Groups.cluster_id,
Scenes.cluster_id,
ThermostatCluster,
ManufacturerThermostatCluster,
TuyaTemperatureOffset,
],
OUTPUT_CLUSTERS: [Time.cluster_id, Ota.cluster_id],
}
}
}