power: improve logging

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-10-19 16:35:49 -04:00
parent 1f1c590409
commit 38b035389d
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 31 additions and 3 deletions

View File

@ -122,8 +122,9 @@ class PrinterPower:
fname = "unknown" fname = "unknown"
if len(queue): if len(queue):
fname = queue[0].get("filename", "unknown") fname = queue[0].get("filename", "unknown")
logging.debug( logging.info(
f"Job '{fname}' queued, powering on device [{name}]") f"Power Device {name}: Job '{fname}' queued, powering on"
)
await dev.process_request("on") await dev.process_request("on")
async def _handle_list_devices(self, async def _handle_list_devices(self,
@ -258,8 +259,15 @@ class PowerDevice:
return return
self.need_scheduled_restart = False self.need_scheduled_restart = False
if state == "ready": if state == "ready":
logging.info("Klipper reports 'ready', aborting FIRMWARE_RESTART") logging.info(
f"Power Device {self.name}: Klipper reports 'ready', "
"aborting FIRMWARE_RESTART"
)
return return
logging.info(
f"Power Device {self.name}: Sending FIRMWARE_RESTART command "
"to Klippy"
)
event_loop = self.server.get_event_loop() event_loop = self.server.get_event_loop()
kapis: APIComp = self.server.lookup_component("klippy_apis") kapis: APIComp = self.server.lookup_component("klippy_apis")
event_loop.delay_callback( event_loop.delay_callback(
@ -286,6 +294,10 @@ class PowerDevice:
if self.bound_service is not None: if self.bound_service is not None:
machine_cmp: Machine = self.server.lookup_component("machine") machine_cmp: Machine = self.server.lookup_component("machine")
action = "start" if self.state == "on" else "stop" action = "start" if self.state == "on" else "stop"
logging.info(
f"Power Device {self.name}: Performing {action} action "
f"on bound service {self.bound_service}"
)
await machine_cmp.do_service_action(action, self.bound_service) await machine_cmp.do_service_action(action, self.bound_service)
if self.state == "on" and self.klipper_restart: if self.state == "on" and self.klipper_restart:
self.need_scheduled_restart = True self.need_scheduled_restart = True
@ -437,6 +449,10 @@ class HTTPDevice(PowerDevice):
): ):
new_state = "on" if self.initial_state else "off" new_state = "on" if self.initial_state else "off"
if new_state != state: if new_state != state:
logging.info(
f"Power Device {self.name}: setting initial "
f"state to {new_state}"
)
await self.set_power(new_state) await self.set_power(new_state)
self.notify_power_changed() self.notify_power_changed()
return return
@ -600,6 +616,10 @@ class KlipperDevice(PowerDevice):
): ):
new_state = "on" if self.initial_state else "off" new_state = "on" if self.initial_state else "off"
if new_state != self.state: if new_state != self.state:
logging.info(
f"Power Device {self.name}: setting initial "
f"state to {new_state}"
)
await self.set_power(new_state) await self.set_power(new_state)
self.notify_power_changed() self.notify_power_changed()
@ -875,6 +895,10 @@ class TPLinkSmartPlug(PowerDevice):
): ):
new_state = "on" if self.initial_state else "off" new_state = "on" if self.initial_state else "off"
if new_state != self.state: if new_state != self.state:
logging.info(
f"Power Device {self.name}: setting initial "
f"state to {new_state}"
)
await self.set_power(new_state) await self.set_power(new_state)
self.notify_power_changed() self.notify_power_changed()
return return
@ -1254,6 +1278,10 @@ class MQTTDevice(PowerDevice):
): ):
new_state = "on" if self.initial_state else "off" new_state = "on" if self.initial_state else "off"
if new_state != self.state: if new_state != self.state:
logging.info(
f"Power Device {self.name}: setting initial "
f"state to {new_state}"
)
await self.set_power(new_state) await self.set_power(new_state)
# Don't reset on next connection # Don't reset on next connection
self.initial_state = None self.initial_state = None