Browse Source

Logging for devices improved

tags/v1.0.0
Dirk Alders 2 years ago
parent
commit
ec23cfca2d
1 changed files with 31 additions and 31 deletions
  1. 31
    31
      devices/__init__.py

+ 31
- 31
devices/__init__.py View File

96
             self.__previous__[key] = prev_value
96
             self.__previous__[key] = prev_value
97
             # Filter, if needed
97
             # Filter, if needed
98
             self.unpack_filter(key)
98
             self.unpack_filter(key)
99
-            self.logger.debug("Received data for (%s) %s - %s", self.topic, key, str(self.get(key)))
99
+            self.logger.debug("Received data %s - %s", key, str(self.get(key)))
100
             self.callback_caller(key, self[key], self.get(key) != self.__previous__.get(key))
100
             self.callback_caller(key, self[key], self.get(key) != self.__previous__.get(key))
101
         elif key not in self.RX_IGNORE_KEYS:
101
         elif key not in self.RX_IGNORE_KEYS:
102
-            self.logger.warning('Got a message from \"%s\" with unparsed content "%s"', self.topic, key)
102
+            self.logger.warning('Got a message with unparsed content: "%s - %s"', key, str(data))
103
         else:
103
         else:
104
             self.logger.debug("Ignoring key %s", key)
104
             self.logger.debug("Ignoring key %s", key)
105
 
105
 
141
             if self.TX_TYPE < 0:
141
             if self.TX_TYPE < 0:
142
                 self.logger.error("Unknown tx type. Set TX_TYPE of class to a known value")
142
                 self.logger.error("Unknown tx type. Set TX_TYPE of class to a known value")
143
             else:
143
             else:
144
-                self.logger.debug("Sending data for (%s) %s - %s", self.topic, key, str(data))
144
+                self.logger.debug("Sending data for %s - %s", key, str(data))
145
                 if self.TX_TYPE == self.TX_DICT:
145
                 if self.TX_TYPE == self.TX_DICT:
146
                     self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
146
                     self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
147
                 else:
147
                 else:
274
         self.pack(self.KEY_OUTPUT_0, state)
274
         self.pack(self.KEY_OUTPUT_0, state)
275
 
275
 
276
     def set_output_0_mcb(self, device, key, data):
276
     def set_output_0_mcb(self, device, key, data):
277
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
277
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
278
         self.set_output_0(data)
278
         self.set_output_0(data)
279
 
279
 
280
     def toggle_output_0_mcb(self, device, key, data):
280
     def toggle_output_0_mcb(self, device, key, data):
281
-        self.logger.info("%s: Toggeling output 0", self.topic)
281
+        self.logger.info("Toggeling output 0")
282
         self.set_output_0('toggle')
282
         self.set_output_0('toggle')
283
 
283
 
284
     def set_output_1(self, state):
284
     def set_output_1(self, state):
286
         self.pack(self.KEY_OUTPUT_1, state)
286
         self.pack(self.KEY_OUTPUT_1, state)
287
 
287
 
288
     def set_output_1_mcb(self, device, key, data):
288
     def set_output_1_mcb(self, device, key, data):
289
-        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
289
+        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
290
         self.set_output_1(data)
290
         self.set_output_1(data)
291
 
291
 
292
     def toggle_output_1_mcb(self, device, key, data):
292
     def toggle_output_1_mcb(self, device, key, data):
293
-        self.logger.info("%s: Toggeling output 1", self.topic)
293
+        self.logger.info("Toggeling output 1")
294
         self.set_output_1('toggle')
294
         self.set_output_1('toggle')
295
 
295
 
296
 
296
 
328
         self.pack(self.KEY_OUTPUT_0, state)
328
         self.pack(self.KEY_OUTPUT_0, state)
329
 
329
 
330
     def set_output_0_mcb(self, device, key, data):
330
     def set_output_0_mcb(self, device, key, data):
331
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
331
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
332
         self.set_output_0(data)
332
         self.set_output_0(data)
333
 
333
 
334
     def toggle_output_0_mcb(self, device, key, data):
334
     def toggle_output_0_mcb(self, device, key, data):
335
-        self.logger.info("%s: Toggeling output 0", self.topic)
335
+        self.logger.info("Toggeling output 0")
336
         self.set_output_0('toggle')
336
         self.set_output_0('toggle')
337
 
337
 
338
 
338
 
417
         self.pack(self.KEY_OUTPUT_0, state)
417
         self.pack(self.KEY_OUTPUT_0, state)
418
 
418
 
419
     def set_output_0_mcb(self, device, key, data):
419
     def set_output_0_mcb(self, device, key, data):
420
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
420
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
421
         self.set_output_0(data)
421
         self.set_output_0(data)
422
 
422
 
423
     def toggle_output_0_mcb(self, device, key, data):
