Переглянути джерело

simulation update

videv_dev
Dirk Alders 1 рік тому
джерело
коміт
0365b5de4a
5 змінених файлів з 714 додано та 677 видалено
  1. 364
    378
      __simulation__/devices.py
  2. 94
    72
      __simulation__/rooms.py
  3. 238
    221
      __simulation__/test.py
  4. 7
    3
      house_n_gui_sim.py
  5. 11
    3
      smart_brain.py

+ 364
- 378
__simulation__/devices.py Переглянути файл

@@ -1,4 +1,5 @@
1 1
 import colored
2
+import copy
2 3
 import json
3 4
 import task
4 5
 import time
@@ -107,6 +108,15 @@ class base(object):
107 108
         if self.AUTOSEND and len(keys_changed) > 0:
108 109
             self.__tx__(keys_changed)
109 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
+
110 120
     def __tx__(self, keys_changed):
111 121
         self.mqtt_client.send(self.topic, json.dumps(self.data))
112 122
 
@@ -138,7 +148,7 @@ class shelly(base):
138 148
     def __init__(self, mqtt_client, topic, input_0_func=None, input_1_func=None, output_0_auto_off=None):
139 149
         super().__init__(mqtt_client, topic)
140 150
         #
141
-        self.store_data(**{self.KEY_OUTPUT_0: "off", self.KEY_OUTPUT_1: "off", self.KEY_INPUT_0: "off", self.KEY_INPUT_1: "off"})
151
+        self.store_data(**{self.KEY_OUTPUT_0: False, self.KEY_OUTPUT_1: False, self.KEY_INPUT_0: False, self.KEY_INPUT_1: False})
142 152
         self.__input_0_func = input_0_func
143 153
         self.__input_1_func = input_1_func
144 154
         self.__output_0_auto_off__ = output_0_auto_off
@@ -146,8 +156,8 @@ class shelly(base):
146 156
             self.__delayed_off__ = task.delayed(float(self.__output_0_auto_off__), self.__auto_off__, self.KEY_OUTPUT_0)
147 157
         #
148 158
         self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
149
-        self.add_callback(self.KEY_OUTPUT_0, self.__start_auto_off__, "on")
150
-        self.add_callback(self.KEY_OUTPUT_0, self.__stop_auto_off__, "off")
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)
151 161
         self.add_callback(self.KEY_OUTPUT_1, self.print_formatted, None)
152 162
         #
153 163
         self.add_callback(self.KEY_INPUT_0, self.__input_function__, None)
@@ -164,7 +174,7 @@ class shelly(base):
164 174
 
165 175
     def __tx__(self, keys_changed):
166 176
         for key in keys_changed:
167
-            self.mqtt_client.send(self.topic + '/' + key, self.data.get(key))
177
+            self.mqtt_client.send(self.topic + '/' + key, "on" if self.data.get(key) else "off")
168 178
 
169 179
     def __input_function__(self, device, key, data):
170 180
         if key == self.KEY_INPUT_0:
@@ -197,14 +207,11 @@ class shelly(base):
197 207
             self.__set_data__(key, 'off')
198 208
 
199 209
     def __set_data__(self, key, value):
200
-        if value in ["on", "off"]:
201
-            self.store_data(**{key: value})
202
-        else:
203
-            print("Wrong value (%s)!" % repr(value))
210
+        self.store_data(**{key: value == "on"})
204 211
 
205 212
     def __toggle_data__(self, key):
206 213
         if key in self.data:
207
-            self.__set_data__(key, 'on' if self.data.get(key) == 'off' else 'off')
214
+            self.__set_data__(key, "on" if not self.data.get(key) else "off")
208 215
 
209 216
     def command(self, command):
210 217
         if command in self.COMMANDS:
@@ -227,15 +234,15 @@ class shelly(base):
227 234
             elif command == self.COMMANDS[8]:
228 235
                 self.__toggle_data__(self.KEY_INPUT_0)
229 236
                 time.sleep(0.4)
230
-                self.__set_data__(self.KEY_LONGPUSH_0, 'on')
237
+                self.__set_data__(self.KEY_LONGPUSH_0, True)
231 238
                 time.sleep(0.1)
232
-                self.__set_data__(self.KEY_LONGPUSH_0, 'off')
239
+                self.__set_data__(self.KEY_LONGPUSH_0, False)
233 240
             elif command == self.COMMANDS[9]:
234 241
                 self.__toggle_data__(self.KEY_INPUT_1)
235 242
                 time.sleep(0.4)
236
-                self.__set_data__(self.KEY_LONGPUSH_1, 'on')
243
+                self.__set_data__(self.KEY_LONGPUSH_1, True)
237 244
                 time.sleep(0.1)
238
-                self.__set_data__(self.KEY_LONGPUSH_1, 'off')
245
+                self.__set_data__(self.KEY_LONGPUSH_1, False)
239 246
             else:
240 247
                 print("%s: not yet implemented!" % command)
241 248
         else:
@@ -243,45 +250,33 @@ class shelly(base):
243 250
 
244 251
     def print_formatted(self, device, key, value):
245 252
         if value is not None:
246
-            info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value == "on" else ""
253
+            info = (" - %ds" % self.__output_0_auto_off__) if self.__output_0_auto_off__ is not None and value else ""
247 254
             channel = "(%s%s)" % (self.names.get(key, key), info)
248
-            print_light(COLOR_SHELLY, value == "on", self.topic, channel)
255
+            print_light(COLOR_SHELLY, value, self.topic, channel)
249 256
 
250 257
 
251 258
 class my_powerplug(base):
252
-    KEY_OUTPUT_0 = "0"
253
-    KEY_OUTPUT_1 = "1"
254
-    KEY_OUTPUT_2 = "2"
255
-    KEY_OUTPUT_3 = "3"
259
+    KEY_OUTPUT_0 = "state"
256 260
     COMMANDS = [
257
-        "get_output_0", "toggle_output_0",
258
-        "get_output_1", "toggle_output_1",
259
-        "get_output_2", "toggle_output_2",
260
-        "get_output_3", "toggle_output_3",
261
+        "get_output", "toggle_output",
261 262
     ]
262 263
 
263
-    def __init__(self, mqtt_client, topic):
264
-        super().__init__(mqtt_client, topic)
264
+    def __init__(self, mqtt_client, topic, channel):
265
+        super().__init__(mqtt_client, topic + '/' + "output/%d" % (channel + 1))
265 266
         #
266
-        for i in range(0, 4):
267
-            self.data[str(i)] = False
268
-            self.add_callback(str(i), self.print_formatted, None)
267
+        self.data[self.KEY_OUTPUT_0] = False
268
+        self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
269 269
 
270 270
     def __rx__(self, client, userdata, message):
271
-        if message.topic.startswith(self.topic + '/output/') and message.topic.endswith('/set'):
272
-            try:
273
-                channels = [int(message.topic.split('/')[-2]) - 1]
274
-            except ValueError:
275
-                channels = range(0, 4)
276
-            for channel in channels:
277
-                payload = payload_filter(message.payload)
278
-                if payload == "toggle":
279
-                    payload = not self.data.get(str(channel))
280
-                self.store_data(**{str(channel): payload})
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})
281 276
 
282 277
     def __tx__(self, keys_changed):
283 278
         for key in keys_changed:
284
-            self.mqtt_client.send(self.topic + "/output/" + str(int(key) + 1), json.dumps(self.data.get(key)))
279
+            self.mqtt_client.send(self.topic, json.dumps(self.data.get(key)))
285 280
 
286 281
     def command(self, command):
287 282
         if command in self.COMMANDS:
@@ -289,18 +284,6 @@ class my_powerplug(base):
289 284
                 self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
290 285
             elif command == self.COMMANDS[1]:
291 286
                 self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)})
292
-            elif command == self.COMMANDS[2]:
293
-                self.print_formatted(self, self.KEY_OUTPUT_1, self.data.get(self.KEY_OUTPUT_1))
294
-            elif command == self.COMMANDS[3]:
295
-                self.store_data(**{self.KEY_OUTPUT_1: not self.data.get(self.KEY_OUTPUT_1)})
296
-            elif command == self.COMMANDS[4]:
297
-                self.print_formatted(self, self.KEY_OUTPUT_2, self.data.get(self.KEY_OUTPUT_2))
298
-            elif command == self.COMMANDS[5]:
299
-                self.store_data(**{self.KEY_OUTPUT_2: not self.data.get(self.KEY_OUTPUT_2)})
300
-            elif command == self.COMMANDS[6]:
301
-                self.print_formatted(self, self.KEY_OUTPUT_3, self.data.get(self.KEY_OUTPUT_3))
302
-            elif command == self.COMMANDS[7]:
303
-                self.store_data(**{self.KEY_OUTPUT_3: not self.data.get(self.KEY_OUTPUT_3)})
304 287
             else:
