Browse Source

device logging improved for functional visibility at loglevel info

tags/v1.3.0
Dirk Alders 1 year ago
parent
commit
bc445a6ec4
6 changed files with 43 additions and 27 deletions
  1. 2
    0
      devices/base.py
  2. 4
    1
      devices/brennenstuhl.py
  3. 17
    12
      devices/mydevices.py
  4. 6
    4
      devices/shelly.py
  5. 7
    4
      devices/silvercrest.py
  6. 7
    6
      devices/tradfri.py

+ 2
- 0
devices/base.py View File

38
         # initialisations
38
         # initialisations
39
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
39
         mqtt_client.add_callback(topic=self.topic, callback=self.receive_callback)
40
         mqtt_client.add_callback(topic=self.topic+"/#", callback=self.receive_callback)
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
     def set(self, key, data, block_callback=[]):
44
     def set(self, key, data, block_callback=[]):
43
         if key in self.RX_IGNORE_KEYS:
45
         if key in self.RX_IGNORE_KEYS:

+ 4
- 1
devices/brennenstuhl.py View File

57
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
57
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
58
         self.__battery_warning__ = False
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
     # WARNING CALL
65
     # WARNING CALL
62
     #
66
     #
92
         self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
96
         self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
93
 
97
 
94
     def set_heating_setpoint_mcb(self, device, key, data):
98
     def set_heating_setpoint_mcb(self, device, key, data):
95
-        self.logger.info("Changing heating setpoint to %s", str(data))
96
         self.set_heating_setpoint(data)
99
         self.set_heating_setpoint(data)

+ 17
- 12
devices/mydevices.py View File

32
     #
32
     #
33
     RX_KEYS = [KEY_OUTPUT_0, KEY_OUTPUT_1, KEY_OUTPUT_2, KEY_OUTPUT_3]
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
     # RX
40
     # RX
72
         self.send_command(self.KEY_OUTPUT_0, state)
73
         self.send_command(self.KEY_OUTPUT_0, state)
73
 
74
 
74
     def set_output_0_mcb(self, device, key, data):
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
         self.set_output_0(data)
76
         self.set_output_0(data)
77
 
77
 
78
     def toggle_output_0_mcb(self, device, key, data):
78
     def toggle_output_0_mcb(self, device, key, data):
79
-        self.logger.info("Toggeling output 0")
80
         self.set_output_0(not self.output_0)
79
         self.set_output_0(not self.output_0)
81
 
80
 
82
     def set_output_1(self, state):
81
     def set_output_1(self, state):
84
         self.send_command(self.KEY_OUTPUT_1, state)
83
         self.send_command(self.KEY_OUTPUT_1, state)
85
 
84
 
86
     def set_output_1_mcb(self, device, key, data):
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
         self.set_output_1(data)
86
         self.set_output_1(data)
89
 
87
 
90
     def toggle_output_1_mcb(self, device, key, data):
88
     def toggle_output_1_mcb(self, device, key, data):
91
-        self.logger.info("Toggeling output 1")
92
         self.set_output_1(not self.output_1)
89
         self.set_output_1(not self.output_1)
93
 
90
 
94
     def set_output_2(self, state):
91
     def set_output_2(self, state):
96
         self.send_command(self.KEY_OUTPUT_2, state)
93
         self.send_command(self.KEY_OUTPUT_2, state)
97
 
94
 
98
     def set_output_2_mcb(self, device, key, data):
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
         self.set_output_2(data)
96
         self.set_output_2(data)
101
 
97
 
102
     def toggle_output_2_mcb(self, device, key, data):
98
     def toggle_output_2_mcb(self, device, key, data):
103
-        self.logger.info("Toggeling output 2")
104
         self.set_output_2(not self.output_2)
99
         self.set_output_2(not self.output_2)
105
 
100
 
106
     def set_output_3(self, state):
101
     def set_output_3(self, state):
108
         self.send_command(self.KEY_OUTPUT_3, state)
103
         self.send_command(self.KEY_OUTPUT_3, state)
109
 
104
 
110
     def set_output_3_mcb(self, device, key, data):
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
         self.set_output_3(data)
106
         self.set_output_3(data)
113
 
107
 
114
     def toggle_output_3_mcb(self, device, key, data):
108
     def toggle_output_3_mcb(self, device, key, data):
115
-        self.logger.info("Toggeling output 3")
116
         self.set_output_3(not self.output_3)
109
         self.set_output_3(not self.output_3)
117
 
110
 