423
     def toggle_output_0_mcb(self, device, key, data):
424
-        self.logger.info("%s: Toggeling output 0", self.topic)
424
+        self.logger.info("Toggeling output 0")
425
         self.set_output_0('toggle')
425
         self.set_output_0('toggle')
426
 
426
 
427
     def set_output_1(self, state):
427
     def set_output_1(self, state):
429
         self.pack(self.KEY_OUTPUT_1, state)
429
         self.pack(self.KEY_OUTPUT_1, state)
430
 
430
 
431
     def set_output_1_mcb(self, device, key, data):
431
     def set_output_1_mcb(self, device, key, data):
432
-        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
432
+        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
433
         self.set_output_1(data)
433
         self.set_output_1(data)
434
 
434
 
435
     def toggle_output_1_mcb(self, device, key, data):
435
     def toggle_output_1_mcb(self, device, key, data):
436
-        self.logger.info("%s: Toggeling output 1", self.topic)
436
+        self.logger.info("Toggeling output 1")
437
         self.set_output_1('toggle')
437
         self.set_output_1('toggle')
438
 
438
 
439
     def set_output_2(self, state):
439
     def set_output_2(self, state):
441
         self.pack(self.KEY_OUTPUT_2, state)
441
         self.pack(self.KEY_OUTPUT_2, state)
442
 
442
 
443
     def set_output_2_mcb(self, device, key, data):
443
     def set_output_2_mcb(self, device, key, data):
444
-        self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "%s: Changing output 2 to %s", self.topic, str(data))
444
+        self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "Changing output 2 to %s", str(data))
445
         self.set_output_2(data)
445
         self.set_output_2(data)
446
 
446
 
447
     def toggle_output_2_mcb(self, device, key, data):
447
     def toggle_output_2_mcb(self, device, key, data):
448
-        self.logger.info("%s: Toggeling output 2", self.topic)
448
+        self.logger.info("Toggeling output 2")
449
         self.set_output_2('toggle')
449
         self.set_output_2('toggle')
450
 
450
 
451
     def set_output_3(self, state):
451
     def set_output_3(self, state):
453
         self.pack(self.KEY_OUTPUT_3, state)
453
         self.pack(self.KEY_OUTPUT_3, state)
454
 
454
 
455
     def set_output_3_mcb(self, device, key, data):
455
     def set_output_3_mcb(self, device, key, data):
456
-        self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "%s: Changing output 3 to %s", self.topic, str(data))
456
+        self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "Changing output 3 to %s", str(data))
457
         self.set_output_3(data)
457
         self.set_output_3(data)
458
 
458
 
459
     def toggle_output_3_mcb(self, device, key, data):
459
     def toggle_output_3_mcb(self, device, key, data):
460
-        self.logger.info("%s: Toggeling output 3", self.topic)
460
+        self.logger.info("Toggeling output 3")
461
         self.set_output_3('toggle')
461
         self.set_output_3('toggle')
462
 
462
 
463
     def set_output_all(self, state):
463
     def set_output_all(self, state):
465
         self.pack(self.KEY_OUTPUT_ALL, state)
465
         self.pack(self.KEY_OUTPUT_ALL, state)
466
 
466
 
467
     def set_output_all_mcb(self, device, key, data):
467
     def set_output_all_mcb(self, device, key, data):
468
-        self.logger.info("%s: Changing all outputs to %s", self.topic, str(data))
468
+        self.logger.info("Changing all outputs to %s", str(data))
469
         self.set_output_all(data)
469
         self.set_output_all(data)
470
 
470
 
471
     def toggle_output_all_mcb(self, device, key, data):
471
     def toggle_output_all_mcb(self, device, key, data):
472
-        self.logger.info("%s: Toggeling all outputs", self.topic)
472
+        self.logger.info("Toggeling all outputs")
473
         self.set_output_0('toggle')
473
         self.set_output_0('toggle')
474
 
474
 
475
 
475
 
537
         self.pack(self.KEY_OUTPUT_0, state)
537
         self.pack(self.KEY_OUTPUT_0, state)
538
 
538
 
539
     def set_output_0_mcb(self, device, key, data):
539
     def set_output_0_mcb(self, device, key, data):
540
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
540
+        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
541
         self.set_output_0(data)
541
         self.set_output_0(data)
542
 
542
 
543
     def toggle_output_0_mcb(self, device, key, data):
543
     def toggle_output_0_mcb(self, device, key, data):
544
-        self.logger.info("%s: Toggeling output 0", self.topic)
544
+        self.logger.info("Toggeling output 0")
545
         self.set_output_0('toggle')
545
         self.set_output_0('toggle')
546
 
546
 
547
     def set_brightness(self, brightness):
547
     def set_brightness(self, brightness):
549
         self.pack(self.KEY_BRIGHTNESS, brightness)