305 288
                 print("%s: not yet implemented!" % command)
306 289
         else:
@@ -308,7 +291,7 @@ class my_powerplug(base):
308 291
 
309 292
     def print_formatted(self, device, key, value):
310 293
         if value is not None:
311
-            print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, "Channel %d" % (int(key) + 1)))
294
+            print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, "State"))
312 295
 
313 296
 
314 297
 class silvercrest_powerplug(base):
@@ -322,7 +305,7 @@ class silvercrest_powerplug(base):
322 305
         super().__init__(mqtt_client, topic)
323 306
         self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
324 307
         #
325
-        self.store_data(**{self.KEY_OUTPUT_0: "off"})
308
+        self.store_data(**{self.KEY_OUTPUT_0: False})
326 309
 
327 310
     def __rx__(self, client, userdata, message):
328 311
         if message.topic == self.topic + '/set':
@@ -331,20 +314,24 @@ class silvercrest_powerplug(base):
331 314
             state = json.loads(message.payload).get('state').lower()
332 315
             if state in STATES:
333 316
                 if state == STATES[0]:
334
-                    self.store_data(**{self.KEY_OUTPUT_0: 'on'})
317
+                    self.store_data(**{self.KEY_OUTPUT_0: True})
335 318
                 elif state == STATES[1]:
336
-                    self.store_data(**{self.KEY_OUTPUT_0: 'off'})
319
+                    self.store_data(**{self.KEY_OUTPUT_0: False})
337 320
                 else:
338
-                    self.store_data(**{self.KEY_OUTPUT_0: "off" if self.data.get(self.KEY_OUTPUT_0) == "on" else "on"})
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")
339 326
 
340 327
     def command(self, command):
341 328
         if command in self.COMMANDS:
342 329
             if command == self.COMMANDS[0]:
343 330
                 self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
344 331
             elif command == self.COMMANDS[1]:
345
-                self.store_data(**{self.KEY_OUTPUT_0: 'on'})
332
+                self.store_data(**{self.KEY_OUTPUT_0: True})
346 333
             elif command == self.COMMANDS[2]:
347
-                self.store_data(**{self.KEY_OUTPUT_0: 'off'})
334
+                self.store_data(**{self.KEY_OUTPUT_0: False})
348 335
             else:
349 336
                 print("%s: not yet implemented!" % command)
350 337
         else:
@@ -352,40 +339,11 @@ class silvercrest_powerplug(base):
352 339
 
353 340
     def print_formatted(self, device, key, value):
354 341
         if value is not None:
355
-            print_light(COLOR_POWERPLUG, value == "on", self.topic, "(%s)" % self.names.get(key, key))
356
-
357
-
358
-class silvercrest_motion_sensor(base):
359
-    KEY_OCCUPANCY = "occupancy"
360
-    COMMANDS = ['motion']
361
-
362
-    def __init__(self, mqtt_client, topic):
363
-        super().__init__(mqtt_client, topic)
364
-        self.data[self.KEY_OCCUPANCY] = False
365
-        self.add_callback(self.KEY_OCCUPANCY, self.print_formatted, None)
366
-
367
-    def __rx__(self, client, userdata, message):
368
-        pass
369
-
370
-    def command(self, command):
371
-        try:
372
-            command, value = command.split(' ')
373
-        except ValueError:
374
-            value = None
375
-        else:
376
-            value = json.loads(value)
377
-        if command == self.COMMANDS[0]:
378
-            self.store_data(**{self.KEY_OCCUPANCY: True})
379
-            time.sleep(value or 10)
380
-            self.store_data(**{self.KEY_OCCUPANCY: False})
381
-
382
-    def print_formatted(self, device, key, value):
383
-        if value is not None:
384
-            print_light(COLOR_MOTION_SENSOR, value, self.topic, "")
342
+            print_light(COLOR_POWERPLUG, value, self.topic, "(%s)" % self.names.get(key, key))
385 343
 
386 344
 
387 345
 class tradfri_light(base):
388
-    KEY_STATE = "state"
346
+    KEY_OUTPUT_0 = "state"
389 347
     KEY_BRIGHTNESS = "brightness"
390 348
     KEY_COLOR_TEMP = "color_temp"
391 349
     KEY_BRIGHTNESS_MOVE = "brightness_move"
@@ -397,7 +355,7 @@ class tradfri_light(base):
397 355
     def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False, send_on_power_on=True):
398 356
         super().__init__(mqtt_client, topic)
399 357
         self.send_on_power_on = send_on_power_on
400
-        self.add_callback(self.KEY_STATE, self.print_formatted, None)
358
+        self.add_callback(self.KEY_OUTPUT_0, self.print_formatted, None)
401 359
         self.add_callback(self.KEY_BRIGHTNESS, self.print_formatted, None)
402 360
         self.add_callback(self.KEY_COLOR_TEMP, self.print_formatted, None)
403 361
         #
@@ -413,34 +371,41 @@ class tradfri_light(base):
413 371
     def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
414 372
         data = {}
415 373
         if enable_state:
416
-            data[self.KEY_STATE] = 'off'
374
+            data[self.KEY_OUTPUT_0] = False
417 375
             self.commands.extend(self.STATE_COMMANDS)
418 376
         if enable_brightness:
419
-            data[self.KEY_BRIGHTNESS] = 128
377
+            data[self.KEY_BRIGHTNESS] = 50
420 378
             self.brightnes_move = (0, time.time())
421 379
             self.commands.extend(self.BRIGHTNESS_COMMANDS)
422 380
         if enable_color_temp:
423
-            data[self.KEY_COLOR_TEMP] = 352
381
+            data[self.KEY_COLOR_TEMP] = 5
424 382
             self.commands.extend(self.COLOR_TEMP_COMMANDS)
425 383
         self.store_data(**data)
426 384
 
427 385
     def __rx__(self, client, userdata, message):
428 386
         data = json.loads(message.payload)
429
-        if self.data.get(self.KEY_STATE) == 'on' or data.get(self.KEY_STATE) in ['on', 'toggle']:
387
+        if self.data.get(self.KEY_OUTPUT_0) or data.get(self.KEY_OUTPUT_0) in ['on', 'toggle']:
430 388
             if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
431 389
                 for targetkey in data:
432 390
                     value = data[targetkey]
433 391
                     if targetkey in self.data.keys():
434
-                        if targetkey == self.KEY_STATE and value == "toggle":
435
-                            value = "on" if self.data.get(self.KEY_STATE) == "off" else "off"
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)
436 401
                         self.store_data(**{targetkey: value})
437 402
                     else:
438 403
                         if targetkey == self.KEY_BRIGHTNESS_MOVE:
439 404
                             new_value = self.data.get(self.KEY_BRIGHTNESS) + (time.time() - self.brightnes_move[1]) * self.brightnes_move[0]
440 405
                             if new_value < 0:
441 406
                                 new_value = 0
442
-                            if new_value > 255:
443
-                                new_value = 255
407
+                            if new_value > 256:
408
+                                new_value = 256
444 409
                             self.store_data(**{self.KEY_BRIGHTNESS: int(new_value)})
445 410
                             self.brightnes_move = (value, time.time())
446 411
                         else:
@@ -448,6 +413,16 @@ class tradfri_light(base):
448 413
             elif message.topic == self.topic + '/get':
449 414
                 self.__tx__(None)
450 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
+
451 426
     def command(self, command):
452 427
         try:
453 428
             command, value = command.split(' ')
@@ -455,9 +430,9 @@ class tradfri_light(base):
455 430
             value = None
456 431
         if command in self.capabilities():
457 432
             if command == self.STATE_COMMANDS[0]:
458
-                self.print_formatted(self, self.KEY_STATE, self.data.get(self.KEY_STATE))
433
+                self.print_formatted(self, self.KEY_OUTPUT_0, self.data.get(self.KEY_OUTPUT_0))
459 434
             elif command == self.STATE_COMMANDS[1]:
460
-                self.store_data(**{self.KEY_STATE: 'off' if self.data.get(self.KEY_STATE) == 'on' else 'on'})
435
+                self.store_data(**{self.KEY_OUTPUT_0: not self.data.get(self.KEY_OUTPUT_0)})
461 436
             elif command == self.BRIGHTNESS_COMMANDS[0]:
