aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/temperature_combined.py
diff options
context:
space:
mode:
Diffstat (limited to 'klippy/extras/temperature_combined.py')
-rw-r--r--klippy/extras/temperature_combined.py73
1 files changed, 44 insertions, 29 deletions
diff --git a/klippy/extras/temperature_combined.py b/klippy/extras/temperature_combined.py
index d032bce0..d8113981 100644
--- a/klippy/extras/temperature_combined.py
+++ b/klippy/extras/temperature_combined.py
@@ -14,47 +14,46 @@ class PrinterSensorCombined:
self.reactor = self.printer.get_reactor()
self.name = config.get_name().split()[-1]
# get sensor names
- self.sensor_names = config.getlist('sensor_list')
+ self.sensor_names = config.getlist("sensor_list")
# get maximum_deviation parameter from config
- self.max_deviation = config.getfloat('maximum_deviation', above=0.)
+ self.max_deviation = config.getfloat("maximum_deviation", above=0.0)
# ensure compatibility with itself
self.sensor = self
# get empty list for sensors, could be any sensor class or a heater
self.sensors = []
# get combination method to handle the different sensor values with
- algos = {'min': min, 'max': max, 'mean': mean}
- self.apply_mode = config.getchoice('combination_method', algos)
+ algos = {"min": min, "max": max, "mean": mean}
+ self.apply_mode = config.getchoice("combination_method", algos)
# set default values
self.last_temp = self.min_temp = self.max_temp = 0.0
# add object
self.printer.add_object("temperature_combined " + self.name, self)
# time-controlled sensor update
self.temperature_update_timer = self.reactor.register_timer(
- self._temperature_update_event)
- self.printer.register_event_handler('klippy:connect',
- self._handle_connect)
- self.printer.register_event_handler('klippy:ready',
- self._handle_ready)
+ self._temperature_update_event
+ )
+ self.printer.register_event_handler("klippy:connect", self._handle_connect)
+ self.printer.register_event_handler("klippy:ready", self._handle_ready)
def _handle_connect(self):
for sensor_name in self.sensor_names:
sensor = self.printer.lookup_object(sensor_name)
# check if sensor has get_status function and
# get_status has a 'temperature' value
- if not hasattr(sensor, 'get_status'):
+ if not hasattr(sensor, "get_status"):
raise self.printer.config_error(
- "'%s' does not have a status."
- % (sensor_name,))
+ "'%s' does not have a status." % (sensor_name,)
+ )
status = sensor.get_status(self.reactor.monotonic())
- if 'temperature' not in status:
+ if "temperature" not in status:
raise self.printer.config_error(
- "'%s' does not report a temperature."
- % (sensor_name,))
+ "'%s' does not report a temperature." % (sensor_name,)
+ )
# Handle temperature monitors
if status["temperature"] is None:
raise self.printer.config_error(
- "Temperature monitor '%s' is not supported"
- % (sensor_name,))
+ "Temperature monitor '%s' is not supported" % (sensor_name,)
+ )
self.sensors.append(sensor)
@@ -62,8 +61,9 @@ class PrinterSensorCombined:
# Start temperature update timer
# There is a race condition with sensors where they can be not ready,
# and return 0 or None - initialize a little bit later.
- self.reactor.update_timer(self.temperature_update_timer,
- self.reactor.monotonic() + 1.)
+ self.reactor.update_timer(
+ self.temperature_update_timer, self.reactor.monotonic() + 1.0
+ )
def setup_minmax(self, min_temp, max_temp):
self.min_temp = min_temp
@@ -79,7 +79,7 @@ class PrinterSensorCombined:
values = []
for sensor in self.sensors:
sensor_status = sensor.get_status(eventtime)
- sensor_temperature = sensor_status['temperature']
+ sensor_temperature = sensor_status["temperature"]
values.append(sensor_temperature)
# check if values are out of max_deviation range
@@ -87,18 +87,24 @@ class PrinterSensorCombined:
self.printer.invoke_shutdown(
"COMBINED SENSOR maximum deviation exceeded limit of %0.1f, "
"max sensor value %0.1f, min sensor value %0.1f."
- % (self.max_deviation, max(values), min(values),))
+ % (
+ self.max_deviation,
+ max(values),
+ min(values),
+ )
+ )
temp = self.apply_mode(values)
if temp:
self.last_temp = temp
def get_temp(self, eventtime):
- return self.last_temp, 0.
+ return self.last_temp, 0.0
def get_status(self, eventtime):
- return {'temperature': round(self.last_temp, 2),
- }
+ return {
+ "temperature": round(self.last_temp, 2),
+ }
def _temperature_update_event(self, eventtime):
# update sensor value
@@ -109,20 +115,29 @@ class PrinterSensorCombined:
self.printer.invoke_shutdown(
"COMBINED SENSOR temperature %0.1f "
"below minimum temperature of %0.1f."
- % (self.last_temp, self.min_temp,))
+ % (
+ self.last_temp,
+ self.min_temp,
+ )
+ )
if self.last_temp > self.max_temp:
self.printer.invoke_shutdown(
"COMBINED SENSOR temperature %0.1f "
"above maximum temperature of %0.1f."
- % (self.last_temp, self.max_temp,))
+ % (
+ self.last_temp,
+ self.max_temp,
+ )
+ )
# this is copied from temperature_host to enable time triggered updates
# get mcu and measured / current(?) time
- mcu = self.printer.lookup_object('mcu')
+ mcu = self.printer.lookup_object("mcu")
measured_time = self.reactor.monotonic()
# convert to print time?! for the callback???
- self.temperature_callback(mcu.estimated_print_time(measured_time),
- self.last_temp)
+ self.temperature_callback(
+ mcu.estimated_print_time(measured_time), self.last_temp
+ )
# set next update time
return measured_time + REPORT_TIME