118
     def set_output_all(self, state):
111
     def set_output_all(self, state):
120
         self.send_command(self.KEY_OUTPUT_ALL, state)
113
         self.send_command(self.KEY_OUTPUT_ALL, state)
121
 
114
 
122
     def set_output_all_mcb(self, device, key, data):
115
     def set_output_all_mcb(self, device, key, data):
123
-        self.logger.info("Changing all outputs to %s", str(data))
124
         self.set_output_all(data)
116
         self.set_output_all(data)
125
 
117
 
126
     def all_off(self):
118
     def all_off(self):
191
     #
183
     #
192
     RX_IGNORE_TOPICS = [KEY_CD, KEY_LINE1, KEY_LINE3, KEY_MUTE, KEY_POWER, KEY_VOLUP, KEY_VOLDOWN]
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
     def set_cd(self, device=None, key=None, data=None):
189
     def set_cd(self, device=None, key=None, data=None):
190
+        self.logger.info("Changing amplifier source to CD")
195
         self.send_command(self.KEY_CD, None)
191
         self.send_command(self.KEY_CD, None)
196
 
192
 
197
     def set_line1(self, device=None, key=None, data=None):
193
     def set_line1(self, device=None, key=None, data=None):
194
+        self.logger.info("Changing amplifier source to LINE1")
198
         self.send_command(self.KEY_LINE1, None)
195
         self.send_command(self.KEY_LINE1, None)
199
 
196
 
200
     def set_line3(self, device=None, key=None, data=None):
197
     def set_line3(self, device=None, key=None, data=None):
198
+        self.logger.info("Changing amplifier source to LINE3")
201
         self.send_command(self.KEY_LINE3, None)
199
         self.send_command(self.KEY_LINE3, None)
202
 
200
 
203
     def set_mute(self, device=None, key=None, data=None):
201
     def set_mute(self, device=None, key=None, data=None):
202
+        self.logger.info("Muting / Unmuting amplifier")
204
         self.send_command(self.KEY_MUTE, None)
203
         self.send_command(self.KEY_MUTE, None)
205
 
204
 
206
     def set_power(self, device=None, key=None, data=None):
205
     def set_power(self, device=None, key=None, data=None):
206
+        self.logger.info("Power on/off amplifier")
207
         self.send_command(self.KEY_POWER, None)
207
         self.send_command(self.KEY_POWER, None)
208
 
208
 
209
     def set_volume_up(self, data=False):
209
     def set_volume_up(self, data=False):
210
         """data: [True, False]"""
210
         """data: [True, False]"""
211
+        self.logger.info("Increasing amplifier volume")
211
         self.send_command(self.KEY_VOLUP, data)
212
         self.send_command(self.KEY_VOLUP, data)
212
 
213
 
213
     def set_volume_down(self, data=False):
214
     def set_volume_down(self, data=False):
214
         """data: [True, False]"""
215
         """data: [True, False]"""
216
+        self.logger.info("Decreasing amplifier volume")
215
         self.send_command(self.KEY_VOLDOWN, data)
217
         self.send_command(self.KEY_VOLDOWN, data)
216
 
218
 
217
     def default_inc(self, device=None, key=None, data=None):
219
     def default_inc(self, device=None, key=None, data=None):
238
     #
240
     #
239
     RX_KEYS = [KEY_STATE, KEY_TITLE]
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
     def set_state(self, num, data):
247
     def set_state(self, num, data):
242
         """data: [True, False]"""
248
         """data: [True, False]"""
243
         self.send_command(self.KEY_STATE + "/" + str(num), data)
249
         self.send_command(self.KEY_STATE + "/" + str(num), data)
244
 
250
 
245
     def set_state_mcb(self, device, key, data):
251
     def set_state_mcb(self, device, key, data):
246
-        self.logger.info("Changing state to %s", str(data))
247
         self.set_state(data)
252
         self.set_state(data)

+ 6
- 4
devices/shelly.py View File

73
         #
73
         #
74
         self.all_off_requested = False
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
     def flash_task(self, *args):
82
     def flash_task(self, *args):
77
         if self.flash_active:
83
         if self.flash_active:
78
             self.send_command(self.output_key_delayed, not self.get(self.output_key_delayed))
84
             self.send_command(self.output_key_delayed, not self.get(self.output_key_delayed))
141
         self.send_command(self.KEY_OUTPUT_0, state)
147
         self.send_command(self.KEY_OUTPUT_0, state)
142
 
148
 
