From 7216d4c636792919e93d64402918d210771348e5 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 27 Sep 2022 00:36:10 +0200 Subject: [PATCH] Add debug logging for MQTT templates (#79016) --- homeassistant/components/mqtt/models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/homeassistant/components/mqtt/models.py b/homeassistant/components/mqtt/models.py index 566f18bc791..274f7019210 100644 --- a/homeassistant/components/mqtt/models.py +++ b/homeassistant/components/mqtt/models.py @@ -6,6 +6,7 @@ from collections import deque from collections.abc import Callable, Coroutine from dataclasses import dataclass, field import datetime as dt +import logging from typing import TYPE_CHECKING, Any, TypedDict, Union import attr @@ -24,6 +25,8 @@ if TYPE_CHECKING: _SENTINEL = object() +_LOGGER = logging.getLogger(__name__) + ATTR_THIS = "this" PublishPayloadType = Union[str, bytes, int, float, None] @@ -138,6 +141,11 @@ class MqttCommandTemplate: if variables is not None: values.update(variables) + _LOGGER.debug( + "Rendering outgoing payload with variables %s and %s", + values, + self._command_template, + ) return _convert_outgoing_payload( self._command_template.async_render(values, parse_result=False) ) @@ -196,10 +204,23 @@ class MqttValueTemplate: values[ATTR_THIS] = self._template_state if default == _SENTINEL: + _LOGGER.debug( + "Rendering incoming payload '%s' with variables %s and %s", + payload, + values, + self._value_template, + ) return self._value_template.async_render_with_possible_json_value( payload, variables=values ) + _LOGGER.debug( + "Rendering incoming payload '%s' with variables %s with default value '%s' and %s", + payload, + values, + default, + self._value_template, + ) return self._value_template.async_render_with_possible_json_value( payload, default, variables=values )