549
         self.pack(self.KEY_BRIGHTNESS, brightness)
550
 
550
 
551
     def set_brightness_mcb(self, device, key, data):
551
     def set_brightness_mcb(self, device, key, data):
552
-        self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "%s: Changing brightness to %s", self.topic, str(data))
552
+        self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "Changing brightness to %s", str(data))
553
         self.set_brightness(data)
553
         self.set_brightness(data)
554
 
554
 
555
     def default_inc(self, speed=40):
555
     def default_inc(self, speed=40):
566
         self.pack(self.KEY_COLOR_TEMP, color_temp)
566
         self.pack(self.KEY_COLOR_TEMP, color_temp)
567
 
567
 
568
     def set_color_temp_mcb(self, device, key, data):
568
     def set_color_temp_mcb(self, device, key, data):
569
-        self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "%s: Changing color temperature to %s", self.topic, str(data))
569
+        self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
570
         self.set_color_temp(data)
570
         self.set_color_temp(data)
571
 
571
 
572
 
572
 
608
     # WARNING CALL
608
     # WARNING CALL
609
     #
609
     #
610
     def warning_call_condition(self):
610
     def warning_call_condition(self):
611
-        return self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
611
+        return self.get(self.KEY_BATTERY) is not None and self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
612
 
612
 
613
     def warning_text(self):
613
     def warning_text(self):
614
         return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
614
         return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
696
         self.pack(self.KEY_STATE, data)
696
         self.pack(self.KEY_STATE, data)
697
 
697
 
698
     def set_state_mcb(self, device, key, data):
698
     def set_state_mcb(self, device, key, data):
699
-        self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
699
+        self.logger.debug("Sending %s with content %s", key, str(data))
700
         self.set_state(data)
700
         self.set_state(data)
701
 
701
 
702
 
702
 
735
         self.pack(self.KEY_ENABLE, data)
735
         self.pack(self.KEY_ENABLE, data)
736
 
736
 
737
     def set_enable_mcb(self, device, key, data):
737
     def set_enable_mcb(self, device, key, data):
738
-        self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
738
+        self.logger.debug("Sending %s with content %s", key, str(data))
739
         self.set_enable(data)
739
         self.set_enable(data)
740
 
740
 
741
     def set_brightness(self, data):
741
     def set_brightness(self, data):
743
         self.pack(self.KEY_BRIGHTNESS, data)
743
         self.pack(self.KEY_BRIGHTNESS, data)
744
 
744
 
745
     def set_brightness_mcb(self, device, key, data):
745
     def set_brightness_mcb(self, device, key, data):
746
-        self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
746
+        self.logger.debug("Sending %s with content %s", key, str(data))
747
         self.set_brightness(data)
747
         self.set_brightness(data)
748
 
748
 
749
     def set_color_temp(self, data):
749
     def set_color_temp(self, data):
751
         self.pack(self.KEY_COLOR_TEMP, data)
751
         self.pack(self.KEY_COLOR_TEMP, data)
752
 
752
 
753
     def set_color_temp_mcb(self, device, key, data):
753
     def set_color_temp_mcb(self, device, key, data):
754
-        self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
754
+        self.logger.debug("Sending %s with content %s", key, str(data))
755
         self.set_color_temp(data)
755
         self.set_color_temp(data)
756
 
756
 
757
 
757
 
773
 
773
 
774
     def set_led(self, key, data):
774
     def set_led(self, key, data):
775
         """data: [True, False]"""
775
         """data: [True, False]"""
776
-        self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
776
+        self.logger.debug("Sending %s with content %s", key, str(data))
777
         self.pack(key, data)
777
         self.pack(key, data)
778
 
778
 
779
 
779
 
828
         self.pack(self.KEY_HEATING_SETPOINT, setpoint)
828
         self.pack(self.KEY_HEATING_SETPOINT, setpoint)
829
 
829
 
830
     def set_heating_setpoint_mcb(self, device, key, data):
830
     def set_heating_setpoint_mcb(self, device, key, data):
831
-        self.logger.info("%s: Changing heating setpoint to %s", self.topic, str(data))
831
+        self.logger.info("Changing heating setpoint to %s", str(data))
832
         self.set_heating_setpoint(data)
832
         self.set_heating_setpoint(data)
833
 
833
 
834
 
834
 
891
         self.pack(self.KEY_STATE + "/" + str(num), data)
891
         self.pack(self.KEY_STATE + "/" + str(num), data)
892
 
892
 
893
     def set_state_mcb(self, device, key, data):
893
     def set_state_mcb(self, device, key, data):
894
-        self.logger.info("%s: Changing state to %s", self.topic, str(data))
894
+        self.logger.info("Changing state to %s", str(data))
895
         self.set_state(data)
895
         self.set_state(data)
896
 
896
 
897
 
897
 

Loading…
Cancel
Save