143
     def set_output_0_mcb(self, device, key, data):
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
         self.set_output_0(data)
150
         self.set_output_0(data)
146
 
151
 
147
     def toggle_output_0_mcb(self, device, key, data):
152
     def toggle_output_0_mcb(self, device, key, data):
148
-        self.logger.info("Toggeling output 0")
149
         self.set_output_0(not self.output_0)
153
         self.set_output_0(not self.output_0)
150
 
154
 
151
     def set_output_1(self, state):
155
     def set_output_1(self, state):
153
         self.send_command(self.KEY_OUTPUT_1, state)
157
         self.send_command(self.KEY_OUTPUT_1, state)
154
 
158
 
155
     def set_output_1_mcb(self, device, key, data):
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
         self.set_output_1(data)
160
         self.set_output_1(data)
158
 
161
 
159
     def toggle_output_1_mcb(self, device, key, data):
162
     def toggle_output_1_mcb(self, device, key, data):
160
-        self.logger.info("Toggeling output 1")
161
         self.set_output_1(not self.output_1)
163
         self.set_output_1(not self.output_1)
162
 
164
 
163
     def flash_0_mcb(self, device, key, data):
165
     def flash_0_mcb(self, device, key, data):

+ 7
- 4
devices/silvercrest.py View File

29
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
29
     RX_KEYS = [KEY_LINKQUALITY, KEY_OUTPUT_0]
30
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0]
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
     # RX
37
     # RX
53
         self.send_command(self.KEY_OUTPUT_0, state)
54
         self.send_command(self.KEY_OUTPUT_0, state)
54
 
55
 
55
     def set_output_0_mcb(self, device, key, data):
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
         self.set_output_0(data)
57
         self.set_output_0(data)
58
 
58
 
59
     def toggle_output_0_mcb(self, device, key, data):
59
     def toggle_output_0_mcb(self, device, key, data):
60
-        self.logger.info("Toggeling output 0")
61
         self.set_output_0(not self.output_0)
60
         self.set_output_0(not self.output_0)
62
 
61
 
63
     def all_off(self):
62
     def all_off(self):
93
         #
92
         #
94
         self.add_callback(self.KEY_BATTERY_LOW, True, self.__warning__, True)
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
     # WARNING CALL
100
     # WARNING CALL
98
     #
101
     #

+ 7
- 6
devices/tradfri.py View File

46
     RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup']
46
     RX_IGNORE_KEYS = ['update', 'color_mode', 'color_temp_startup']
47
     RX_FILTER_DATA_KEYS = [KEY_OUTPUT_0, KEY_BRIGHTNESS, KEY_COLOR_TEMP]
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
     def __device_to_instance_filter__(self, key, data):
53
     def __device_to_instance_filter__(self, key, data):
53
         if key == self.KEY_BRIGHTNESS:
54
         if key == self.KEY_BRIGHTNESS:
97
         self.send_command(self.KEY_OUTPUT_0, state)
98
         self.send_command(self.KEY_OUTPUT_0, state)
98
 
99
 
99
     def set_output_0_mcb(self, device, key, data):
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
         self.set_output_0(data)
101
         self.set_output_0(data)
102
 
102
 
103
     def toggle_output_0_mcb(self, device, key, data):
103
     def toggle_output_0_mcb(self, device, key, data):
104
-        self.logger.info("Toggeling output 0")
105
         self.set_output_0(not self.output_0)
104
         self.set_output_0(not self.output_0)
106
 
105
 
107
     def set_brightness(self, brightness):
106
     def set_brightness(self, brightness):
109
         self.send_command(self.KEY_BRIGHTNESS, brightness)
108
         self.send_command(self.KEY_BRIGHTNESS, brightness)
110
 
109
 
111
     def set_brightness_mcb(self, device, key, data):
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
         self.set_brightness(data)
111
         self.set_brightness(data)
114
 
112
 
115
     def default_inc(self, speed=40):
113
     def default_inc(self, speed=40):
126
         self.send_command(self.KEY_COLOR_TEMP, color_temp)
124
         self.send_command(self.KEY_COLOR_TEMP, color_temp)
127
 
125
 
128
     def set_color_temp_mcb(self, device, key, data):
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
         self.set_color_temp(data)
127
         self.set_color_temp(data)
131
 
128
 
132
     def all_off(self):
129
     def all_off(self):
187
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
184
         self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
188
         self.__battery_warning__ = False
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
     # WARNING CALL
192
     # WARNING CALL
192
     #
193
     #

Loading…
Cancel
Save