462 437
                 self.print_formatted(self, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
463 438
             elif command == self.BRIGHTNESS_COMMANDS[1]:
@@ -472,28 +447,28 @@ class tradfri_light(base):
472 447
             print("Unknown command!")
473 448
 
474 449
     def power_off(self, device, key, value):
475
-        self.data[self.KEY_STATE] = 'off'
476
-        self.print_formatted(self, self.KEY_STATE, 'off')
450
+        self.data[self.KEY_OUTPUT_0] = False
451
+        self.print_formatted(self, self.KEY_OUTPUT_0, False)
477 452
 
478 453
     def power_on(self, device, key, value):
479 454
         if self.send_on_power_on:
480
-            self.store_data(**{self.KEY_STATE: 'on'})
455
+            self.store_data(**{self.KEY_OUTPUT_0: True})
481 456
         else:
482
-            self.data[self.KEY_STATE] = 'on'
483
-            self.print_formatted(self, self.KEY_STATE, 'on')
457
+            self.data[self.KEY_OUTPUT_0] = True
458
+            self.print_formatted(self, self.KEY_OUTPUT_0, True)
484 459
 
485 460
     def print_formatted(self, device, key, value):
486 461
         if value is not None:
487 462
             color = COLOR_LIGHT_ACTIVE
488
-            if key == self.KEY_STATE:
489
-                print_light(COLOR_LIGHT_ACTIVE, value == "on", self.topic, "")
463
+            if key == self.KEY_OUTPUT_0:
464
+                print_light(COLOR_LIGHT_ACTIVE, value, self.topic, "")
490 465
                 self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
491 466
                 self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
492 467
             elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
493
-                perc_value = round(value * 100 / 256, 0) if key == self.KEY_BRIGHTNESS else round((value - 250) * 100 / 204, 0)
468
+                perc_value = round(value, 0) if key == self.KEY_BRIGHTNESS else round(10 * value, 0)
494 469
                 print_percent(
495
-                    COLOR_LIGHT_PASSIVE if self.data.get(self.KEY_STATE) != "on" else COLOR_LIGHT_ACTIVE,
496
-                    'B' if key == gui_light.KEY_BRIGHTNESS else 'C',
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',
497 472
                     perc_value,
498 473
                     "%3d%%" % perc_value,
499 474
                     self.topic,
@@ -501,44 +476,109 @@ class tradfri_light(base):
501 476
                 )
502 477
 
503 478
 
504
-class gui_light(tradfri_light):
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):
505 525
     AUTOSEND = False
506 526
     #
507
-    KEY_ENABLE = "enable"
527
+    KEY_STATE = "state"
528
+    KEY_BRIGHTNESS = "brightness"
529
+    KEY_COLOR_TEMP = "color_temp"
508 530
     KEY_TIMER = "timer"
509
-    KEY_LED_X = "led%d"
510
-
511
-    def __init__(self, mqtt_client, topic, enable_state=True, enable_brightness=False, enable_color_temp=False):
512
-        super().__init__(mqtt_client, topic, enable_state, enable_brightness, enable_color_temp)
513
-        self.add_callback(self.KEY_ENABLE, self.print_formatted, None)
514
-        self.add_callback(self.KEY_TIMER, self.print_formatted, None)
515
-        for i in range(0, 10):
516
-            self.add_callback(self.KEY_LED_X % i, self.print_formatted, None)
517
-        self.led_names = {}
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
518 543
         #
519 544
         self.maxvalue = None
520
-
521
-    def __init_data__(self, enable_state, enable_brightness, enable_color_temp):
522
-        data = {}
523
-        data[self.KEY_ENABLE] = False
545
+        # add commands to be available
524 546
         if enable_state:
525
-            data[self.KEY_STATE] = False
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)
526 553
         if enable_brightness:
527
-            data[self.KEY_BRIGHTNESS] = 50
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)
528 560
         if enable_color_temp:
529
-            data[self.KEY_COLOR_TEMP] = 5
530
-        data[self.KEY_TIMER] = '-'
531
-        for i in range(0, 10):
532
-            data[self.KEY_LED_X % i] = False
533
-        self.store_data(**data)
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)
534 574
 
535 575
     def __rx__(self, client, userdata, message):
536 576
         value = payload_filter(message.payload)
537
-        if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
538
-            targetkey = message.topic.split('/')[-2]
577
+        if message.topic.startswith(self.topic):
578
+            targetkey = message.topic.split('/')[-1]
539 579
             if targetkey in self.data.keys():
540 580
                 self.store_data(**{targetkey: value})
541
-            else:
581
+            elif targetkey != "__info__":
542 582
                 print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
543 583
         elif message.topic == self.topic + '/get':
544 584
             self.__tx__(None)
@@ -566,26 +606,22 @@ class gui_light(tradfri_light):
566 606
                 self.print_formatted(self, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
567 607
             elif command == self.COLOR_TEMP_COMMANDS[1]:
568 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))
569 611
             else:
570 612
                 print("%s: not yet implemented!" % command)
571 613
         else:
572 614
             print("Unknown command!")
573 615
 
574
-    def add_led_name(self, key, name):
575
-        self.led_names[key] = name
576
-
577 616
     def print_formatted(self, device, key, value):
578 617
         if value is not None:
579 618
             device = " - ".join(self.topic.split('/')[1:])
580 619
             if key == self.KEY_STATE:
581 620
                 print_switch(COLOR_GUI_ACTIVE, value, self.topic, "")
582
-            elif key == self.KEY_ENABLE:
583
-                self.print_formatted(device, self.KEY_BRIGHTNESS, self.data.get(self.KEY_BRIGHTNESS))
584
-                self.print_formatted(device, self.KEY_COLOR_TEMP, self.data.get(self.KEY_COLOR_TEMP))
585 621
             elif key in [self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP]:
586 622
                 perc_value = round(value * 10 if key == self.KEY_COLOR_TEMP else value, 0)
