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

device logging improved for functional visibility at loglevel info

tags/v1.3.0
Dirk Alders 1 рік тому
джерело
коміт
bc445a6ec4

+ 2
- 0
devices/base.py Переглянути файл

@@ -38,6 +38,8 @@ class base(mqtt_base):
38 38
         # initialisations
39 39
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
40 40
         mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
41
+        #
42
+        self.add_callback(None, None, self.__state_logging__, on_change_only=True)
41 43
 
42 44
     def set(self, key, data, block_callback=[]):
43 45
         if key in self.RX_IGNORE_KEYS:

+ 4
- 1
devices/brennenstuhl.py Переглянути файл

@@ -57,6 +57,10 @@ class brennenstuhl_heatingvalve(base):
57 57
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
58 58
         self.__battery_warning__ = False
59 59
 
60
+    def __state_logging__(self, inst, key, data):
61
+        if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
62
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
63
+
60 64
     #
61 65
     # WARNING CALL
62 66
     #
@@ -92,5 +96,4 @@ class brennenstuhl_heatingvalve(base):
92 96
         self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
93 97
 
94 98
     def set_heating_setpoint_mcb(self, device, key, data):
95
-        self.logger.info("Changing heating setpoint to %s", str(data))
96 99
         self.set_heating_setpoint(data)

+ 17
- 12
devices/mydevices.py Переглянути файл

@@ -32,8 +32,9 @@ class powerplug(base):
32 32
     #
33 33
     RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
34 34
 
35
-    def __init__(self, mqtt_client, topic):
36
-        super().__init__(mqtt_client, topic)
35
+    def __state_logging__(self, inst, key, data):
36
+        if key in self.KEY_OUTPUT_LIST:
37
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
37 38
 
38 39
     #
39 40
     # RX
@@ -72,11 +73,9 @@ class powerplug(base):
72 73
         self.send_command(self.KEY_OUTPUT_0, state)
73 74
 
74 75
     def set_output_0_mcb(self, device, key, data):
75
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
76 76
         self.set_output_0(data)
77 77
 
78 78
     def toggle_output_0_mcb(self, device, key, data):
79
-        self.logger.info("Toggeling output 0")
80 79
         self.set_output_0(not self.output_0)
81 80
 
82 81
     def set_output_1(self, state):
@@ -84,11 +83,9 @@ class powerplug(base):
84 83
         self.send_command(self.KEY_OUTPUT_1, state)
85 84
 
86 85
     def set_output_1_mcb(self, device, key, data):
87
-        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
88 86
         self.set_output_1(data)
89 87
 
90 88
     def toggle_output_1_mcb(self, device, key, data):
91
-        self.logger.info("Toggeling output 1")
92 89
         self.set_output_1(not self.output_1)
93 90
 
94 91
     def set_output_2(self, state):
@@ -96,11 +93,9 @@ class powerplug(base):
96 93
         self.send_command(self.KEY_OUTPUT_2, state)
97 94
 
98 95
     def set_output_2_mcb(self, device, key, data):
99
-        self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "Changing output 2 to %s", str(data))
100 96
         self.set_output_2(data)
101 97
 
102 98
     def toggle_output_2_mcb(self, device, key, data):
103
-        self.logger.info("Toggeling output 2")
104 99
         self.set_output_2(not self.output_2)
105 100
 
106 101
     def set_output_3(self, state):
@@ -108,11 +103,9 @@ class powerplug(base):
108 103
         self.send_command(self.KEY_OUTPUT_3, state)
109 104
 
110 105
     def set_output_3_mcb(self, device, key, data):
111
-        self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "Changing output 3 to %s", str(data))
112 106
         self.set_output_3(data)
113 107
 
114 108
     def toggle_output_3_mcb(self, device, key, data):
115
-        self.logger.info("Toggeling output 3")
116 109
         self.set_output_3(not self.output_3)
117 110
 
118 111
     def set_output_all(self, state):
@@ -120,7 +113,6 @@ class powerplug(base):
120 113
         self.send_command(self.KEY_OUTPUT_ALL, state)
121 114
 
122 115
     def set_output_all_mcb(self, device, key, data):
