Support empty output of MQTT binary_sensor value_template (#37420)
* Support empty output of MQTT binary_sensor value_template * Strip white space * Add test * Add test
This commit is contained in:
1 parent
333c151955
commit
9ade1de3d5
2 files changed
+87
-4
No files matched your search
@@ -189,17 +189,30 @@ class MqttBinarySensor(
|
||||
payload = value_template.async_render_with_possible_json_value(
|
||||
payload, variables={"entity_id": self.entity_id}
|
||||
)
|
||||
if not payload.strip(): # No output from template, ignore
|
||||
_LOGGER.debug(
|
||||
"Empty template output for entity: %s with state topic: %s. Payload: '%s', with value template '%s'",
|
||||
self._config[CONF_NAME],
|
||||
self._config[CONF_STATE_TOPIC],
|
||||
msg.payload,
|
||||
value_template,
|
||||
)
|
||||
return
|
||||
|
||||
if payload == self._config[CONF_PAYLOAD_ON]:
|
||||
self._state = True
|
||||
elif payload == self._config[CONF_PAYLOAD_OFF]:
|
||||
self._state = False
|
||||
else: # Payload is not for this entity
|
||||
_LOGGER.warning(
|
||||
"No matching payload found for entity: %s with state topic: %s. Payload: %s, with value template %s",
|
||||
template_info = ""
|
||||
if value_template is not None:
|
||||
template_info = f", template output: '{payload}', with value template '{str(value_template)}'"
|
||||
_LOGGER.info(
|
||||
"No matching payload found for entity: %s with state topic: %s. Payload: '%s'%s",
|
||||
self._config[CONF_NAME],
|
||||
self._config[CONF_STATE_TOPIC],
|
||||
payload,
|
||||
value_template,
|
||||
msg.payload,
|
||||
template_info,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
Reference in new issue
Block a user