587 623
                 print_percent(
588
-                    COLOR_GUI_PASSIVE if not self.data.get(self.KEY_ENABLE, False) else COLOR_GUI_ACTIVE,
624
+                    COLOR_GUI_ACTIVE,
589 625
                     'B' if key == self.KEY_BRIGHTNESS else 'C',
590 626
                     perc_value,
591 627
                     "%3d%%" % perc_value,
@@ -606,241 +642,191 @@ class gui_light(tradfri_light):
606 642
                     perc = 0
607 643
                     self.maxvalue = None
608 644
                 print_percent(COLOR_GUI_ACTIVE, 't', perc, '%3d%%' % perc, self.topic, '(%.1f)' % disp_value)
609
-            elif key.startswith(self.KEY_LED_X[:-2]):
610
-                print_light(COLOR_GUI_ACTIVE, value, self.topic, '(%s)' % self.led_names.get(key, key), True)
611
-
612 645
 
613
-class tradfri_button(base):
614
-    KEY_ACTION = "action"
615
-    #
616
-    ACTION_TOGGLE = "toggle"
617
-    ACTION_BRIGHTNESS_UP = "brightness_up_click"
618
-    ACTION_BRIGHTNESS_DOWN = "brightness_down_click"
619
-    ACTION_RIGHT = "arrow_right_click"
620
-    ACTION_LEFT = "arrow_left_click"
621
-    ACTION_BRIGHTNESS_UP_LONG = "brightness_up_hold"
622
-    ACTION_BRIGHTNESS_DOWN_LONG = "brightness_down_hold"
623
-    ACTION_RIGHT_LONG = "arrow_right_hold"
624
-    ACTION_LEFT_LONG = "arrow_left_hold"
625
-    #
626
-    COMMANDS = [ACTION_TOGGLE, ACTION_LEFT, ACTION_RIGHT, ACTION_BRIGHTNESS_UP, ACTION_BRIGHTNESS_DOWN,
627
-                ACTION_LEFT_LONG, ACTION_RIGHT_LONG, ACTION_BRIGHTNESS_UP_LONG, ACTION_BRIGHTNESS_DOWN_LONG]
628 646
 
629
-    def __init__(self, mqtt_client, topic):
630
-        super().__init__(mqtt_client, topic)
631
-
632
-    def __rx__(self, client, userdata, message):
633
-        pass
634
-
635
-    def command(self, command):
636
-        try:
637
-            command, value = command.split(' ')
638
-        except ValueError:
639
-            value = None
640
-        else:
641
-            value = json.loads(value)
642
-        if command in self.capabilities():
643
-            action = self.COMMANDS[self.COMMANDS.index(command)]
644
-            if self.COMMANDS.index(command) <= 4:
645
-                self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
646
-            elif self.COMMANDS.index(command) <= 8:
647
-                self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
648
-                time.sleep(value or 0.5)
649
-                action = '_'.join(action.split('_')[:-1] + ['release'])
650
-                self.mqtt_client.send(self.topic, json.dumps({self.KEY_ACTION: action}))
651
-
652
-
653
-class gui_led_array(base):
654
-    AUTOSEND = False
655
-    #
656
-    KEY_LED_0 = "led0"
657
-    KEY_LED_1 = "led1"
658
-    KEY_LED_2 = "led2"
659
-    KEY_LED_3 = "led3"
660
-    KEY_LED_4 = "led4"
661
-    KEY_LED_5 = "led5"
662
-    KEY_LED_6 = "led6"
663
-    KEY_LED_7 = "led7"
664
-    KEY_LED_8 = "led8"
665
-    KEY_LED_9 = "led9"
666
-
667
-    def __init__(self, mqtt_client, topic, ):
668
-        super().__init__(mqtt_client, topic)
669
-        for i in range(0, 10):
670
-            key = getattr(self, "KEY_LED_%d" % i)
671
-            self.data[key] = False
672
-            self.add_callback(key, self.print_formatted, None)
673
-
674
-    def __rx__(self, client, userdata, message):
675
-        value = payload_filter(message.payload)
676
-        if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
677
-            targetkey = message.topic.split('/')[-2]
678
-            if targetkey in self.data.keys():
679
-                self.store_data(**{targetkey: value})
680
-            else:
681
-                print("Unknown key %s in %s" % (targetkey, self.__class__.__name__))
682
-
683
-    def print_formatted(self, device, key, value):
684
-        print_light(COLOR_GUI_ACTIVE, value, self.topic, '(%s)' % self.names.get(key, key), True)
685
-
686
-
687
-class remote(base):
688
-    def __rx__(self, client, userdata, message):
689
-        if message.topic == self.topic + "/VOLUP":
690
-            if payload_filter(message.payload):
691
-                icon = u'\u1403'
692
-            else:
693
-                icon = u'\u25a1'
694
-        elif message.topic == self.topic + "/VOLDOWN":
695
-            if payload_filter(message.payload):
696
-                icon = u'\u1401'
697
-            else:
698
-                icon = u'\u25a1'
699
-        else:
700
-            return
701
-        devicename = ' - '.join(self.topic.split('/')[1:-1])
702
-        print(COLOR_REMOTE + 10 * ' ' + icon + 6 * ' ' + devicename + colored.attr("reset"))
703
-
704
-
705
-class brennenstuhl_heating_valve(base):
706
-    TEMP_RANGE = [10, 30]
707
-    #
708
-    KEY_TEMPERATURE_SETPOINT = "current_heating_setpoint"
709
-    KEY_TEMPERATURE = "local_temperature"
710
-    #
711
-    COMMANDS = [
712
-        "get_temperature_setpoint", "set_temperature_setpoint",
713
-    ]
714
-
715
-    def __init__(self, mqtt_client, topic):
716
-        super().__init__(mqtt_client, topic)
717
-        self.store_data(**{
718
-            self.KEY_TEMPERATURE_SETPOINT: 20,
719
-            self.KEY_TEMPERATURE: 20.7,
720
-        })
721
-        self.add_callback(self.KEY_TEMPERATURE_SETPOINT, self.print_formatted, None)
722
-
723
-    def __rx__(self, client, userdata, message):
724
-        if message.topic.startswith(self.topic) and message.topic.endswith("/set"):
725
-            payload = payload_filter(message.payload)
726
-            self.store_data(**payload)
727
-
728
-    def command(self, command):
729
-        try:
730
-            command, value = command.split(' ')
731
-        except ValueError:
732
-            value = None
733
-        if command in self.COMMANDS:
734
-            if command == self.COMMANDS[0]:
735
-                self.print_formatted(self, self.KEY_TEMPERATURE_SETPOINT, self.data.get(self.KEY_TEMPERATURE_SETPOINT))
736
-            elif command == self.COMMANDS[1]:
737
-                self.store_data(**{self.KEY_TEMPERATURE_SETPOINT: command_float_value(value)})
738
-
739
-    def print_formatted(self, device, key, value):
740
-        devicename = ' - '.join(self.topic.split('/')[1:])
741
-        if key == self.KEY_TEMPERATURE_SETPOINT:
742
-            perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
743
-            perc = 100 if perc > 100 else perc
744
-            perc = 0 if perc < 0 else perc
745
-            print_percent(COLOR_HEATING_VALVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "")
746
-
747
-
748
-class gui_heating_valve(base):
749
-    AUTOSEND = False
750
-    #
751
-    TEMP_RANGE = [10, 30]
752
-    #
753
-    KEY_TIMER = "timer"
754
-    KEY_TEMPERATURE = "temperature"
755
-    KEY_SETPOINT_TEMP = "setpoint_temp"
756
-    KEY_SETPOINT_TO_DEFAULT = "setpoint_to_default"
757
-    KEY_BOOST = 'boost'
758
-    KEY_AWAY = "away"
759
-    KEY_SUMMER = "summer"
760
-    KEY_ENABLE = "enable"
761
-    #
762
-    COMMANDS = [
763
-        "get_temperature",
764
-        "get_temperature_setpoint", "set_temperature_setpoint",
765
-        "trigger_boost", "trigger_setpoint_to_default",
766
-        "toggle_away", "toggle_summer",
767
-    ]
768
-
769
-    def __init__(self, mqtt_client, topic):
770
-        super().__init__(mqtt_client, topic)
771
-        self.add_callback(self.KEY_SETPOINT_TEMP, self.print_formatted, None)
772
-        self.add_callback(self.KEY_TIMER, self.print_formatted, None)
773
-        self.add_callback(self.KEY_AWAY, self.print_formatted, None)
774
-        self.add_callback(self.KEY_SUMMER, self.print_formatted, None)
775
-        #
776
-        self.store_data(**{
777
-            self.KEY_TEMPERATURE: 20.7,
778
-            self.KEY_SETPOINT_TEMP: 20,
779
-            self.KEY_TIMER: 0,
780
-            self.KEY_AWAY: False,
781
-            self.KEY_SUMMER: False,
782
-            self.KEY_ENABLE: True
783
-        })
784
-
785
-    def __rx__(self, client, userdata, message):
786
-        value = payload_filter(message.payload)
787
-        if message.topic.startswith(self.topic) and message.topic.endswith('/set'):
788
-            targetkey = message.topic.split('/')[-2]
789
-            if targetkey in self.data.keys():
790
-                self.store_data(**{targetkey: value})
791
-            else:
792
-                print("Unknown key %s in %s::%s" % (targetkey, message.topic, self.__class__.__name__))
793
-        elif message.topic == self.topic + '/get':
794
-            self.__tx__(None)
795
-
796
-    def send(self, key, data):
797
-        if data is not None:
798
-            topic = self.topic + '/' + key
799
-            self.mqtt_client.send(topic, json.dumps(data))
800
-
801
-    def command(self, command):
802
-        try:
803
-            command, value = command.split(' ')
804
-        except ValueError:
805
-            value = None
806
-        if command in self.COMMANDS:
807
-            if command == self.COMMANDS[0]:
808
-                self.print_formatted(self, self.KEY_TEMPERATURE, self.data.get(self.KEY_TEMPERATURE))
809
-            elif command == self.COMMANDS[1]:
810
-                self.print_formatted(self, self.KEY_SETPOINT_TEMP, self.data.get(self.KEY_SETPOINT_TEMP))
811
-            elif command == self.COMMANDS[2]:
812
-                self.send(self.KEY_SETPOINT_TEMP, command_float_value(value))
813
-            elif command == self.COMMANDS[3]:
814
-                self.send(self.KEY_BOOST, True)
815
-            elif command == self.COMMANDS[4]:
816
-                self.send(self.KEY_SETPOINT_TO_DEFAULT, True)
817
-            elif command == self.COMMANDS[5]:
818
-                self.send(self.KEY_AWAY, not self.data.get(self.KEY_AWAY))
819
-            elif command == self.COMMANDS[6]:
820
-                self.send(self.KEY_SUMMER, not self.data.get(self.KEY_SUMMER))
821
-
822
-    def print_formatted(self, device, key, value):
823
-        devicename = ' - '.join(self.topic.split('/')[1:])
824
-        if key == self.KEY_TIMER:
825
-            value /= 60
826
-            try:
827
-                perc = 100 * value / 60
828
-            except TypeError:
829
-                value = 0
830
-                perc = 0
831
-            print_percent(COLOR_GUI_ACTIVE, 't', perc, "%4.1fmin" % value, self.topic, "(Timer)")
832
-        elif key == self.KEY_TEMPERATURE:
833
-            perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
834
-            perc = 100 if perc > 100 else perc
835
-            perc = 0 if perc < 0 else perc
836
-            print_percent(COLOR_GUI_ACTIVE, '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Temperature)")
837
-        elif key == self.KEY_SETPOINT_TEMP:
838
-            perc = 100 * (value - self.TEMP_RANGE[0]) / (self.TEMP_RANGE[1] - self.TEMP_RANGE[0])
839
-            perc = 100 if perc > 100 else perc
840
-            perc = 0 if perc < 0 else perc
841
-            print_percent(COLOR_GUI_ACTIVE if self.data.get(self.KEY_ENABLE) else COLOR_GUI_PASSIVE,
842
-                          '\u03d1', perc, "%4.1f°C" % value, self.topic, "(Setpoint)")
843
-        elif key == self.KEY_AWAY:
844
-            print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Away Mode)")
845
-        elif key == self.KEY_SUMMER:
846
-            print_switch(COLOR_GUI_ACTIVE, value, self.topic, "(Summer Mode)")
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)")