123
-        self.logger.info("Changing all outputs to %s", str(data))
124 116
         self.set_output_all(data)
125 117
 
126 118
     def all_off(self):
@@ -191,27 +183,37 @@ class remote(base):
191 183
     #
192 184
     RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
193 185
 
186
+    def __state_logging__(self, inst, key, data):
187
+        pass    # This is just a TX device using self.set_*
188
+
194 189
     def set_cd(self, device=None, key=None, data=None):
190
+        self.logger.info("Changing amplifier source to CD")
195 191
         self.send_command(self.KEY_CD, None)
196 192
 
197 193
     def set_line1(self, device=None, key=None, data=None):
194
+        self.logger.info("Changing amplifier source to LINE1")
198 195
         self.send_command(self.KEY_LINE1, None)
199 196
 
200 197
     def set_line3(self, device=None, key=None, data=None):
198
+        self.logger.info("Changing amplifier source to LINE3")
201 199
         self.send_command(self.KEY_LINE3, None)
202 200
 
203 201
     def set_mute(self, device=None, key=None, data=None):
202
+        self.logger.info("Muting / Unmuting amplifier")
204 203
         self.send_command(self.KEY_MUTE, None)
205 204
 
206 205
     def set_power(self, device=None, key=None, data=None):
206
+        self.logger.info("Power on/off amplifier")
207 207
         self.send_command(self.KEY_POWER, None)
208 208
 
209 209
     def set_volume_up(self, data=False):
210 210
         """data: [True, False]"""
211
+        self.logger.info("Increasing amplifier volume")
211 212
         self.send_command(self.KEY_VOLUP, data)
212 213
 
213 214
     def set_volume_down(self, data=False):
214 215
         """data: [True, False]"""
216
+        self.logger.info("Decreasing amplifier volume")
215 217
         self.send_command(self.KEY_VOLDOWN, data)
216 218
 
217 219
     def default_inc(self, device=None, key=None, data=None):
@@ -238,10 +240,13 @@ class audio_status(base):
238 240
     #
239 241
     RX_KEYS = [KEY_STATE, KEY_TITLE]
240 242
 
243
+    def __state_logging__(self, inst, key, data):
244
+        if key in [self.KEY_STATE, self.KEY_TITLE]:
245
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
246
+
241 247
     def set_state(self, num, data):
242 248
         """data: [True, False]"""
243 249
         self.send_command(self.KEY_STATE + "/" + str(num), data)
244 250
 
245 251
     def set_state_mcb(self, device, key, data):
246
-        self.logger.info("Changing state to %s", str(data))
247 252
         self.set_state(data)

+ 6
- 4
devices/shelly.py Переглянути файл

@@ -73,6 +73,12 @@ class shelly(base):
73 73
         #
74 74
         self.all_off_requested = False
75 75
 
76
+    def __state_logging__(self, inst, key, data):
77
+        if key in [self.KEY_OUTPUT_0, self.KEY_OUTPUT_1]:
78
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
79
+        elif key in [self.KEY_INPUT_0, self.KEY_INPUT_1, self.KEY_LONGPUSH_0, self.KEY_LONGPUSH_1]:
80
+            self.logger.info("Input action '%s' with '%s'", key, repr(data))
81
+
76 82
     def flash_task(self, *args):
77 83
         if self.flash_active:
78 84
             self.send_command(self.output_key_delayed, not self.get(self.output_key_delayed))
@@ -141,11 +147,9 @@ class shelly(base):
141 147
         self.send_command(self.KEY_OUTPUT_0, state)
142 148
 
143 149
     def set_output_0_mcb(self, device, key, data):
144
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
145 150
         self.set_output_0(data)
146 151
 
147 152
     def toggle_output_0_mcb(self, device, key, data):
148
-        self.logger.info("Toggeling output 0")
149 153
         self.set_output_0(not self.output_0)
150 154
 
151 155
     def set_output_1(self, state):
@@ -153,11 +157,9 @@ class shelly(base):
153 157
         self.send_command(self.KEY_OUTPUT_1, state)
154 158
 
155 159
     def set_output_1_mcb(self, device, key, data):
