|
@@ -1,832 +0,0 @@
|
1
|
|
-import colored
|
2
|
|
-import copy
|
3
|
|
-import json
|
4
|
|
-import task
|
5
|
|
-import time
|
6
|
|
-
|
7
|
|
-COLOR_GUI_ACTIVE = colored.fg("light_blue")
|
8
|
|
-COLOR_GUI_PASSIVE = COLOR_GUI_ACTIVE + colored.attr("dim")
|
9
|
|
-COLOR_SHELLY = colored.fg("light_magenta")
|
10
|
|
-COLOR_POWERPLUG = colored.fg("light_cyan")
|
11
|
|
-COLOR_LIGHT_ACTIVE = colored.fg("yellow")
|
12
|
|
-COLOR_LIGHT_PASSIVE = COLOR_LIGHT_ACTIVE + colored.attr("dim")
|
13
|
|
-COLOR_MOTION_SENSOR = colored.fg("dark_orange_3b")
|
14
|
|
-COLOR_HEATING_VALVE = colored.fg("red")
|
15
|
|
-COLOR_REMOTE = colored.fg("green")
|
16
|
|
-
|
17
|
|
-
|
18
|
|
-def payload_filter(payload):
|
19
|
|
- try:
|
20
|
|
- return json.loads(payload)
|
21
|
|
- except json.decoder.JSONDecodeError:
|
22
|
|
- return payload.decode("utf-8")
|
23
|
|
-
|
24
|
|
-
|
25
|
|
-def command_int_value(value):
|
26
|
|
- try:
|
27
|
|
- return int(value)
|
28
|
|
- except TypeError:
|
29
|
|
- print("You need to give a integer parameter not '%s'" % str(value))
|
30
|
|
-
|
31
|
|
-
|
32
|
|
-def command_float_value(value):
|
33
|
|
- try:
|
34
|
|
- return float(value)
|
35
|
|
- except TypeError:
|
36
|
|
- print("You need to give a integer parameter not '%s'" % str(value))
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-def devicename(topic):
|
40
|
|
- return " - ".join(topic.split('/')[1:])
|
41
|
|
-
|
42
|
|
-
|
43
|
|
-def percent_bar(value):
|
44
|
|
- rv = ""
|
45
|
|
- for i in range(0, 10):
|
46
|
|
- rv += u"\u25ac" if (value - 5) > 10*i else u"\u25ad"
|
47
|
|
- return rv
|
48
|
|
-
|
49
|
|
-
|
50
|
|
-def print_light(color, state, topic, description, led=False):
|
51
|
|
- if led is True:
|
52
|
|
- if state is True:
|
53
|
|
- icon = colored.fg('green') + "\u2b24" + color
|
54
|
|
- else:
|
55
|
|
- icon = colored.fg('light_gray') + "\u2b24" + color
|
56
|
|
- else:
|
57
|
|
- icon = u'\u2b24' if state is True else u'\u25ef'
|
58
|
|
- print(color + 10 * ' ' + icon + 9 * ' ' + devicename(topic), description + colored.attr("reset"))
|
59
|
|
-
|
60
|
|
-
|
61
|
|
-def print_switch(color, state, topic, description):
|
62
|
|
- icon = u'\u25a0' if state is True else u'\u25a1'
|
63
|
|
- print(color + 10 * ' ' + icon + 9 * ' ' + devicename(topic), description + colored.attr("reset"))
|
64
|
|
-
|
65
|
|
-
|
66
|
|
-def print_percent(color, prefix, perc_value, value_str, topic, description):
|
67
|
|
- if len(prefix) > 1 or len(value_str) > 7:
|
68
|
|
- raise ValueError("Length of prefix (%d) > 1 or length of value_str (%d) > 7" % (len(prefix), len(value_str)))
|
69
|
|
- print(color + prefix + percent_bar(perc_value), value_str + (8 - len(value_str)) * ' ' + devicename(topic), description + colored.attr("reset"))
|
70
|
|
-
|
71
|
|
-
|
72
|
|
-class base(object):
|
73
|
|
- AUTOSEND = True
|
74
|
|
- COMMANDS = []
|
75
|
|
-
|
76
|
|
- def __init__(self, mqtt_client, topic):
|
77
|
|
- self.mqtt_client = mqtt_client
|
78
|
|
- self.topic = topic
|
79
|
|
- #
|
80
|
|
- self.data = {}
|
81
|
|
- self.callbacks = {}
|
82
|
|
- self.names = {}
|
83
|
|
- self.commands = self.COMMANDS[:]
|
84
|
|
- #
|
85
|
|
- self.mqtt_client.add_callback(self.topic, self.__rx__)
|
86
|
|
- self.mqtt_client.add_callback(self.topic + '/#', self.__rx__)
|
87
|
|
-
|
88
|
|
- def add_callback(self, key, callback, value):
|
89
|
|
- if self.callbacks.get(key) is None:
|
90
|
|
- self.callbacks[key] = []
|
91
|
|
- self.callbacks[key].append((callback, value))
|
92
|
|
-
|
93
|
|
- def add_channel_name(self, key, name):
|
94
|
|
- self.names[key] = name
|
95
|
|
-
|
96
|
|
- def capabilities(self):
|
97
|
|
- return self.commands
|
98
|
|
-
|
99
|
|
- def store_data(self, *args, **kwargs):
|
100
|
|
- keys_changed = []
|
101
|
|
- for key in kwargs:
|
102
|
|
- if kwargs[key] is not None and kwargs[key] != self.data.get(key):
|
103
|
|
- keys_changed.append(key)
|
104
|
|
- self.data[key] = kwargs[key]
|
105
|
|
- for callback, value in self.callbacks.get(key, [(None, None)]):
|
106
|
|
- if callback is not None and (value is None or value == kwargs[key]):
|
107
|
|
- callback(self, key, kwargs[key])
|
108
|
|
- if self.AUTOSEND and len(keys_changed) > 0:
|
109
|
|
- self.__tx__(keys_changed)
|
110
|
|
-
|
111
|
|
- def get_data(self, key, default=None):
|
112
|
|
- rv = self.data.get(key, default)
|
113
|
|
- try:
|
114
|
|
- rv = True if rv.lower() == 'on' else rv
|
115
|
|
- rv = False if rv.lower() == 'off' else rv
|
116
|
|
- except AttributeError:
|
117
|
|
- pass
|
118
|
|
- return rv
|
119
|
|
-
|
120
|
|
- def __tx__(self, keys_changed):
|
121
|
|
- self.mqtt_client.send(self.topic, json.dumps(self.data))
|
122
|
|
-
|
123
|
|
- def __rx__(self, client, userdata, message):
|
124
|
|
- print("%s: __rx__ not handled!" % self.__class__.__name__)
|
125
|
|
-
|
126
|
|
-
|
127
|
|
-class shelly(base):
|
128
|
|
- KEY_OUTPUT_0 = "relay/0"
|
129
|
|
- KEY_OUTPUT_1 = "relay/1"
|
130
|
|
- KEY_INPUT_0 = "input/0"
|
131
|
|
- KEY_INPUT_1 = "input/1"
|
132
|
|
- KEY_LONGPUSH_0 = "longpush/0"
|
133
|
|
- KEY_LONGPUSH_1 = "longpush/1"
|
134
|
|
- #
|
135
|
|
- INPUT_FUNC_OUT1_FOLLOW = "out1_follow"
|
136
|
|
- INPUT_FUNC_OUT1_TRIGGER = "out1_trigger"
|
137
|
|
- INPUT_FUNC_OUT2_FOLLOW = "out2_follow"
|
138
|
|
- INPUT_FUNC_OUT2_TRIGGER = "out2_trigger"
|
139
|
|
- #
|
140
|
|
- COMMANDS = [
|
141
|
|
- "get_relay_0", "toggle_relay_0",
|
142
|
|
- "get_relay_1", "toggle_relay_1",
|
143
|
|
- "get_input_0", "toggle_input_0",
|
144
|
|
- "get_input_1", "toggle_input_1",
|
145
|
|
- "trigger_long_input_0", "trigger_long_input_1",
|
146
|
|
- ]
|
147
|
|
-
|
148
|
|
- def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None):
|
149
|
|
- super().__init__(mqtt_client, topic)
|
150
|
|
- #
|
151
|
|
- self.store_data(**{self.KEY_OUTPUT_0: False, self.KEY_OUTPUT_1: False, self.KEY_INPUT_0: False, self.KEY_INPUT_1: False})
|
152
|
|
- self.__input_0_func = input_0_func
|
153
|
|
- self.__input_1_func = input_1_func
|
154
|
|
- self.__output_0_auto_off__ = output_0_auto_off
|
155
|
|
- if self.__output_0_auto_off__ is not None:
|
156
|
|
- self.__delayed_off__ = task.delayed(float(self.__output_0_auto_off__), self.__auto_off__, self.KEY_OUTPUT_0)
|
157
|
|
- #
|
158
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
|
159
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.__start_auto_off__, True)
|
160
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.__stop_auto_off__, True)
|
161
|
|
- self.add_callback(self.KEY_OUTPUT_1, self.print_formatted, None)
|
162
|
|
- #
|
163
|
|
- self.add_callback(self.KEY_INPUT_0, self.__input_function__, None)
|
164
|
|
- self.add_callback(self.KEY_INPUT_1, self.__input_function__, None)
|
165
|
|
-
|
166
|
|
- def __rx__(self, client, userdata, message):
|
167
|
|
- value = payload_filter(message.payload)
|
168
|
|
- if message.topic.startswith(self.topic) and message.topic.endswith("/command"):
|
169
|
|
- key = '/'.join(message.topic.split('/')[-3:-1])
|
170
|
|
- if value == 'toggle':
|
171
|
|
- self.__toggle_data__(key)
|
172
|
|
- else:
|
173
|
|
- self.__set_data__(key, value)
|
174
|
|
-
|
175
|
|
- def __tx__(self, keys_changed):
|
176
|
|
- for key in keys_changed:
|
177
|
|
- self.mqtt_client.send(self.topic + '/' + key, "on" if self.data.get(key) else "off")
|
178
|
|
-
|
179
|
|
- def __input_function__(self, device, key, data):
|
180
|
|
- if key == self.KEY_INPUT_0:
|
181
|
|
- func = self.__input_0_func
|
182
|
|
- elif key == self.KEY_INPUT_1:
|
183
|
|
- func = self.__input_1_func
|
184
|
|
- else:
|
185
|
|
- func = None
|
186
|
|
- if func == self.INPUT_FUNC_OUT1_FOLLOW:
|
187
|
|
- self.__set_data__(self.KEY_OUTPUT_0, data)
|
188
|
|
- elif func == self.INPUT_FUNC_OUT1_TRIGGER:
|
189
|
|
- self.__toggle_data__(self.KEY_OUTPUT_0)
|
190
|
|
- elif func == self.INPUT_FUNC_OUT2_FOLLOW:
|
191
|
|
- self.__set_data__(self.KEY_OUTPUT_1, data)
|
192
|
|
- elif func == self.INPUT_FUNC_OUT2_TRIGGER:
|
193
|
|
- self.__toggle_data__(self.KEY_OUTPUT_1)
|
194
|
|
-
|
195
|
|
- def __start_auto_off__(self, device, key, data):
|
196
|
|
- self.__stop_auto_off__(device, key, data)
|
197
|
|
- if self.__output_0_auto_off__ is not None:
|
198
|
|
- self.__delayed_off__.run()
|
199
|
|
-
|
200
|
|
- def __stop_auto_off__(self, device, key, data):
|
201
|
|
- if self.__output_0_auto_off__ is not None:
|
202
|
|
- if not self.__delayed_off__._stopped:
|
203
|
|
- self.__delayed_off__.stop()
|
204
|
|
-
|
205
|
|
- def __auto_off__(self, key):
|
206
|
|
- if key == self.KEY_OUTPUT_0:
|
207
|
|
- self.__set_data__(key, 'off')
|
208
|
|
-
|
209
|
|
- def __set_data__(self, key, value):
|
210
|
|
- self.store_data(**{key: value == "on"})
|
211
|
|
-
|
212
|
|
- def __toggle_data__(self, key):
|
213
|
|
- if key in self.data:
|
214
|
|
- self.__set_data__(key, "on" if not self.data.get(key) else "off")
|
215
|
|
-
|
216
|
|
- def command(self, command):
|
217
|
|
- if command in self.COMMANDS:
|
218
|
|
- if command == self.COMMANDS[0]:
|
219
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
|
220
|
|
- elif command == self.COMMANDS[1]:
|
221
|
|
- self.__toggle_data__(self.KEY_OUTPUT_0)
|
222
|
|
- elif command == self.COMMANDS[2]:
|
223
|
|
- self.print_formatted(self, self.KEY_OUTPUT_1, self.data.get(self.KEY_OUTPUT_1))
|
224
|
|
- elif command == self.COMMANDS[3]:
|
225
|
|
- self.__toggle_data__(self.KEY_OUTPUT_1)
|
226
|
|
- elif command == self.COMMANDS[4]:
|
227
|
|
- self.print_formatted(self, self.KEY_INPUT_0, self.data.get(self.KEY_INPUT_0))
|
228
|
|
- elif command == self.COMMANDS[5]:
|
229
|
|
- self.__toggle_data__(self.KEY_INPUT_0)
|
230
|
|
- elif command == self.COMMANDS[6]:
|
231
|
|
- self.print_formatted(self, self.KEY_INPUT_1, self.data.get(self.KEY_INPUT_1))
|
232
|
|
- elif command == self.COMMANDS[7]:
|
233
|
|
- self.__toggle_data__(self.KEY_INPUT_1)
|
234
|
|
- elif command == self.COMMANDS[8]:
|
235
|
|
- self.__toggle_data__(self.KEY_INPUT_0)
|
236
|
|
- time.sleep(0.4)
|
237
|
|
- self.__set_data__(self.KEY_LONGPUSH_0, True)
|
238
|
|
- time.sleep(0.1)
|
239
|
|
- self.__set_data__(self.KEY_LONGPUSH_0, False)
|
240
|
|
- elif command == self.COMMANDS[9]:
|
241
|
|
- self.__toggle_data__(self.KEY_INPUT_1)
|
242
|
|
- time.sleep(0.4)
|
243
|
|
- self.__set_data__(self.KEY_LONGPUSH_1, True)
|
244
|
|
- time.sleep(0.1)
|
245
|
|
- self.__set_data__(self.KEY_LONGPUSH_1, False)
|
246
|
|
- else:
|
247
|
|
- print("%s: not yet implemented!" % command)
|
248
|
|
- else:
|
249
|
|
- print("Unknown command!")
|
250
|
|
-
|
251
|
|
- def print_formatted(self, device, key, value):
|
252
|
|
- if value is not None:
|
253
|
|
- info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value else ""
|
254
|
|
- channel = "(%s%s)" % (self.names.get(key, key), info)
|
255
|
|
- print_light(COLOR_SHELLY, value, self.topic, channel)
|
256
|
|
-
|
257
|
|
-
|
258
|
|
-class my_powerplug(base):
|
259
|
|
- KEY_OUTPUT_0 = "state"
|
260
|
|
- COMMANDS = [
|
261
|
|
- "get_output", "toggle_output",
|
262
|
|
- ]
|
263
|
|
-
|
264
|
|
- def __init__(self, mqtt_client, topic, channel):
|
265
|
|
- super().__init__(mqtt_client, topic + '/' + "output/%d" % (channel + 1))
|
266
|
|
- #
|
267
|
|
- self.data[self.KEY_OUTPUT_0] = False
|
268
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
|
269
|
|
-
|
270
|
|
- def __rx__(self, client, userdata, message):
|
271
|
|
- if message.topic == self.topic + '/set':
|
272
|
|
- payload = payload_filter(message.payload)
|
273
|
|
- if payload == "toggle":
|
274
|
|
- payload = not self.data.get(self.KEY_OUTPUT_0)
|
275
|
|
- self.store_data(**{self.KEY_OUTPUT_0: payload})
|
276
|
|
-
|
277
|
|
- def __tx__(self, keys_changed):
|
278
|
|
- for key in keys_changed:
|
279
|
|
- self.mqtt_client.send(self.topic, json.dumps(self.data.get(key)))
|
280
|
|
-
|
281
|
|
- def command(self, command):
|
282
|
|
- if command in self.COMMANDS:
|
283
|
|
- if command == self.COMMANDS[0]:
|
284
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
|
285
|
|
- elif command == self.COMMANDS[1]:
|
286
|
|
- self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)})
|
287
|
|
- else:
|
288
|
|
- print("%s: not yet implemented!" % command)
|
289
|
|
- else:
|
290
|
|
- print("Unknown command!")
|
291
|
|
-
|
292
|
|
- def print_formatted(self, device, key, value):
|
293
|
|
- if value is not None:
|
294
|
|
- print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, "State"))
|
295
|
|
-
|
296
|
|
-
|
297
|
|
-class silvercrest_powerplug(base):
|
298
|
|
- KEY_OUTPUT_0 = "state"
|
299
|
|
- #
|
300
|
|
- COMMANDS = [
|
301
|
|
- "get_state", "set_state", "unset_state",
|
302
|
|
- ]
|
303
|
|
-
|
304
|
|
- def __init__(self, mqtt_client, topic):
|
305
|
|
- super().__init__(mqtt_client, topic)
|
306
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
|
307
|
|
- #
|
308
|
|
- self.store_data(**{self.KEY_OUTPUT_0: False})
|
309
|
|
-
|
310
|
|
- def __rx__(self, client, userdata, message):
|
311
|
|
- if message.topic == self.topic + '/set':
|
312
|
|
- STATES = ["on", "off", "toggle"]
|
313
|
|
- #
|
314
|
|
- state = json.loads(message.payload).get('state').lower()
|
315
|
|
- if state in STATES:
|
316
|
|
- if state == STATES[0]:
|
317
|
|
- self.store_data(**{self.KEY_OUTPUT_0: True})
|
318
|
|
- elif state == STATES[1]:
|
319
|
|
- self.store_data(**{self.KEY_OUTPUT_0: False})
|
320
|
|
- else:
|
321
|
|
- self.store_data(**{not self.data.get(self.KEY_OUTPUT_0)})
|
322
|
|
-
|
323
|
|
- def __tx__(self, keys_changed):
|
324
|
|
- for key in keys_changed:
|
325
|
|
- self.mqtt_client.send(self.topic + '/' + key, "on" if self.data.get(key) else "off")
|
326
|
|
-
|
327
|
|
- def command(self, command):
|
328
|
|
- if command in self.COMMANDS:
|
329
|
|
- if command == self.COMMANDS[0]:
|
330
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
|
331
|
|
- elif command == self.COMMANDS[1]:
|
332
|
|
- self.store_data(**{self.KEY_OUTPUT_0: True})
|
333
|
|
- elif command == self.COMMANDS[2]:
|
334
|
|
- self.store_data(**{self.KEY_OUTPUT_0: False})
|
335
|
|
- else:
|
336
|
|
- print("%s: not yet implemented!" % command)
|
337
|
|
- else:
|
338
|
|
- print("Unknown command!")
|
339
|
|
-
|
340
|
|
- def print_formatted(self, device, key, value):
|
341
|
|
- if value is not None:
|
342
|
|
- print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, key))
|
343
|
|
-
|
344
|
|
-
|
345
|
|
-class tradfri_light(base):
|
346
|
|
- KEY_OUTPUT_0 = "state"
|
347
|
|
- KEY_BRIGHTNESS = "brightness"
|
348
|
|
- KEY_COLOR_TEMP = "color_temp"
|
349
|
|
- KEY_BRIGHTNESS_MOVE = "brightness_move"
|
350
|
|
- #
|
351
|
|
- STATE_COMMANDS = ("get_state", "toggle_state", )
|
352
|
|
- BRIGHTNESS_COMMANDS = ("get_brightness", "set_brightness",)
|
353
|
|
- COLOR_TEMP_COMMANDS = ("get_color_temp", "set_color_temp",)
|
354
|
|
-
|
355
|
|
- def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True):
|
356
|
|
- super().__init__(mqtt_client, topic)
|
357
|
|
- self.send_on_power_on = send_on_power_on
|
358
|
|
- self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
|
359
|
|
- self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None)
|
360
|
|
- self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None)
|
361
|
|
- #
|
362
|
|
- self.commands = []
|
363
|
|
- if enable_state:
|
364
|
|
- self.commands.extend(self.STATE_COMMANDS)
|
365
|
|
- if enable_brightness:
|
366
|
|
- self.commands.extend(self.BRIGHTNESS_COMMANDS)
|
367
|
|
- if enable_color_temp:
|
368
|
|
- self.commands.extend(self.COLOR_TEMP_COMMANDS)
|
369
|
|
- self.__init_data__(enable_state, enable_brightness, enable_color_temp)
|
370
|
|
-
|
371
|
|
- def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
|
372
|
|
- data = {}
|
373
|
|
- if enable_state:
|
374
|
|
- data[self.KEY_OUTPUT_0] = False
|
375
|
|
- self.commands.extend(self.STATE_COMMANDS)
|
376
|
|
- if enable_brightness:
|
377
|
|
- data[self.KEY_BRIGHTNESS] = 50
|
378
|
|
- self.brightnes_move = (0, time.time())
|
379
|
|
- self.commands.extend(self.BRIGHTNESS_COMMANDS)
|
380
|
|
- if enable_color_temp:
|
381
|
|
- data[self.KEY_COLOR_TEMP] = 5
|
382
|
|
- self.commands.extend(self.COLOR_TEMP_COMMANDS)
|
383
|
|
- self.store_data(**data)
|
384
|
|
-
|
385
|
|
- def __rx__(self, client, userdata, message):
|
386
|
|
- data = json.loads(message.payload)
|
387
|
|
- if self.data.get(self.KEY_OUTPUT_0) or data.get(self.KEY_OUTPUT_0) in ['on', 'toggle']:
|
388
|
|
- if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
|
389
|
|
- for targetkey in data:
|
390
|
|
- value = data[targetkey]
|
391
|
|
- if targetkey in self.data.keys():
|
392
|
|
- if targetkey == self.KEY_OUTPUT_0:
|
393
|
|
- if value == "toggle":
|
394
|
|
- value = not self.data.get(self.KEY_OUTPUT_0)
|
395
|
|
- else:
|
396
|
|
- value = value == "on"
|
397
|
|
- elif targetkey == self.KEY_BRIGHTNESS:
|
398
|
|
- value = round((value - 1) / 2.53, 0)
|
399
|
|
- elif targetkey == self.KEY_COLOR_TEMP:
|
400
|
|
- value = round((value - 250) / 20.4, 0)
|
401
|
|
- self.store_data(**{targetkey: value})
|
402
|
|
- else:
|
403
|
|
- if targetkey == self.KEY_BRIGHTNESS_MOVE:
|
404
|
|
- new_value = self.data.get(self.KEY_BRIGHTNESS) + (time.time() - self.brightnes_move[1]) * self.brightnes_move[0]
|
405
|
|
- if new_value < 0:
|
406
|
|
- new_value = 0
|
407
|
|
- if new_value > 256:
|
408
|
|
- new_value = 256
|
409
|
|
- self.store_data(**{self.KEY_BRIGHTNESS: int(new_value)})
|
410
|
|
- self.brightnes_move = (value, time.time())
|
411
|
|
- else:
|
412
|
|
- print("%s: UNKNOWN KEY %s" % (message.topic, targetkey))
|
413
|
|
- elif message.topic == self.topic + '/get':
|
414
|
|
- self.__tx__(None)
|
415
|
|
-
|
416
|
|
- def __tx__(self, keys_changed):
|
417
|
|
- tx_data = copy.copy(self.data)
|
418
|
|
- if self.KEY_OUTPUT_0 in tx_data:
|
419
|
|
- tx_data[self.KEY_OUTPUT_0] = "on" if tx_data[self.KEY_OUTPUT_0] else "off"
|
420
|
|
- if self.KEY_BRIGHTNESS in tx_data:
|
421
|
|
- tx_data[self.KEY_BRIGHTNESS] = 1 + round(2.53 * tx_data[self.KEY_BRIGHTNESS], 0)
|
422
|
|
- if self.KEY_COLOR_TEMP in tx_data:
|
423
|
|
- tx_data[self.KEY_COLOR_TEMP] = 250 + round(20.4 * tx_data[self.KEY_COLOR_TEMP], 0)
|
424
|
|
- self.mqtt_client.send(self.topic, json.dumps(tx_data))
|
425
|
|
-
|
426
|
|
- def command(self, command):
|
427
|
|
- try:
|
428
|
|
- command, value = command.split(' ')
|
429
|
|
- except ValueError:
|
430
|
|
- value = None
|
431
|
|
- if command in self.capabilities():
|
432
|
|
- if command == self.STATE_COMMANDS[0]:
|
433
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
|
434
|
|
- elif command == self.STATE_COMMANDS[1]:
|
435
|
|
- self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)})
|
436
|
|
- elif command == self.BRIGHTNESS_COMMANDS[0]:
|
437
|
|
- self.print_formatted(self, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
|
438
|
|
- elif command == self.BRIGHTNESS_COMMANDS[1]:
|
439
|
|
- self.store_data(**{self.KEY_BRIGHTNESS: command_int_value(value)})
|
440
|
|
- elif command == self.COLOR_TEMP_COMMANDS[0]:
|
441
|
|
- self.print_formatted(self, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
|
442
|
|
- elif command == self.COLOR_TEMP_COMMANDS[1]:
|
443
|
|
- self.store_data(**{self.KEY_COLOR_TEMP: command_int_value(value)})
|
444
|
|
- else:
|
445
|
|
- print("%s: not yet implemented!" % command)
|
446
|
|
- else:
|
447
|
|
- print("Unknown command!")
|
448
|
|
-
|
449
|
|
- def power_off(self, device, key, value):
|
450
|
|
- self.data[self.KEY_OUTPUT_0] = False
|
451
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, False)
|
452
|
|
-
|
453
|
|
- def power_on(self, device, key, value):
|
454
|
|
- if self.send_on_power_on:
|
455
|
|
- self.store_data(**{self.KEY_OUTPUT_0: True})
|
456
|
|
- else:
|
457
|
|
- self.data[self.KEY_OUTPUT_0] = True
|
458
|
|
- self.print_formatted(self, self.KEY_OUTPUT_0, True)
|
459
|
|
-
|
460
|
|
- def print_formatted(self, device, key, value):
|
461
|
|
- if value is not None:
|
462
|
|
- color = COLOR_LIGHT_ACTIVE
|
463
|
|
- if key == self.KEY_OUTPUT_0:
|
464
|
|
- print_light(COLOR_LIGHT_ACTIVE, value, self.topic, "")
|
465
|
|
- self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
|
466
|
|
- self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
|
467
|
|
- elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
|
468
|
|
- perc_value = round(value, 0) if key == self.KEY_BRIGHTNESS else round(10 * value, 0)
|
469
|
|
- print_percent(
|
470
|
|
- COLOR_LIGHT_PASSIVE if not self.data.get(self.KEY_OUTPUT_0) else COLOR_LIGHT_ACTIVE,
|
471
|
|
- 'B' if key == self.KEY_BRIGHTNESS else 'C',
|
472
|
|
- perc_value,
|
473
|
|
- "%3d%%" % perc_value,
|
474
|
|
- self.topic,
|
475
|
|
- ""
|
476
|
|
- )
|
477
|
|
-
|
478
|
|
-
|
479
|
|
-class brennenstuhl_heating_valve(base):
|
480
|
|
- TEMP_RANGE = [10, 30]
|
481
|
|
- #
|
482
|
|
- KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint"
|
483
|
|
- KEY_TEMPERATURE = "local_temperature"
|
484
|
|
- #
|
485
|
|
- COMMANDS = [
|
486
|
|
- "get_temperature_setpoint", "set_temperature_setpoint", "set_local_temperature",
|
487
|
|
- ]
|
488
|
|
-
|
489
|
|
- def __init__(self, mqtt_client, topic):
|
490
|
|
- super().__init__(mqtt_client, topic)
|
491
|
|
- self.store_data(**{
|
492
|
|
- self.KEY_TEMPERATURE_SETPOINT: 20,
|
493
|
|
- self.KEY_TEMPERATURE: 20.7,
|
494
|
|
- })
|
495
|
|
- self.add_callback(self.KEY_TEMPERATURE_SETPOINT, self.print_formatted, None)
|
496
|
|
-
|
497
|
|
- def __rx__(self, client, userdata, message):
|
498
|
|
- if message.topic.startswith(self.topic) and message.topic.endswith("/set"):
|
499
|
|
- payload = payload_filter(message.payload)
|
500
|
|
- self.store_data(**payload)
|
501
|
|
-
|
502
|
|
- def command(self, command):
|
503
|
|
- try:
|
504
|
|
- command, value = command.split(' ')
|
505
|
|
- except ValueError:
|
506
|
|
- value = None
|
507
|
|
- if command in self.COMMANDS:
|
508
|
|
- if command == self.COMMANDS[0]:
|
509
|
|
- self.print_formatted(self, self.KEY_TEMPERATURE_SETPOINT, self.data.get(self.KEY_TEMPERATURE_SETPOINT))
|
510
|
|
- elif command == self.COMMANDS[1]:
|
511
|
|
- self.store_data(**{self.KEY_TEMPERATURE_SETPOINT: command_float_value(value)})
|
512
|
|
- elif command == self.COMMANDS[2]:
|
513
|
|
- self.store_data(**{self.KEY_TEMPERATURE: command_float_value(value)})
|
514
|
|
-
|
515
|
|
- def print_formatted(self, device, key, value):
|
516
|
|
- devicename = ' - '.join(self.topic.split('/')[1:])
|
517
|
|
- if key == self.KEY_TEMPERATURE_SETPOINT:
|
518
|
|
- perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
|
519
|
|
- perc = 100 if perc > 100 else perc
|
520
|
|
- perc = 0 if perc < 0 else perc
|
521
|
|
- print_percent(COLOR_HEATING_VALVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "")
|
522
|
|
-
|
523
|
|
-
|
524
|
|
-class videv_light(base):
|
525
|
|
- AUTOSEND = False
|
526
|
|
- #
|
527
|
|
- KEY_STATE = "state"
|
528
|
|
- KEY_BRIGHTNESS = "brightness"
|
529
|
|
- KEY_COLOR_TEMP = "color_temp"
|
530
|
|
- KEY_TIMER = "timer"
|
531
|
|
- #
|
532
|
|
- STATE_COMMANDS = ("get_state", "toggle_state", )
|
533
|
|
- BRIGHTNESS_COMMANDS = ("get_brightness", "set_brightness", )
|
534
|
|
- COLOR_TEMP_COMMANDS = ("get_color_temp", "set_color_temp", )
|
535
|
|
- TIMER_COMMANDS = ("get_timer", )
|
536
|
|
-
|
537
|
|
- def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, enable_timer=False):
|
538
|
|
- super().__init__(mqtt_client, topic)
|
539
|
|
- self.enable_state = enable_state
|
540
|
|
- self.enable_brightness = enable_brightness
|
541
|
|
- self.enable_color_temp = enable_color_temp
|
542
|
|
- self.enable_timer = enable_timer
|
543
|
|
- #
|
544
|
|
- self.maxvalue = None
|
545
|
|
- # add commands to be available
|
546
|
|
- if enable_state:
|
547
|
|
- # init default value
|
548
|
|
- self.data[self.KEY_STATE] = False
|
549
|
|
- # add print callback
|
550
|
|
- self.add_callback(self.KEY_STATE, self.print_formatted, None)
|
551
|
|
- # add commands to be available
|
552
|
|
- self.commands.extend(self.STATE_COMMANDS)
|
553
|
|
- if enable_brightness:
|
554
|
|
- # init default value
|
555
|
|
- self.data[self.KEY_BRIGHTNESS] = 50
|
556
|
|
- # add print callback
|
557
|
|
- self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None)
|
558
|
|
- # add commands to be available
|
559
|
|
- self.commands.extend(self.BRIGHTNESS_COMMANDS)
|
560
|
|
- if enable_color_temp:
|
561
|
|
- # init default value
|
562
|
|
- self.data[self.KEY_COLOR_TEMP] = 5
|
563
|
|
- # add print callback
|
564
|
|
- self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None)
|
565
|
|
- # add commands to be available
|
566
|
|
- self.commands.extend(self.COLOR_TEMP_COMMANDS)
|
567
|
|
- if enable_timer:
|
568
|
|
- # init default value
|
569
|
|
- self.data[self.KEY_TIMER] = 0
|
570
|
|
- # add print callback
|
571
|
|
- self.add_callback(self.KEY_TIMER, self.print_formatted, None)
|
572
|
|
- # add commands to be available
|
573
|
|
- self.commands.extend(self.TIMER_COMMANDS)
|
574
|
|
-
|
575
|
|
- def __rx__(self, client, userdata, message):
|
576
|
|
- value = payload_filter(message.payload)
|
577
|
|
- if message.topic.startswith(self.topic):
|
578
|
|
- targetkey = message.topic.split('/')[-1]
|
579
|
|
- if targetkey in self.data.keys():
|
580
|
|
- self.store_data(**{targetkey: value})
|
581
|
|
- elif targetkey != "__info__":
|
582
|
|
- print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
|
583
|
|
- elif message.topic == self.topic + '/get':
|
584
|
|
- self.__tx__(None)
|
585
|
|
-
|
586
|
|
- def send(self, key, data):
|
587
|
|
- if data is not None:
|
588
|
|
- topic = self.topic + '/' + key
|
589
|
|
- self.mqtt_client.send(topic, json.dumps(data))
|
590
|
|
-
|
591
|
|
- def command(self, command):
|
592
|
|
- try:
|
593
|
|
- command, value = command.split(' ')
|
594
|
|
- except ValueError:
|
595
|
|
- value = None
|
596
|
|
- if command in self.capabilities():
|
597
|
|
- if command == self.STATE_COMMANDS[0]:
|
598
|
|
- self.print_formatted(self, self.KEY_STATE, self.data.get(self.KEY_STATE))
|
599
|
|
- elif command == self.STATE_COMMANDS[1]:
|
600
|
|
- self.send(self.KEY_STATE, not self.data.get(self.KEY_STATE))
|
601
|
|
- elif command == self.BRIGHTNESS_COMMANDS[0]:
|
602
|
|
- self.print_formatted(self, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
|
603
|
|
- elif command == self.BRIGHTNESS_COMMANDS[1]:
|
604
|
|
- self.send(self.KEY_BRIGHTNESS, command_int_value(value))
|
605
|
|
- elif command == self.COLOR_TEMP_COMMANDS[0]:
|
606
|
|
- self.print_formatted(self, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
|
607
|
|
- elif command == self.COLOR_TEMP_COMMANDS[1]:
|
608
|
|
- self.send(self.KEY_COLOR_TEMP, command_int_value(value))
|
609
|
|
- elif command == self.TIMER_COMMANDS[0]:
|
610
|
|
- self.print_formatted(self, self.KEY_TIMER, self.data.get(self.KEY_TIMER))
|
611
|
|
- else:
|
612
|
|
- print("%s: not yet implemented!" % command)
|
613
|
|
- else:
|
614
|
|
- print("Unknown command!")
|
615
|
|
-
|
616
|
|
- def print_formatted(self, device, key, value):
|
617
|
|
- if value is not None:
|
618
|
|
- device = " - ".join(self.topic.split('/')[1:])
|
619
|
|
- if key == self.KEY_STATE:
|
620
|
|
- print_switch(COLOR_GUI_ACTIVE, value, self.topic, "")
|
621
|
|
- elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
|
622
|
|
- perc_value = round(value * 10 if key == self.KEY_COLOR_TEMP else value, 0)
|
623
|
|
- print_percent(
|
624
|
|
- COLOR_GUI_ACTIVE,
|
625
|
|
- 'B' if key == self.KEY_BRIGHTNESS else 'C',
|
626
|
|
- perc_value,
|
627
|
|
- "%3d%%" % perc_value,
|
628
|
|
- self.topic,
|
629
|
|
- ""
|
630
|
|
- )
|
631
|
|
- elif key == self.KEY_TIMER:
|
632
|
|
- if value > 0:
|
633
|
|
- if self.maxvalue is None and value != 0:
|
634
|
|
- self.maxvalue = value
|
635
|
|
- disp_value = value
|
636
|
|
- try:
|
637
|
|
- perc = disp_value / self.maxvalue * 100
|
638
|
|
- except ZeroDivisionError:
|
639
|
|
- perc = 0
|
640
|
|
- else:
|
641
|
|
- disp_value = 0
|
642
|
|
- perc = 0
|
643
|
|
- self.maxvalue = None
|
644
|
|
- print_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, self.topic, '(%.1f)' % disp_value)
|
645
|
|
-
|
646
|
|
-
|
647
|
|
-# class silvercrest_motion_sensor(base):
|
648
|
|
-# KEY_OCCUPANCY = "occupancy"
|
649
|
|
-# COMMANDS = ['motion']
|
650
|
|
-
|
651
|
|
-# def __init__(self, mqtt_client, topic):
|
652
|
|
-# super().__init__(mqtt_client, topic)
|
653
|
|
-# self.data[self.KEY_OCCUPANCY] = False
|
654
|
|
-# self.add_callback(self.KEY_OCCUPANCY, self.print_formatted, None)
|
655
|
|
-
|
656
|
|
-# def __rx__(self, client, userdata, message):
|
657
|
|
-# pass
|
658
|
|
-
|
659
|
|
-# def command(self, command):
|
660
|
|
-# try:
|
661
|
|
-# command, value = command.split(' ')
|
662
|
|
-# except ValueError:
|
663
|
|
-# value = None
|
664
|
|
-# else:
|
665
|
|
-# value = json.loads(value)
|
666
|
|
-# if command == self.COMMANDS[0]:
|
667
|
|
-# self.store_data(**{self.KEY_OCCUPANCY: True})
|
668
|
|
-# time.sleep(value or 10)
|
669
|
|
-# self.store_data(**{self.KEY_OCCUPANCY: False})
|
670
|
|
-
|
671
|
|
-# def print_formatted(self, device, key, value):
|
672
|
|
-# if value is not None:
|
673
|
|
-# print_light(COLOR_MOTION_SENSOR, value, self.topic, "")
|
674
|
|
-
|
675
|
|
-
|
676
|
|
-# class tradfri_button(base):
|
677
|
|
-# KEY_ACTION = "action"
|
678
|
|
-# #
|
679
|
|
-# ACTION_TOGGLE = "toggle"
|
680
|
|
-# ACTION_BRIGHTNESS_UP = "brightness_up_click"
|
681
|
|
-# ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
|
682
|
|
-# ACTION_RIGHT = "arrow_right_click"
|
683
|
|
-# ACTION_LEFT = "arrow_left_click"
|
684
|
|
-# ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
|
685
|
|
-# ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
|
686
|
|
-# ACTION_RIGHT_LONG = "arrow_right_hold"
|
687
|
|
-# ACTION_LEFT_LONG = "arrow_left_hold"
|
688
|
|
-# #
|
689
|
|
-# COMMANDS = [ACTION_TOGGLE, ACTION_LEFT, ACTION_RIGHT, ACTION_BRIGHTNESS_UP, ACTION_BRIGHTNESS_DOWN,
|
690
|
|
-# ACTION_LEFT_LONG, ACTION_RIGHT_LONG, ACTION_BRIGHTNESS_UP_LONG, ACTION_BRIGHTNESS_DOWN_LONG]
|
691
|
|
-
|
692
|
|
-# def __init__(self, mqtt_client, topic):
|
693
|
|
-# super().__init__(mqtt_client, topic)
|
694
|
|
-
|
695
|
|
-# def __rx__(self, client, userdata, message):
|
696
|
|
-# pass
|
697
|
|
-
|
698
|
|
-# def command(self, command):
|
699
|
|
-# try:
|
700
|
|
-# command, value = command.split(' ')
|
701
|
|
-# except ValueError:
|
702
|
|
-# value = None
|
703
|
|
-# else:
|
704
|
|
-# value = json.loads(value)
|
705
|
|
-# if command in self.capabilities():
|
706
|
|
-# action = self.COMMANDS[self.COMMANDS.index(command)]
|
707
|
|
-# if self.COMMANDS.index(command) <= 4:
|
708
|
|
-# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
709
|
|
-# elif self.COMMANDS.index(command) <= 8:
|
710
|
|
-# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
711
|
|
-# time.sleep(value or 0.5)
|
712
|
|
-# action = '_'.join(action.split('_')[:-1] + ['release'])
|
713
|
|
-# self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
|
714
|
|
-
|
715
|
|
-
|
716
|
|
-# class remote(base):
|
717
|
|
-# def __rx__(self, client, userdata, message):
|
718
|
|
-# if message.topic == self.topic + "/VOLUP":
|
719
|
|
-# if payload_filter(message.payload):
|
720
|
|
-# icon = u'\u1403'
|
721
|
|
-# else:
|
722
|
|
-# icon = u'\u25a1'
|
723
|
|
-# elif message.topic == self.topic + "/VOLDOWN":
|
724
|
|
-# if payload_filter(message.payload):
|
725
|
|
-# icon = u'\u1401'
|
726
|
|
-# else:
|
727
|
|
-# icon = u'\u25a1'
|
728
|
|
-# else:
|
729
|
|
-# return
|
730
|
|
-# devicename = ' - '.join(self.topic.split('/')[1:-1])
|
731
|
|
-# print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset"))
|
732
|
|
-
|
733
|
|
-
|
734
|
|
-# class gui_heating_valve(base):
|
735
|
|
-# AUTOSEND = False
|
736
|
|
-# #
|
737
|
|
-# TEMP_RANGE = [10, 30]
|
738
|
|
-# #
|
739
|
|
-# KEY_TIMER = "timer"
|
740
|
|
-# KEY_TEMPERATURE = "temperature"
|
741
|
|
-# KEY_SETPOINT_TEMP = "setpoint_temp"
|
742
|
|
-# KEY_SETPOINT_TO_DEFAULT = "setpoint_to_default"
|
743
|
|
-# KEY_BOOST = 'boost'
|
744
|
|
-# KEY_AWAY = "away"
|
745
|
|
-# KEY_SUMMER = "summer"
|
746
|
|
-# KEY_ENABLE = "enable"
|
747
|
|
-# #
|
748
|
|
-# COMMANDS = [
|
749
|
|
-# "get_temperature",
|
750
|
|
-# "get_temperature_setpoint", "set_temperature_setpoint",
|
751
|
|
-# "trigger_boost", "trigger_setpoint_to_default",
|
752
|
|
-# "toggle_away", "toggle_summer",
|
753
|
|
-# ]
|
754
|
|
-
|
755
|
|
-# def __init__(self, mqtt_client, topic):
|
756
|
|
-# super().__init__(mqtt_client, topic)
|
757
|
|
-# self.add_callback(self.KEY_SETPOINT_TEMP, self.print_formatted, None)
|
758
|
|
-# self.add_callback(self.KEY_TIMER, self.print_formatted, None)
|
759
|
|
-# self.add_callback(self.KEY_AWAY, self.print_formatted, None)
|
760
|
|
-# self.add_callback(self.KEY_SUMMER, self.print_formatted, None)
|
761
|
|
-# #
|
762
|
|
-# self.store_data(**{
|
763
|
|
-# self.KEY_TEMPERATURE: 20.7,
|
764
|
|
-# self.KEY_SETPOINT_TEMP: 20,
|
765
|
|
-# self.KEY_TIMER: 0,
|
766
|
|
-# self.KEY_AWAY: False,
|
767
|
|
-# self.KEY_SUMMER: False,
|
768
|
|
-# self.KEY_ENABLE: True
|
769
|
|
-# })
|
770
|
|
-
|
771
|
|
-# def __rx__(self, client, userdata, message):
|
772
|
|
-# value = payload_filter(message.payload)
|
773
|
|
-# if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
|
774
|
|
-# targetkey = message.topic.split('/')[-2]
|
775
|
|
-# if targetkey in self.data.keys():
|
776
|
|
-# self.store_data(**{targetkey: value})
|
777
|
|
-# else:
|
778
|
|
-# print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
|
779
|
|
-# elif message.topic == self.topic + '/get':
|
780
|
|
-# self.__tx__(None)
|
781
|
|
-
|
782
|
|
-# def send(self, key, data):
|
783
|
|
-# if data is not None:
|
784
|
|
-# topic = self.topic + '/' + key
|
785
|
|
-# self.mqtt_client.send(topic, json.dumps(data))
|
786
|
|
-
|
787
|
|
-# def command(self, command):
|
788
|
|
-# try:
|
789
|
|
-# command, value = command.split(' ')
|
790
|
|
-# except ValueError:
|
791
|
|
-# value = None
|
792
|
|
-# if command in self.COMMANDS:
|
793
|
|
-# if command == self.COMMANDS[0]:
|
794
|
|
-# self.print_formatted(self, self.KEY_TEMPERATURE, self.data.get(self.KEY_TEMPERATURE))
|
795
|
|
-# elif command == self.COMMANDS[1]:
|
796
|
|
-# self.print_formatted(self, self.KEY_SETPOINT_TEMP, self.data.get(self.KEY_SETPOINT_TEMP))
|
797
|
|
-# elif command == self.COMMANDS[2]:
|
798
|
|
-# self.send(self.KEY_SETPOINT_TEMP, command_float_value(value))
|
799
|
|
-# elif command == self.COMMANDS[3]:
|
800
|
|
-# self.send(self.KEY_BOOST, True)
|
801
|
|
-# elif command == self.COMMANDS[4]:
|
802
|
|
-# self.send(self.KEY_SETPOINT_TO_DEFAULT, True)
|
803
|
|
-# elif command == self.COMMANDS[5]:
|
804
|
|
-# self.send(self.KEY_AWAY, not self.data.get(self.KEY_AWAY))
|
805
|
|
-# elif command == self.COMMANDS[6]:
|
806
|
|
-# self.send(self.KEY_SUMMER, not self.data.get(self.KEY_SUMMER))
|
807
|
|
-
|
808
|
|
-# def print_formatted(self, device, key, value):
|
809
|
|
-# devicename = ' - '.join(self.topic.split('/')[1:])
|
810
|
|
-# if key == self.KEY_TIMER:
|
811
|
|
-# value /= 60
|
812
|
|
-# try:
|
813
|
|
-# perc = 100 * value / 60
|
814
|
|
-# except TypeError:
|
815
|
|
-# value = 0
|
816
|
|
-# perc = 0
|
817
|
|
-# print_percent(COLOR_GUI_ACTIVE, 't', perc, "%4.1fmin" % value, self.topic, "(Timer)")
|
818
|
|
-# elif key == self.KEY_TEMPERATURE:
|
819
|
|
-# perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
|
820
|
|
-# perc = 100 if perc > 100 else perc
|
821
|
|
-# perc = 0 if perc < 0 else perc
|
822
|
|
-# print_percent(COLOR_GUI_ACTIVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Temperature)")
|
823
|
|
-# elif key == self.KEY_SETPOINT_TEMP:
|
824
|
|
-# perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
|
825
|
|
-# perc = 100 if perc > 100 else perc
|
826
|
|
-# perc = 0 if perc < 0 else perc
|
827
|
|
-# print_percent(COLOR_GUI_ACTIVE if self.data.get(self.KEY_ENABLE) else COLOR_GUI_PASSIVE,
|
828
|
|
-# '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Setpoint)")
|
829
|
|
-# elif key == self.KEY_AWAY:
|
830
|
|
-# print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Away Mode)")
|
831
|
|
-# elif key == self.KEY_SUMMER:
|
832
|
|
-# print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Summer Mode)")
|