+ 94
- 72
__simulation__/rooms.py Переглянути файл

@@ -1,6 +1,6 @@
1 1
 import config
2
-from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, tradfri_button, silvercrest_motion_sensor, my_powerplug, remote, brennenstuhl_heating_valve
3
-from __simulation__.devices import gui_light, gui_led_array, gui_heating_valve
2
+from __simulation__.devices import shelly, silvercrest_powerplug, tradfri_light, my_powerplug, brennenstuhl_heating_valve
3
+from __simulation__.devices import videv_light
4 4
 import inspect
5 5
 
6 6
 
@@ -40,58 +40,58 @@ class base(object):
40 40
 
41 41
 class gfw_floor(base):
42 42
     def __init__(self, mqtt_client):
43
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI, True, True, True)
44 43
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
45 44
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
46
-        self.main_light_zigbee_1 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False)
47
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_on, "on")
48
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
45
+        self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1, True, True, True, False)
46
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
47
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
49 48
         self.main_light_zigbee_2 = tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2, True, True, True, False)
50
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, "on")
51
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_1.power_off, "off")
49
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_on, True)
50
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee_2.power_off, False)
51
+
52
+        #
53
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV, True, True, True)
52 54
 
53 55
 
54 56
 class gfw_marion(base):
55 57
     def __init__(self, mqtt_client):
56
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI, True, False, False)
57 58
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
58 59
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
60
+
59 61
         self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
60
-        self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_GUI)
62
+
63
+        #
64
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV, True, False, False)
61 65
 
62 66
 
63 67
 class gfw_dirk(base):
64 68
     def __init__(self, mqtt_client):
65
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI, True, True, True)
66 69
         self.main_light = shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
67 70
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
68 71
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE, True, True, True)
69
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
70
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
71
-        #
72
-        self.powerplug = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
73
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
74
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_1, "Desk_Light")
75
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_2, "CD_Player")
76
-        self.powerplug.add_channel_name(my_powerplug.KEY_OUTPUT_3, "PC_Dock")
77
-        self.gui_amplifier = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI, True, False, False)
78
-        self.gui_desk_light = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI, True, True, True)
72
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
73
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
74
+
75
+        self.amplifier = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 0)
76
+        self.amplifier.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Amplifier")
77
+        self.desk_light = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 1)
78
+        self.desk_light.add_channel_name(my_powerplug.KEY_OUTPUT_0, "Desk Light")
79
+        self.cd_player = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 2)
80
+        self.cd_player.add_channel_name(my_powerplug.KEY_OUTPUT_0, "CD_Player")
81
+        self.pc_dock = my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG, 3)
82
+        self.pc_dock.add_channel_name(my_powerplug.KEY_OUTPUT_0, "PC_Dock")
79 83
         self.desk_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE, True, True, True)
80
-        self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_on, True)
81
-        self.powerplug.add_callback(my_powerplug.KEY_OUTPUT_1, self.desk_light_zigbee.power_off, False)
82
-        self.gui_cd_player = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI, True, False, False)
83
-        self.gui_pc_dock = gui_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI, True, False, False)
84
-        #
85
-        self.remote = remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
86
-        #
87
-        self.input_device = tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
88
-        self.led_array = gui_led_array(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
89
-        self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
90
-        self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Desk Light")
91
-        self.led_array.add_channel_name(gui_led_array.KEY_LED_2, "Amplifier")
92
-        #
84
+        self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, self.desk_light_zigbee.power_on, True)
85
+        self.desk_light.add_callback(my_powerplug.KEY_OUTPUT_0, self.desk_light_zigbee.power_off, False)
86
+
93 87
         self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
94
-        self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_GUI)
88
+
89
+        #
90
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV, True, True, True)
91
+        self.videv_amplifier = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV, True, False, False)
92
+        self.videv_desk_light = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV, True, True, True)
93
+        self.videv_cd_player = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV, True, False, False)
94
+        self.videv_pc_dock = videv_light(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV, True, False, False)
95 95
 
96 96
 
97 97
 class gfw(base):
@@ -103,32 +103,43 @@ class gfw(base):
103 103
 
104 104
 class ffw_julian(base):
105 105
     def __init__(self, mqtt_client):
106
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_GUI, True, True, True)
107 106
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
108 107
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
109 108
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_ZIGBEE, True, True, True)
110
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
111
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
109
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
110
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
111
+
112
+        #
113
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_JULIAN_MAIN_LIGHT_VIDEV, True, True, True)
112 114
 
113 115
 
114 116
 class ffw_livingroom(base):
115 117
     def __init__(self, mqtt_client):
116
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
117 118
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
118 119
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
120
+        self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
121
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
122
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
123
+
124
+        #
125
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
119 126
 
120 127
 
121 128
 class ffw_sleep(base):
122 129
     def __init__(self, mqtt_client):
123
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_GUI, True, True, False)
124 130
         self.main_light = shelly(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
125 131
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
132
+        self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
133
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
134
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
135
+
136
+        #
137
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFW_SLEEP_MAIN_LIGHT_VIDEV, True, True, False)
126 138
 
127 139
 
128 140
 class ffw_bath(base):
129 141
     def __init__(self, mqtt_client):
130 142
         self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_ZIGBEE)
131
-        self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFW_BATH_HEATING_VALVE_GUI)
132 143
 
133 144
 
134 145
 class ffw(base):
@@ -141,77 +152,90 @@ class ffw(base):
141 152
 
142 153
 class ffe_floor(base):
143 154
     def __init__(self, mqtt_client):
144
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI, True, False, False)
145 155
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
146 156
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
147 157
 
158
+        #
159
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV, True, False, False)
160
+
148 161
 
149 162
 class ffe_kitchen(base):
150 163
     def __init__(self, mqtt_client):
151
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI, True, False, False)
152 164
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
153 165
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
154
-        #
155
-        self.gui_circulation_pump = gui_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_GUI, True, False, False)
166
+
156 167
         self.circulation_pump = shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY,
157 168
                                        input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER, output_0_auto_off=10*60)
158 169
         self.circulation_pump.add_channel_name(shelly.KEY_OUTPUT_0, "Circulation Pump")
159 170
 
171
+        #
172
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV, True, False, False)
173
+        self.videv_circulation_pump = videv_light(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV, True, False, False, True)
174
+
160 175
 
161 176
 class ffe_diningroom(base):
162 177
     def __init__(self, mqtt_client):
163
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI, True, False, False)
164 178
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
165 179
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
166
-        self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI, True, False, False)
180
+
167 181
         self.floor_lamp = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
168 182
         self.floor_lamp.add_channel_name(silvercrest_powerplug.KEY_OUTPUT_0, "Floor Lamp")
183
+
169 184
         if config.CHRISTMAS:
170 185
             self.garland = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
171 186
             self.garland.add_channel_name(silvercrest_powerplug, "Garland")
172 187
 
188
+        #
189
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV, True, False, False)
190
+        self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV, True, False, False)
191
+        if config.CHRISTMAS:
192
+            self.videv_garland = videv_light(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV, True, False, False)
193
+
173 194
 
174 195
 class ffe_sleep(base):
175 196
     def __init__(self, mqtt_client):
176
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, True, True, True)
177 197
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
178 198
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
179 199
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE, True, True, True)
180
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
181
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
182
-        #
183
-        self.gui_bed_light_di = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI, True, True, False)
200
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
201
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
202
+
184 203
         self.bed_light_di_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE, True, True, False)
185
-        self.gui_bed_light_ma = gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI, True, False, False)
186
-        self.bed_light_ma_powerplug = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
187
-        #
188
-        self.input_device = tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
189
-        self.led_array = gui_led_array(mqtt_client, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
190
-        self.led_array.add_channel_name(gui_led_array.KEY_LED_0, "Main Light")
191
-        self.led_array.add_channel_name(gui_led_array.KEY_LED_1, "Bed Light Dirk")
192
-        #
204
+        self.bed_light_ma = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
205
+
193 206
         self.heating_valve = brennenstuhl_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
194
-        self.gui_heating_valve = gui_heating_valve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_GUI)
207
+
208
+        #
209
+        self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False)
210
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV, True, True, True)
211
+        self.videv_bed_light_di = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV, True, True, False)
212
+        self.videv_bed_light_ma = videv_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV, True, False, False)
195 213
 
196 214
 
197 215
 class ffe_livingroom(base):
198 216
     def __init__(self, mqtt_client):
199
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, True, True, True)
200 217
         self.main_light = shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
201 218
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
202 219
         self.main_light_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE, True, True, True)
203
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, "on")
204
-        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, "off")
205
-        for i in range(1, 7):
220
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_on, True)
221
+        self.main_light.add_callback(shelly.KEY_OUTPUT_0, self.main_light_zigbee.power_off, False)
222
+
223
+        self.floor_lamp_zigbee = tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % 1, True, True, True)
224
+        for i in range(2, 7):
206 225
             setattr(self, "floor_lamp_zigbee_%d" % i, tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i, True, True, True))
