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 <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-02-24 06:05:07 -05:00
parent 90e13c07f7
commit 0850c16b00
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
2 changed files with 2 additions and 2 deletions

View File

@ -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

View File

@ -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)