From 0850c16b00052b817126f27af22dba004a0c7366 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 24 Feb 2024 06:05:07 -0500 Subject: [PATCH] sensor: require the 'state_response_template' The sensor configuration isn't useful unless the user configures a template that calls "set_result" to update fields for the desired template. Remove the default payload template and require that it be configured. Signed-off-by: Eric Callahan --- docs/configuration.md | 2 +- moonraker/components/sensor.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9b0cb80..a035caa 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2837,7 +2837,7 @@ state_response_template: # # The above example assumes a json response with multiple fields in a struct # is received. Individual measurements are extracted from that struct, coerced -# to a numeric format and passed to Moonraker. The default is the payload. +# to a numeric format and passed to Moonraker. This parameter must be provided. ``` !!! Note diff --git a/moonraker/components/sensor.py b/moonraker/components/sensor.py index ea6b16b..5115bd2 100644 --- a/moonraker/components/sensor.py +++ b/moonraker/components/sensor.py @@ -116,7 +116,7 @@ class MQTTSensor(BaseSensor): self.mqtt: MQTTClient = self.server.load_component(cfg, "mqtt") self.state_topic: str = cfg.get("state_topic") - self.state_response = cfg.load_template("state_response_template", "{payload}") + self.state_response = cfg.gettemplate("state_response_template") self.config = replace(self.config, source=self.state_topic) self.qos: Optional[int] = cfg.getint("qos", None, minval=0, maxval=2)