-
Notifications
You must be signed in to change notification settings - Fork 0
/
meteostation.py
276 lines (233 loc) · 9.59 KB
/
meteostation.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
"""Device handler for PTVO Meteostation Ver 1"""
from zigpy.profiles import zha
from zigpy.quirks import CustomCluster, CustomDevice
from zhaquirks import Bus, LocalDataCluster
from zigpy.zcl.clusters.homeautomation import Diagnostic
from zigpy.zcl.clusters.general import Basic, BinaryInput, OnOff, AnalogInput, MultistateInput, GreenPowerProxy
from zigpy.zcl.clusters.measurement import TemperatureMeasurement, RelativeHumidity, PressureMeasurement
from zhaquirks.const import (
DEVICE_TYPE,
ENDPOINTS,
INPUT_CLUSTERS,
MODELS_INFO,
OUTPUT_CLUSTERS,
PROFILE_ID,
)
DEV_TEMPERATURE_REPORTED = "dev_temperature_reported"
TEMPERATURE_REPORTED = "temperature_reported"
HUMIDITY_REPORTED = "humidity_reported"
PRESSURE_REPORTED = "pressure_reported"
PTVO_DEVICE = 0xfffe
GREEN_POWER_DEVICE = 0x0061
GP_DEVICE_ID = 0xA1E0
class PtvoAnalogInputCluster(CustomCluster, AnalogInput):
"""Analog input cluster, used to relay temperature, humidity and Pressure to Meteostation cluster."""
cluster_id = AnalogInput.cluster_id
def __init__(self, *args, **kwargs):
"""Init."""
self._current_state = {}
self._current_value = 0
super().__init__(*args, **kwargs)
def _update_attribute(self, attrid, value):
super()._update_attribute(attrid, value)
if value is not None:
if attrid == 85:
self._current_value = value
if attrid == 28:
if value == "C":
"""Device temperature value."""
d_value = self._current_value * 100
self.endpoint.device.dev_temperature_bus.listener_event(DEV_TEMPERATURE_REPORTED, d_value)
if value == "C,44":
"""Temperature value."""
t_value = self._current_value * 100
self.endpoint.device.temperature_bus.listener_event(TEMPERATURE_REPORTED, t_value)
if value == "%,44":
"""Humidity value."""
h_value = self._current_value * 100
self.endpoint.device.humidity_bus.listener_event(HUMIDITY_REPORTED, h_value)
if value == "Pa,76":
"""Pressure value."""
p_value = int(self._current_value) / 100
self.endpoint.device.pressure_bus.listener_event(PRESSURE_REPORTED, p_value)
class DevTemperatureMeasurementCluster(LocalDataCluster, TemperatureMeasurement):
cluster_id = TemperatureMeasurement.cluster_id
MEASURED_VALUE_ID = 0x0000
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.endpoint.device.dev_temperature_bus.add_listener(self)
def dev_temperature_reported(self, value):
"""Temperature reported."""
self._update_attribute(self.MEASURED_VALUE_ID, value)
class TemperatureMeasurementCluster(LocalDataCluster, TemperatureMeasurement):
cluster_id = TemperatureMeasurement.cluster_id
MEASURED_VALUE_ID = 0x0000
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.endpoint.device.temperature_bus.add_listener(self)
def temperature_reported(self, value):
"""Temperature reported."""
self._update_attribute(self.MEASURED_VALUE_ID, value)
class HumidityMeasurementCluster(LocalDataCluster, RelativeHumidity):
"""Humidity measurement cluster to receive reports that are sent to the analog cluster."""
cluster_id = RelativeHumidity.cluster_id
MEASURED_VALUE_ID = 0x0000
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.endpoint.device.humidity_bus.add_listener(self)
def humidity_reported(self, value):
"""Humidity reported."""
self._update_attribute(self.MEASURED_VALUE_ID, value)
class PressureMeasurementCluster(LocalDataCluster, PressureMeasurement):
"""Pressure measurement cluster to receive reports that are sent to the analog cluster."""
cluster_id = PressureMeasurement.cluster_id
MEASURED_VALUE_ID = 0x0000
def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.endpoint.device.pressure_bus.add_listener(self)
def pressure_reported(self, value):
"""Humidity reported."""
self._update_attribute(self.MEASURED_VALUE_ID, value)
class meteostation(CustomDevice):
"""Meteostation Ver 1 based on PTVO firmware."""
def __init__(self, *args, **kwargs):
"""Init device."""
self.dev_temperature_bus = Bus()
self.temperature_bus = Bus()
self.humidity_bus = Bus()
self.pressure_bus = Bus()
super().__init__(*args, **kwargs)
signature = {
MODELS_INFO: [("ptvo.info", "meteostation")],
ENDPOINTS: {
# <SimpleDescriptor endpoint=1 profile=260 device_type=65534
# device_version=1
# input_clusters=[0, 12]
# output_clusters=[0, 18]>
1: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [
Basic.cluster_id,
AnalogInput.cluster_id,
],
OUTPUT_CLUSTERS: [
Basic.cluster_id,
MultistateInput.cluster_id,
],
},
# <SimpleDescriptor endpoint=2 profile=260 device_type=65534
# device_version=1
# input_clusters=[6]
# output_clusters=[6]>
2: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [OnOff.cluster_id],
OUTPUT_CLUSTERS: [OnOff.cluster_id],
},
# <SimpleDescriptor endpoint=3 profile=260 device_type=65534
# device_version=1
# input_clusters=[6]
# output_clusters=[6]>
3: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [OnOff.cluster_id],
OUTPUT_CLUSTERS: [OnOff.cluster_id],
},
# <SimpleDescriptor endpoint=4 profile=260 device_type=65534
# device_version=1
# input_clusters=[12]
# output_clusters=[]>
4: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [AnalogInput.cluster_id],
OUTPUT_CLUSTERS: [],
},
# <SimpleDescriptor endpoint=5 profile=260 device_type=65534
# device_version=1
# input_clusters=[12]
# output_clusters=[]>
5: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [AnalogInput.cluster_id],
OUTPUT_CLUSTERS: [],
},
# <SimpleDescriptor endpoint=7 profile=260 device_type=65534
# device_version=1
# input_clusters=[12]
# output_clusters=[]>
7: {
PROFILE_ID: zha.PROFILE_ID,
DEVICE_TYPE: PTVO_DEVICE,
INPUT_CLUSTERS: [AnalogInput.cluster_id],
OUTPUT_CLUSTERS: [],
},
# <SimpleDescriptor endpoint=242 profile=41440 device_type=65534
# device_version=1
# input_clusters=[12]
# output_clusters=[]>
242: {
PROFILE_ID: GP_DEVICE_ID,
DEVICE_TYPE: GREEN_POWER_DEVICE,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
},
},
}
replacement = {
ENDPOINTS: {
1: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [
Basic.cluster_id,
AnalogInput.cluster_id,
TemperatureMeasurementCluster,
HumidityMeasurementCluster,
PressureMeasurementCluster,
],
OUTPUT_CLUSTERS: [
Basic.cluster_id,
MultistateInput.cluster_id,
],
},
2: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [
DevTemperatureMeasurementCluster,
],
OUTPUT_CLUSTERS: [OnOff.cluster_id],
},
3: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [OnOff.cluster_id],
},
4: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [PtvoAnalogInputCluster],
OUTPUT_CLUSTERS: [],
},
5: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [PtvoAnalogInputCluster],
OUTPUT_CLUSTERS: [],
},
7: {
PROFILE_ID: zha.PROFILE_ID,
INPUT_CLUSTERS: [PtvoAnalogInputCluster],
OUTPUT_CLUSTERS: [],
},
242: {
INPUT_CLUSTERS: [],
OUTPUT_CLUSTERS: [GreenPowerProxy.cluster_id],
},
},
}