207
-        self.gui_floor_lamp = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI, True, True, True)
226
+
208 227
         if config.CHRISTMAS:
209 228
             self.xmas_tree = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
210 229
             self.xmas_tree.add_channel_name(silvercrest_powerplug, "Xmas-Tree")
211
-            self.gui_xmas_tree = gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
212 230
             self.xmas_star = silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
213 231
             self.xmas_star.add_channel_name(silvercrest_powerplug, "Xmas-Star")
214 232
 
233
+        #
234
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV, True, True, True)
235
+        self.videv_floor_lamp = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV, True, True, True)
236
+        if config.CHRISTMAS:
237
+            self.videv_xmas_tree = videv_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV)
238
+
215 239
 
216 240
 class ffe(base):
217 241
     def __init__(self, mqtt_client):
@@ -224,13 +248,11 @@ class ffe(base):
224 248
 
225 249
 class stairway(base):
226 250
     def __init__(self, mqtt_client):
227
-        self.gui_main_light = gui_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_GUI, True, False, False)
228
-        self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 0, "Motion Ground Floor")
229
-        self.gui_main_light.add_led_name(self.gui_main_light.KEY_LED_X % 1, "Motion First Floor")
230 251
         self.main_light = shelly(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_SHELLY, input_0_func=shelly.INPUT_FUNC_OUT1_TRIGGER)
231 252
         self.main_light.add_channel_name(shelly.KEY_OUTPUT_0, "Main Light")
232
-        self.motion_sensor_gf = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_GF)
233
-        self.motion_sensor_ff = silvercrest_motion_sensor(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_MOTION_SENSOR_FF)
253
+
254
+        #
255
+        self.videv_main_light = videv_light(mqtt_client, config.TOPIC_STW_STAIRWAY_MAIN_LIGHT_VIDEV, True, False, False, True)
234 256
 
235 257
 
236 258
 class house(base):

+ 238
- 221
__simulation__/test.py Переглянути файл

@@ -1,232 +1,249 @@
1 1
 import colored
2
+import inspect
3
+from __simulation__ import devices
2 4
 import time
3 5
 
4 6
 
5
-DT_TOGGLE = 0.1
7
+DT_TOGGLE = 0.3
8
+
9
+
10
+TEST_FULL = 'full'
11
+TEST_SMOKE = 'smoke'
12
+#
13
+COLOR_SUCCESS = colored.fg("light_green")
14
+COLOR_FAIL = colored.fg("light_red")
6 15
 
7 16
 
8 17
 class test_smarthome(object):
9
-    def __init__(self, house):
10
-        self.house = house
11
-
12
-    def __smoke__(self):
13
-        result = ""
14
-        result += "Smoke-Test\n"
15
-        result += "  GUI Element exists for every shelly instance\n"
16
-        result += self.__gui_element_exists__("shelly")
17
-        result += "  On-Off test for every shelly instance\n"
18
-        result += self.__on_off_test__("shelly")
19
-        result += "  GUI Element exists for every silvercrest_powerplug instance\n"
20
-        result += self.__gui_element_exists__("silvercrest_powerplug")
21
-        result += "  On-Off test for every silvercrest_powerplug instance\n"
22
-        result += self.__on_off_test__("silvercrest_powerplug")
23
-        result += "  GUI Element exists for every my_powerplug instance and port\n"
24
-        result += self.__gui_element_exists_my_powerplug__()
25
-        result += "  On-Off test for every my_powerplug instance\n"
26
-        result += self.__on_off_test_my_powerplug__()
27
-        result += "  GUI Element exists for every tradfri_light instance\n"
28
-        result += self.__gui_element_exists__("tradfri_light")
29
-        result += "  Enable and disable test for gui elements corresponding with tradfri_light\n"
30
-        result += self.__br_ct_enable_test__()
31
-        result += "  Chnage brightness and color_temp by gui test\n"
32
-        result += self.__br_ct_change_test__()
33
-        return result
34
-
35
-    def __full__(self):
36
-        result = "Full-Test"
37
-        return result
38
-
39
-    def smoke(self):
40
-        print(self.__smoke__())
41
-
42
-    def full(self):
43
-        out = self.__smoke__()
44
-        out += self.__full__()
45
-        print(out)
46
-
47
-    def print_error(self, text, lvl=2):
48
-        return lvl*"  " + colored.fg("light_red") + '* ' + text + "\n" + colored.attr("reset")
49
-
50
-    def print_success(self, text, lvl=2):
51
-        return lvl*"  " + colored.fg("light_green") + '* ' + text + "\n" + colored.attr("reset")
52
-
53
-    def __gui_element_exists__(self, obj_name):
54
-        result = ""
55
-        for member in self.house.getmembers():
56
-            obj = self.house.getobjbyname(member)
57
-            if obj.__class__.__name__ == obj_name:
58
-                if obj_name == "tradfri_light":
59
-                    basename = member[:member.index('_zigbee')]
60
-                else:
61
-                    basename = member
18
+    def __init__(self, rooms):
19
+        # add testcases by room objects
20
+        for name in rooms.getmembers():
21
+            obj = rooms.getobjbyname(name)
22
+            if obj.__class__.__name__ == "videv_light":
23
+                common_name = '.'.join(name.split('.')[:-1]) + '.' + name.split('.')[-1][6:]
24
+                li_device = rooms.getobjbyname(common_name + '_zigbee') if obj.enable_brightness or obj.enable_color_temp else None
62 25
                 try:
63
-                    gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
26
+                    sw_device = rooms.getobjbyname(common_name) if obj.enable_state else None
64 27
                 except AttributeError:
