|
@@ -2,7 +2,7 @@
|
2
|
2
|
# -*- coding: utf-8 -*-
|
3
|
3
|
#
|
4
|
4
|
from devices.base import base_output
|
5
|
|
-import logging
|
|
5
|
+from devices.base import base_rpc
|
6
|
6
|
import task
|
7
|
7
|
|
8
|
8
|
|
|
@@ -169,3 +169,70 @@ class shelly(base_output):
|
169
|
169
|
self.set_output_0(False)
|
170
|
170
|
if self.output_1:
|
171
|
171
|
self.set_output_1(False)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+class shelly_rpc(base_rpc):
|
|
175
|
+ KEY_OUTPUT_0 = "switch:0"
|
|
176
|
+ KEY_OUTPUT_1 = "switch:1"
|
|
177
|
+ KEY_OUTPUT_2 = "switch:2"
|
|
178
|
+ KEY_INPUT_0 = "input:0"
|
|
179
|
+ KEY_INPUT_1 = "input:1"
|
|
180
|
+ KEY_INPUT_2 = "input:2"
|
|
181
|
+ KEY_LONGPUSH_0 = "input:0:long_push"
|
|
182
|
+ KEY_LONGPUSH_1 = "input:1:long_push"
|
|
183
|
+ KEY_LONGPUSH_2 = "input:2:long_push"
|
|
184
|
+ KEY_SINGLEPUSH_0 = "input:0:single_push"
|
|
185
|
+ KEY_SINGLEPUSH_1 = "input:1:single_push"
|
|
186
|
+ KEY_SINGLEPUSH_2 = "input:2:single_push"
|
|
187
|
+ KEY_DOUBLEPUSH_0 = "input:0:double_push"
|
|
188
|
+ KEY_DOUBLEPUSH_1 = "input:1:double_push"
|
|
189
|
+ KEY_DOUBLEPUSH_2 = "input:2:double_push"
|
|
190
|
+ KEY_TRIPLEPUSH_0 = "input:0:triple_push"
|
|
191
|
+ KEY_TRIPLEPUSH_1 = "input:1:triple_push"
|
|
192
|
+ KEY_TRIPLEPUSH_2 = "input:2:triple_push"
|
|
193
|
+
|
|
194
|
+ RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_INPUT_0, KEY_INPUT_1, KEY_INPUT_2,
|
|
195
|
+ KEY_LONGPUSH_0, KEY_LONGPUSH_1, KEY_LONGPUSH_2, KEY_SINGLEPUSH_0, KEY_SINGLEPUSH_1, KEY_SINGLEPUSH_2,
|
|
196
|
+ KEY_DOUBLEPUSH_0, KEY_DOUBLEPUSH_1, KEY_DOUBLEPUSH_2, KEY_TRIPLEPUSH_0, KEY_TRIPLEPUSH_1, KEY_TRIPLEPUSH_2]
|
|
197
|
+
|
|
198
|
+ def __state_logging__(self, inst, key, data):
|
|
199
|
+ if key in [self.KEY_OUTPUT_0, self.KEY_OUTPUT_1, self.KEY_OUTPUT_2]:
|
|
200
|
+ self.logger.info("State change of '%s' to '%s'", key, repr(data))
|
|
201
|
+ elif key in [self.KEY_INPUT_0, self.KEY_INPUT_1, self.KEY_INPUT_2]:
|
|
202
|
+ self.logger.info("Input action '%s' with '%s'", key, repr(data))
|
|
203
|
+ elif key in [self.KEY_LONGPUSH_0, self.KEY_LONGPUSH_1, self.KEY_LONGPUSH_2,
|
|
204
|
+ self.KEY_SINGLEPUSH_0, self.KEY_SINGLEPUSH_1, self.KEY_SINGLEPUSH_2,
|
|
205
|
+ self.KEY_DOUBLEPUSH_0, self.KEY_DOUBLEPUSH_1, self.KEY_DOUBLEPUSH_2,
|
|
206
|
+ self.KEY_TRIPLEPUSH_0, self.KEY_TRIPLEPUSH_1, self.KEY_TRIPLEPUSH_2]:
|
|
207
|
+ self.logger.info("Input action '%s'", key)
|
|
208
|
+
|
|
209
|
+ def set_output_0(self, state):
|
|
210
|
+ """state: [True, False]"""
|
|
211
|
+ self.rpc_switch_set(self.KEY_OUTPUT_0, state)
|
|
212
|
+
|
|
213
|
+ def set_output_0_mcb(self, device, key, data):
|
|
214
|
+ self.set_output_0(data)
|
|
215
|
+
|
|
216
|
+ def toggle_output_0_mcb(self, device, key, data):
|
|
217
|
+ self.set_output_0(not self.get(self.KEY_OUTPUT_0))
|
|
218
|
+
|
|
219
|
+ def set_output_1(self, state):
|
|
220
|
+ """state: [True, False]"""
|
|
221
|
+ self.rpc_switch_set(self.KEY_OUTPUT_1, state)
|
|
222
|
+
|
|
223
|
+ def set_output_1_mcb(self, device, key, data):
|
|
224
|
+ self.set_output_1(data)
|
|
225
|
+
|
|
226
|
+ def toggle_output_1_mcb(self, device, key, data):
|
|
227
|
+ print(self.get(self.KEY_OUTPUT_1))
|
|
228
|
+ self.set_output_1(not self.get(self.KEY_OUTPUT_1))
|
|
229
|
+
|
|
230
|
+ def set_output_2(self, state):
|
|
231
|
+ """state: [True, False]"""
|
|
232
|
+ self.rpc_switch_set(self.KEY_OUTPUT_2, state)
|
|
233
|
+
|
|
234
|
+ def set_output_2_mcb(self, device, key, data):
|
|
235
|
+ self.set_output_2(data)
|
|
236
|
+
|
|
237
|
+ def toggle_output_2_mcb(self, device, key, data):
|
|
238
|
+ self.set_output_2(not self.get(self.KEY_OUTPUT_2))
|