Logging for devices improved

This commit is contained in:
Dirk Alders 2023-01-04 01:20:00 +01:00
parent d085aa8581
commit ec23cfca2d

View File

@ -96,10 +96,10 @@ class base(dict):
self.__previous__[key] = prev_value
# Filter, if needed
self.unpack_filter(key)
self.logger.debug("Received data for (%s) %s - %s", self.topic, key, str(self.get(key)))
self.logger.debug("Received data %s - %s", key, str(self.get(key)))
self.callback_caller(key, self[key], self.get(key) != self.__previous__.get(key))
elif key not in self.RX_IGNORE_KEYS:
self.logger.warning('Got a message from \"%s\" with unparsed content "%s"', self.topic, key)
self.logger.warning('Got a message with unparsed content: "%s - %s"', key, str(data))
else:
self.logger.debug("Ignoring key %s", key)
@ -141,7 +141,7 @@ class base(dict):
if self.TX_TYPE < 0:
self.logger.error("Unknown tx type. Set TX_TYPE of class to a known value")
else:
self.logger.debug("Sending data for (%s) %s - %s", self.topic, key, str(data))
self.logger.debug("Sending data for %s - %s", key, str(data))
if self.TX_TYPE == self.TX_DICT:
self.mqtt_client.send('/'.join([self.topic, self.TX_TOPIC]), json.dumps({key: data}))
else:
@ -274,11 +274,11 @@ class shelly(base):
self.pack(self.KEY_OUTPUT_0, state)
def set_output_0_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
self.set_output_0(data)
def toggle_output_0_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 0", self.topic)
self.logger.info("Toggeling output 0")
self.set_output_0('toggle')
def set_output_1(self, state):
@ -286,11 +286,11 @@ class shelly(base):
self.pack(self.KEY_OUTPUT_1, state)
def set_output_1_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
self.set_output_1(data)
def toggle_output_1_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 1", self.topic)
self.logger.info("Toggeling output 1")
self.set_output_1('toggle')
@ -328,11 +328,11 @@ class silvercrest_powerplug(base):
self.pack(self.KEY_OUTPUT_0, state)
def set_output_0_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
self.set_output_0(data)
def toggle_output_0_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 0", self.topic)
self.logger.info("Toggeling output 0")
self.set_output_0('toggle')
@ -417,11 +417,11 @@ class my_powerplug(base):
self.pack(self.KEY_OUTPUT_0, state)
def set_output_0_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
self.set_output_0(data)
def toggle_output_0_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 0", self.topic)
self.logger.info("Toggeling output 0")
self.set_output_0('toggle')
def set_output_1(self, state):
@ -429,11 +429,11 @@ class my_powerplug(base):
self.pack(self.KEY_OUTPUT_1, state)
def set_output_1_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "%s: Changing output 1 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_1 else logging.DEBUG, "Changing output 1 to %s", str(data))
self.set_output_1(data)
def toggle_output_1_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 1", self.topic)
self.logger.info("Toggeling output 1")
self.set_output_1('toggle')
def set_output_2(self, state):
@ -441,11 +441,11 @@ class my_powerplug(base):
self.pack(self.KEY_OUTPUT_2, state)
def set_output_2_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "%s: Changing output 2 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_2 else logging.DEBUG, "Changing output 2 to %s", str(data))
self.set_output_2(data)
def toggle_output_2_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 2", self.topic)
self.logger.info("Toggeling output 2")
self.set_output_2('toggle')
def set_output_3(self, state):
@ -453,11 +453,11 @@ class my_powerplug(base):
self.pack(self.KEY_OUTPUT_3, state)
def set_output_3_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "%s: Changing output 3 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_3 else logging.DEBUG, "Changing output 3 to %s", str(data))
self.set_output_3(data)
def toggle_output_3_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 3", self.topic)
self.logger.info("Toggeling output 3")
self.set_output_3('toggle')
def set_output_all(self, state):
@ -465,11 +465,11 @@ class my_powerplug(base):
self.pack(self.KEY_OUTPUT_ALL, state)
def set_output_all_mcb(self, device, key, data):
self.logger.info("%s: Changing all outputs to %s", self.topic, str(data))
self.logger.info("Changing all outputs to %s", str(data))
self.set_output_all(data)
def toggle_output_all_mcb(self, device, key, data):
self.logger.info("%s: Toggeling all outputs", self.topic)
self.logger.info("Toggeling all outputs")
self.set_output_0('toggle')
@ -537,11 +537,11 @@ class tradfri_light(base):
self.pack(self.KEY_OUTPUT_0, state)
def set_output_0_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "%s: Changing output 0 to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.output_0 else logging.DEBUG, "Changing output 0 to %s", str(data))
self.set_output_0(data)
def toggle_output_0_mcb(self, device, key, data):
self.logger.info("%s: Toggeling output 0", self.topic)
self.logger.info("Toggeling output 0")
self.set_output_0('toggle')
def set_brightness(self, brightness):
@ -549,7 +549,7 @@ class tradfri_light(base):
self.pack(self.KEY_BRIGHTNESS, brightness)
def set_brightness_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "%s: Changing brightness to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.brightness else logging.DEBUG, "Changing brightness to %s", str(data))
self.set_brightness(data)
def default_inc(self, speed=40):
@ -566,7 +566,7 @@ class tradfri_light(base):
self.pack(self.KEY_COLOR_TEMP, color_temp)
def set_color_temp_mcb(self, device, key, data):
self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "%s: Changing color temperature to %s", self.topic, str(data))
self.logger.log(logging.INFO if data != self.color_temp else logging.DEBUG, "Changing color temperature to %s", str(data))
self.set_color_temp(data)
@ -608,7 +608,7 @@ class tradfri_button(base):
# WARNING CALL
#
def warning_call_condition(self):
return self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
return self.get(self.KEY_BATTERY) is not None and self.get(self.KEY_BATTERY) <= BATTERY_WARN_LEVEL
def warning_text(self):
return "Low battery level detected for %s. Battery level was %.0f%%." % (self.topic, self.get(self.KEY_BATTERY))
@ -696,7 +696,7 @@ class nodered_gui_switch(nodered_gui_button):
self.pack(self.KEY_STATE, data)
def set_state_mcb(self, device, key, data):
self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_state(data)
@ -735,7 +735,7 @@ class nodered_gui_brightness_color_temp(base):
self.pack(self.KEY_ENABLE, data)
def set_enable_mcb(self, device, key, data):
self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_enable(data)
def set_brightness(self, data):
@ -743,7 +743,7 @@ class nodered_gui_brightness_color_temp(base):
self.pack(self.KEY_BRIGHTNESS, data)
def set_brightness_mcb(self, device, key, data):
self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_brightness(data)
def set_color_temp(self, data):
@ -751,7 +751,7 @@ class nodered_gui_brightness_color_temp(base):
self.pack(self.KEY_COLOR_TEMP, data)
def set_color_temp_mcb(self, device, key, data):
self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
self.logger.debug("Sending %s with content %s", key, str(data))
self.set_color_temp(data)
@ -773,7 +773,7 @@ class nodered_gui_leds(base):
def set_led(self, key, data):
"""data: [True, False]"""
self.logger.debug("%s: Sending %s with content %s", self.topic, key, str(data))
self.logger.debug("Sending %s with content %s", key, str(data))
self.pack(key, data)
@ -828,7 +828,7 @@ class brennenstuhl_heatingvalve(base):
self.pack(self.KEY_HEATING_SETPOINT, setpoint)
def set_heating_setpoint_mcb(self, device, key, data):
self.logger.info("%s: Changing heating setpoint to %s", self.topic, str(data))
self.logger.info("Changing heating setpoint to %s", str(data))
self.set_heating_setpoint(data)
@ -891,7 +891,7 @@ class status(base):
self.pack(self.KEY_STATE + "/" + str(num), data)
def set_state_mcb(self, device, key, data):
self.logger.info("%s: Changing state to %s", self.topic, str(data))
self.logger.info("Changing state to %s", str(data))
self.set_state(data)