65
-                    result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj_name))
66
-                else:
67
-                    result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj_name))
68
-        return result
69
-
70
-    def __gui_element_exists_my_powerplug__(self):
71
-        result = ""
72
-        for member in self.house.getmembers():
73
-            obj = self.house.getobjbyname(member)
74
-            if obj.__class__.__name__ == "my_powerplug":
75
-                for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
76
-                    try:
77
-                        gui = self.house.getobjbyname('.'.join(member.split(
78
-                            '.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
79
-                    except AttributeError:
80
-                        result += self.print_error("No GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
81
-                    else:
82
-                        result += self.print_success("GUI element available, while testing %s (%s)." % (member, obj.names.get(channel)))
83
-        return result
84
-
85
-    def __on_off_test_my_powerplug__(self):
86
-        result = ""
87
-        for member in self.house.getmembers():
88
-            obj = self.house.getobjbyname(member)
89
-            if obj.__class__.__name__ == "my_powerplug":
90
-                for channel in [obj.KEY_OUTPUT_0, obj.KEY_OUTPUT_1, obj.KEY_OUTPUT_2, obj.KEY_OUTPUT_3]:
91
-                    try:
92
-                        gui = self.house.getobjbyname('.'.join(member.split(
93
-                            '.')[:-1]) + '.gui_' + obj.names.get(channel.lower(), "__dummy__").lower())
94
-                    except AttributeError:
95
-                        raise AttributeError
96
-                        pass  # exists test already covers non existing gui-elements
97
-                    else:
98
-                        success = True
99
-                        # Initial state equal between obj and gui
100
-                        obj_state = obj.data.get(channel)
101
-                        gui_state = gui.data.get(gui.KEY_STATE)
102
-                        if obj_state != gui_state:
103
-                            result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
104
-                                                       ("my_powerplug", obj_state, gui_state, member, obj.names.get(channel)))
105
-                            success = False
106
-                        # state obj change results in state change of obj and gui
107
-                        for i in range(1, 3):
108
-                            gui.command("toggle_state")
109
-                            time.sleep(2 * DT_TOGGLE)
110
-                            last_obj_state = obj_state
111
-                            obj_state = obj.data.get(channel)
112
-                            gui_state = gui.data.get(gui.KEY_STATE)
113
-                            if last_obj_state == obj_state:
114
-                                result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
115
-                                                           (i, obj_state, member, obj.names.get(channel)))
116
-                                success = False
117
-                            if obj_state != gui_state:
118
-                                result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
119
-                                                           (i, obj_state, gui_state, member, obj.names.get(channel)))
120
-                                success = False
121
-                        #
122
-                        if success:
123
-                            result += self.print_success("On-Off test successfull, while testing %s (%s)." % (member, obj.names.get(channel)))
124
-        return result
125
-
126
-    def __on_off_test__(self, obj_name):
127
-        result = ""
128
-        for member in self.house.getmembers():
129
-            obj = self.house.getobjbyname(member)
130
-            if obj.__class__.__name__ == obj_name:
28
+                    # must be a device without switching device
29
+                    sw_device = li_device
30
+                setattr(self, common_name.replace('.', '_'), testcase_light(obj, sw_device, li_device))
31
+        # add test collection
32
+        self.all = test_collection(self)
33
+
34
+    def getmembers(self, prefix=''):
35
+        rv = []
36
+        for name, obj in inspect.getmembers(self):
37
+            if prefix:
38
+                full_name = prefix + '.' + name
39
+            else:
40
+                full_name = name
41
+            if not name.startswith('_'):
131 42
                 try:
132
-                    gui = self.house.getobjbyname('.'.join(member.split('.')[:-1]) + '.gui_' + member.split('.')[-1])
43
+                    if obj.__class__.__bases__[0].__name__ == "testcase" or obj.__class__.__name__ == "test_collection":
44
+                        rv.append(full_name)
45
+                    else:
46
+                        rv.extend(obj.getmembers(full_name))
133 47
                 except AttributeError:
134
-                    pass  # exists test already covers non existing gui-elements
135
-                else:
136
-                    success = True
137
-                    # Initial state equal between obj and gui
138
-                    obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
139
-                    gui_state = gui.data.get(gui.KEY_STATE)
140
-                    if obj_state != gui_state:
141
-                        result += self.print_error("Initial state of %s (%s) is not equal to GUI state (%s), while testing %s (%s)" %
142
-                                                   (obj_name, obj_state, gui_state, member, obj_name))
143
-                        success = False
144
-                    # state obj change results in state change of obj and gui
145
-                    for i in range(1, 3):
146
-                        gui.command("toggle_state")
147
-                        time.sleep(2 * DT_TOGGLE)
148
-                        last_obj_state = obj_state
149
-                        obj_state = obj.data.get(obj.KEY_OUTPUT_0).lower() == "on"
150
-                        gui_state = gui.data.get(gui.KEY_STATE)
151
-                        if last_obj_state == obj_state:
152
-                            result += self.print_error("State after %d. toggle of gui state: State unchanged (%s), while testing %s (%s)" %
153
-                                                       (i, obj_state, member, obj_name))
154
-                            success = False
155
-                        if obj_state != gui_state:
156
-                            result += self.print_error("State after %d. toggle of gui state:: State of device (%s) is not equal to GUI state (%s), while testing %s (%s)" %
157
-                                                       (i, obj_state, gui_state, member, obj_name))
158
-                            success = False
159
-                    #
160
-                    if success:
161
-                        result += self.print_success("On-Off test successfull, while testing %s." % (member))
162
-        return result
163
-
164
-    def __br_ct_enable_test__(self):
165
-        result = ""
166
-        for member in self.house.getmembers():
167
-            obj = self.house.getobjbyname(member)
168
-            if obj.__class__.__name__ == "tradfri_light":
169
-                basename = member[:member.index('_zigbee')]
170
-                gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
171
-                success = True
172
-                #
173
-                if gui.data.get(gui.KEY_ENABLE) != False:
174
-                    result += self.print_error("Inital enable state is not False, while testing %s." % (member))
175
-                    success = False
176
-                #
177
-                gui.command("toggle_state")
178
-                time.sleep(2 * DT_TOGGLE)
179
-                if gui.data.get(gui.KEY_ENABLE) != True:
180
-                    result += self.print_error("Enable state is not True after switching on, while testing %s." % (member))
181
-                    success = False
182
-                #
183
-                gui.command("toggle_state")
184
-                time.sleep(2 * DT_TOGGLE)
185
-                if gui.data.get(gui.KEY_ENABLE) != False:
186
-                    result += self.print_error("Enable state is not False after switching off, while testing %s." % (member))
187
-                    success = False
188
-                #
189
-                if success:
190
-                    result += self.print_success("Enable-Disable test successfull, while testing %s." % (member))
191
-        return result
192
-
193
-    def __br_ct_change_test__(self):
194
-        result = ""
195
-        for member in self.house.getmembers():
196
-            obj = self.house.getobjbyname(member)
197
-            if obj.__class__.__name__ == "tradfri_light":
198
-                basename = member[:member.index('_zigbee')]
199
-                gui = self.house.getobjbyname('.'.join(basename.split('.')[:-1]) + '.gui_' + basename.split('.')[-1])
200
-                success = True
201
-                #
202
-                if gui.data.get(gui.KEY_STATE) != True:
203
-                    gui.command("toggle_state")
204
-                    time.sleep(2 * DT_TOGGLE)
205
-                if gui.data.get(gui.KEY_STATE) != True:
206
-                    result += self.print_error("Unable to switch on light, while testing %s." % (member))
207
-                    success = False
208
-                    continue
209
-                #
210
-                if "set_brightness" in obj.capabilities():
211
-                    brightness = gui.data.get(obj.KEY_BRIGHTNESS)
212
-                    targetvalue = brightness + (25 if brightness <= 50 else -25)
213
-                    gui.command("set_brightness %d" % targetvalue)
214
-                    time.sleep(2 * DT_TOGGLE)
215
-                    if gui.data.get(obj.KEY_BRIGHTNESS) != targetvalue:
216
-                        result += self.print_error("Brightness change by gui was not successfull, while testing %s." % (member))
217
-                        success = False
218
-                if "set_color_temp" in obj.capabilities():
219
-                    color_temp = gui.data.get(obj.KEY_COLOR_TEMP)
220
-                    targetvalue = color_temp + (3 if color_temp <= 5 else -3)
221
-                    gui.command("set_color_temp %d" % targetvalue)
222
-                    time.sleep(2 * DT_TOGGLE)
223
-                    if gui.data.get(obj.KEY_COLOR_TEMP) != targetvalue:
224
-                        result += self.print_error("Color temperature change by gui was not successfull, while testing %s." % (member))
225
-                        success = False
226
-                #
227
-                gui.command("toggle_state")
228
-                time.sleep(2 * DT_TOGGLE)
229
-                #
230
-                if success:
231
-                    result += self.print_success("Brightness-ColorTemp test successfull, while testing %s." % (member))
232
-        return result
48
+                    pass
49
+        return rv
50
+
51
+    def getobjbyname(self, name):
52
+        if name.startswith("test."):
53
+            name = name[5:]
54
+        obj = self
55
+        for subname in name.split('.'):
56
+            obj = getattr(obj, subname)
57
+        return obj
58
+
59
+    def command(self, full_command):
60
+        try:
61
+            parameter = " " + full_command.split(' ')[1]
62
+        except IndexError:
63
+            parameter = ""
64
+        command = full_command.split(' ')[0].split('.')[-1] + parameter
65
+        device_name = '.'.join(full_command.split(' ')[0].split('.')[:-1])
66
+        self.getobjbyname(device_name).command(command)
67
+
68
+
69
+class test_result_base(object):
70
+    def __init__(self):
71
+        self.__init_test_counters__()
72
+
73
+    def __init_test_counters__(self):
74
+        self.test_counter = 0
75
+        self.success_tests = 0
76
+        self.failed_tests = 0
77
+
78
+    def statistic(self):
79
+        return (self.test_counter, self.success_tests, self.failed_tests)
80
+
81
+    def print_statistic(self):
82
+        color = COLOR_SUCCESS if self.test_counter == self.success_tests else COLOR_FAIL
83
+        print(color + "*** SUCCESS: (%4d/%4d)   FAIL: (%4d/%4d) ***\n" % (self.success_tests,
84
+              self.test_counter, self.failed_tests, self.test_counter) + colored.attr("reset"))
85
+
86
+
87
+class test_collection(test_result_base):
88
+    def __init__(self, test_instance):
89
+        super().__init__()
90
+        self.test_instance = test_instance
91
+
92
+    def capabilities(self):
93
+        return [TEST_FULL, TEST_SMOKE]
94
+
95
+    def command(self, command):
96
+        self.__init_test_counters__()
97
+        for member in self.test_instance.getmembers():
98
+            obj = self.test_instance.getobjbyname(member)
99
+            if id(obj) != id(self):
100
+                obj.test_all(command)
101
+                num, suc, fail = obj.statistic()
102
+                self.test_counter += num
103
+                self.success_tests += suc
104
+                self.failed_tests += fail
105
+        self.print_statistic()
106
+
107
+
108
+class testcase(test_result_base):
109
+    def __init__(self):
110
+        super().__init__()
111
+        self.__test_list__ = []
112
+
113
+    def capabilities(self):
114
+        if len(self.__test_list__) > 0 and not 'test_all' in self.__test_list__:
115
+            self.__test_list__.append('test_all')
116
+        self.__test_list__.sort()
117
+        return self.__test_list__
118
+
119
+    def test_all(self, test=TEST_FULL):
120
+        test_counter = 0
121
+        success_tests = 0
122
+        failed_tests = 0
123
+        for tc_name in self.capabilities():
124
+            if tc_name != "test_all":
125
+                self.command(tc_name, test)
126
+                test_counter += self.test_counter
127
+                success_tests += self.success_tests
128
+                failed_tests += self.failed_tests
129
+        self.test_counter = test_counter
130
+        self.success_tests = success_tests
131
+        self.failed_tests = failed_tests
132
+
133
+    def command(self, command, test=TEST_FULL):
134
+        self.__init_test_counters__()
135
+        tc = getattr(self, command)
136
+        self.__init_test_counters__()
137
+        rv = tc(test)
138
+        self.print_statistic()
139
+
140
+    def heading(self, desciption):
141
+        print(desciption)
142
+
143
+    def sub_heading(self, desciption):
144
+        print(2 * " " + desciption)
145
+
146
+    def result(self, desciption, success):
147
+        self.test_counter += 1
148
+        if success:
149
+            self.success_tests += 1
150
+        else:
151
+            self.failed_tests += 1
152
+        print(4 * " " + ("SUCCESS - " if success else "FAIL    - ") + desciption)
153
+
154
+
155
+class testcase_light(testcase):
156
+    def __init__(self, videv, sw_device, li_device):
157
+        self.videv = videv
158
+        self.sw_device = sw_device
159
+        self.li_device = li_device
160
+        self.__test_list__ = []
161
+        if self.videv.enable_state:
162
+            self.__test_list__.append('test_power_on_off')
163
+        if self.videv.enable_brightness:
164
+            self.__test_list__.append('test_brightness')
165
+        if self.videv.enable_color_temp:
166
+            self.__test_list__.append('test_color_temp')
167
+
168
+    def test_power_on_off(self, test=TEST_FULL):
169
+        self.heading("Power On/ Off test (%s)" % self.videv.topic)
170
+        #
171
+        sw_state = self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0)
172
+        #
173
+        for i in range(0, 2):
174
+            self.sub_heading("State change of switching device")
175
+            #
176
+            self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: not self.sw_device.data.get(self.sw_device.KEY_OUTPUT_0)})
177
+            time.sleep(DT_TOGGLE)
178
+            self.result("Virtual device state after Switch on by switching device", sw_state != self.videv.get_data(self.videv.KEY_STATE))
179
+            self.result("Switching device state after Switch on by switching device",
180
+                        sw_state != self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0))
181
+
182
+            self.sub_heading("State change of virtual device")
183
+            #
184
+            self.videv.send(self.videv.KEY_STATE, not self.videv.data.get(self.videv.KEY_STATE))
185
+            time.sleep(DT_TOGGLE)
186
+            self.result("Virtual device state after Switch off by virtual device", sw_state == self.videv.get_data(self.videv.KEY_STATE))
187
+            self.result("Switching device state after Switch on by switching device",
188
+                        sw_state == self.sw_device.get_data(self.sw_device.KEY_OUTPUT_0))
189
+
190
+    def test_brightness(self, test=TEST_FULL):
191
+        self.heading("Brightness test (%s)" % self.videv.topic)
192
+        #
193
+        br_state = self.li_device.get_data(self.li_device.KEY_BRIGHTNESS)
194
+        delta = -15 if br_state > 50 else 15
195
+
196
+        self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: True})
197
+        time.sleep(DT_TOGGLE)
198
+
199
+        for i in range(0, 2):
200
+            self.sub_heading("Brightness change by light device")
201
+            #
202
+            self.li_device.store_data(**{self.li_device.KEY_BRIGHTNESS: br_state + delta})
203
+            time.sleep(DT_TOGGLE)
204
+            self.result("Virtual device state after setting brightness by light device",
205
+                        br_state + delta == self.videv.get_data(self.videv.KEY_BRIGHTNESS))
206
+            self.result("Light device state after setting brightness by light device", br_state +
207
+                        delta == self.li_device.get_data(self.li_device.KEY_BRIGHTNESS))
208
+
209
+            self.sub_heading("Brightness change by virtual device")
210
+            #
211
+            self.videv.send(self.videv.KEY_BRIGHTNESS, br_state)
212
+            time.sleep(DT_TOGGLE)
213
+            self.result("Virtual device state after setting brightness by light device", br_state == self.videv.get_data(self.videv.KEY_BRIGHTNESS))
214
+            self.result("Light device state after setting brightness by light device",
215
+                        br_state == self.li_device.get_data(self.li_device.KEY_BRIGHTNESS))
216
+
217
+        self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: False})
218
+        time.sleep(DT_TOGGLE)
219
+
220
+    def test_color_temp(self, test=TEST_FULL):
221
+        self.heading("Color temperature test (%s)" % self.videv.topic)
222
+        #
223
+        ct_state = self.li_device.get_data(self.li_device.KEY_COLOR_TEMP)
224
+        delta = -3 if ct_state > 5 else 3
225
+
226
+        self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: True})
227
+        time.sleep(DT_TOGGLE)
228
+
229
+        for i in range(0, 2):
230
+            self.sub_heading("Color temperature change by light device")
231
+            #
232
+            self.li_device.store_data(**{self.li_device.KEY_COLOR_TEMP: ct_state + delta})
233
+            time.sleep(DT_TOGGLE)
234
+            self.result("Virtual device state after setting color temperature by light device",
235
+                        ct_state + delta == self.videv.get_data(self.videv.KEY_COLOR_TEMP))
236
+            self.result("Light device state after setting color temperature by light device", ct_state +
237
+                        delta == self.li_device.get_data(self.li_device.KEY_COLOR_TEMP))
238
+
239
+            self.sub_heading("Color temperature change by virtual device")
240
+            #
241
+            self.videv.send(self.videv.KEY_COLOR_TEMP, ct_state)
242
+            time.sleep(DT_TOGGLE)
243
+            self.result("Virtual device state after setting color temperature by light device",
244
+                        ct_state == self.videv.get_data(self.videv.KEY_COLOR_TEMP))
245
+            self.result("Light device state after setting color temperature by light device",
246
+                        ct_state == self.li_device.get_data(self.li_device.KEY_COLOR_TEMP))
247
+
248
+        self.sw_device.store_data(**{self.sw_device.KEY_OUTPUT_0: False})
249
+        time.sleep(DT_TOGGLE)