156
-        self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
157 160
         self.set_output_1(data)
158 161
 
159 162
     def toggle_output_1_mcb(self, device, key, data):
160
-        self.logger.info("Toggeling output 1")
161 163
         self.set_output_1(not self.output_1)
162 164
 
163 165
     def flash_0_mcb(self, device, key, data):

+ 7
- 4
devices/silvercrest.py Переглянути файл

@@ -29,8 +29,9 @@ class silvercrest_powerplug(base):
29 29
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
30 30
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
31 31
 
32
-    def __init__(self, mqtt_client, topic):
33
-        super().__init__(mqtt_client, topic)
32
+    def __state_logging__(self, inst, key, data):
33
+        if key in [self.KEY_OUTPUT_0]:
34
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
34 35
 
35 36
     #
36 37
     # RX
@@ -53,11 +54,9 @@ class silvercrest_powerplug(base):
53 54
         self.send_command(self.KEY_OUTPUT_0, state)
54 55
 
55 56
     def set_output_0_mcb(self, device, key, data):
56
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
57 57
         self.set_output_0(data)
58 58
 
59 59
     def toggle_output_0_mcb(self, device, key, data):
60
-        self.logger.info("Toggeling output 0")
61 60
         self.set_output_0(not self.output_0)
62 61
 
63 62
     def all_off(self):
@@ -93,6 +92,10 @@ class silvercrest_motion_sensor(base):
93 92
         #
94 93
         self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
95 94
 
95
+    def __state_logging__(self, inst, key, data):
96
+        if key in [self.KEY_OCCUPANCY, self.KEY_UNMOUNTED]:
97
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
98
+
96 99
     #
97 100
     # WARNING CALL
98 101
     #

+ 7
- 6
devices/tradfri.py Переглянути файл

@@ -46,8 +46,9 @@ class tradfri_light(base):
46 46
     RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup']
47 47
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
48 48
 
49
-    def __init__(self, mqtt_client, topic):
50
-        super().__init__(mqtt_client, topic)
49
+    def __state_logging__(self, inst, key, data):
50
+        if key in [self.KEY_OUTPUT_0, self.KEY_BRIGHTNESS, self.KEY_COLOR_TEMP, self.KEY_BRIGHTNESS_FADE]:
51
+            self.logger.info("State change of '%s' to '%s'", key, repr(data))
51 52
 
52 53
     def __device_to_instance_filter__(self, key, data):
53 54
         if key == self.KEY_BRIGHTNESS:
@@ -97,11 +98,9 @@ class tradfri_light(base):
97 98
         self.send_command(self.KEY_OUTPUT_0, state)
98 99
 
99 100
     def set_output_0_mcb(self, device, key, data):
100
-        self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
101 101
         self.set_output_0(data)
102 102
 
103 103
     def toggle_output_0_mcb(self, device, key, data):
104
-        self.logger.info("Toggeling output 0")
105 104
         self.set_output_0(not self.output_0)
106 105
 
107 106
     def set_brightness(self, brightness):
@@ -109,7 +108,6 @@ class tradfri_light(base):
109 108
         self.send_command(self.KEY_BRIGHTNESS, brightness)
110 109
 
111 110
     def set_brightness_mcb(self, device, key, data):
112
-        self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "Changing brightness to %s", str(data))
113 111
         self.set_brightness(data)
114 112
 
115 113
     def default_inc(self, speed=40):
@@ -126,7 +124,6 @@ class tradfri_light(base):
126 124
         self.send_command(self.KEY_COLOR_TEMP, color_temp)
127 125
 
128 126
     def set_color_temp_mcb(self, device, key, data):
129
-        self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
130 127
         self.set_color_temp(data)
131 128
 
132 129
     def all_off(self):
@@ -187,6 +184,10 @@ class tradfri_button(base):
187 184
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
188 185
         self.__battery_warning__ = False
189 186
 
187
+    def __state_logging__(self, inst, key, data):
188
+        if key in [self.KEY_ACTION]:
189
+            self.logger.info("Input '%s' with '%s'", key, repr(data))
190
+
190 191
     #
191 192
     # WARNING CALL
192 193
     #

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