Trouble working with temerature hook

Lead by other examples I try to implement the hook like this:

class LedStripePlugin(octoprint.plugin.StartupPlugin,
			octoprint.plugin.ShutdownPlugin):

....
	
	
	def ReadTemperature(self, comm_instance, parsed_temperatures, *args, **kwargs):
		self._logger.info("ToolTemp, %s" % parsed_temperatures)

def __plugin_load__():
	global __plugin_implementation__
	__plugin_implementation__ = LedStripePlugin()

	global __plugin_hooks__
	__plugin_hooks__ = {
		"octoprint.comm.protocol.temperatures.received": __plugin_implementation__.ReadTemperature
	}

In the result the data are shown in the log, but no temp graph & data are shown in the GUI.

What I didn't get handling hooks?

That what you return from a hook can influence what happens :wink:

(https://docs.octoprint.org/en/master/plugins/hooks.html#octoprint-comm-protocol-temperatures-received)

The hook returns the dictionary: (LogInfo Printout, tested with the simulator)
2020-04-07 12:20:32,210 - octoprint.plugins.LedStripePlugin - INFO - ToolTemp, {'B': (21.3, 0.0), 'T0': (21.3, 0.0)}
No further warnings or errors found in the log, but the GUI doesn't show the graphs and no temperatures. Without this hook all temperatures and graphs are shown..

The hook handler as shared above doesn't return anything. It logs something, but it doesn't return anything from the function itself. OctoPrint thus assumes your hook has deemed all temperature data invalid and doesn't show anything.

Try

def ReadTemperature(self, comm_instance, parsed_temperatures, *args, **kwargs):
    self._logger.info("ToolTemp, %s" % parsed_temperatures)
    return parsed_temperatures

(side note: function/method names in Python start with a lower case, this isn't C# :wink: )

1 Like