+ 7
- 3
house_n_gui_sim.py Переглянути файл

@@ -13,7 +13,7 @@ if __name__ == "__main__":
13 13
     mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
14 14
                           password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
15 15
     #
16
-    COMMANDS = ['quit', 'help', 'test.smoke', 'test.full']
16
+    COMMANDS = ['quit', 'help']
17 17
     #
18 18
     h = house(mc)
19 19
     for name in h.getmembers():
@@ -22,6 +22,10 @@ if __name__ == "__main__":
22 22
             COMMANDS.append(name + '.' + c)
23 23
     #
24 24
     ts = test_smarthome(h)
25
+    for name in ts.getmembers():
26
+        d = ts.getobjbyname(name)
27
+        for c in d.capabilities():
28
+            COMMANDS.append('test.' + name + '.' + c)
25 29
 
26 30
     def reduced_list(text):
27 31
         """
@@ -68,8 +72,8 @@ if __name__ == "__main__":
68 72
             break
69 73
         elif userfeedback == 'help':
70 74
             print("Help is not yet implemented!")
71
-        elif userfeedback == 'test.full':
72
-            ts.full()
75
+        elif userfeedback.startswith("test"):
76
+            ts.command(userfeedback)
73 77
         elif userfeedback == 'test.smoke':
74 78
             ts.smoke()
75 79
         elif command in COMMANDS[2:]:

+ 11
- 3
smart_brain.py Переглянути файл

@@ -7,11 +7,19 @@ import time
7 7
 
8 8
 logger = logging.getLogger(config.APP_NAME)
9 9
 
10
-# TODO: Change Nodered topics to videv
11
-# TODO: Extend virtual devices
10
+# TODO: Extend virtual devices and implement all_off functionality in function.all_functions.init_off_functionality
12 11
 #         * All Off
13 12
 #         * ...
14
-# TODO: Remove gui from rooms and devices
13
+# TODO: Restructure nodered gui (own heating page - with circulation pump)
14
+# TODO: Extend tests in simulation
15
+#         - Synch functions (ffe.livingroom.floorlamp [with main_light and 1-6], ffe.diningroom/floorlamp, ffe.dirk.amplifier (with spotify, mpd, cd_player), gfw.floor.main_light)
16
+#         - Remote actions after amplifier on
17
+#         - Switching button functions (gfw_dirk, ffe.sleep)
18
+#         - Heating functionality (base: set temp, set default, away_mode, summer_mode, start and stop boost)
19
+#         - Brightness button functions (gfw.dirk, ffe.sleep)
20
+#         - Motion stairways (incl. sensor feedback)
21
+#         - Heating functionality (extended: timer)
22
+#         - Timer (circulation and stairways)
15 23
 # TODO: Rework devices to base.mqtt (pack -> set, ...)
16 24
 # TODO: Implement handling of warnings (videv element to show in webapp?)
17 25
 

Завантаження…
Відмінити
Зберегти