From 08efe2bf6d6c93f1f6c0d2dc915e3917232af751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B8yer=20Iversen?= Date: Wed, 8 Feb 2017 18:07:43 +0100 Subject: [PATCH] Improve warning message in template rendering (#5806) * improve warning message when template is none * improve error message when template is none * improve error message when template is none * improve error message when template is none --- homeassistant/components/binary_sensor/template.py | 5 +++-- homeassistant/components/sensor/template.py | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/binary_sensor/template.py b/homeassistant/components/binary_sensor/template.py index e097c7c0ea4..fa60412c77f 100644 --- a/homeassistant/components/binary_sensor/template.py +++ b/homeassistant/components/binary_sensor/template.py @@ -118,7 +118,8 @@ class BinarySensorTemplate(BinarySensorDevice): if ex.args and ex.args[0].startswith( "UndefinedError: 'None' has no attribute"): # Common during HA startup - so just a warning - _LOGGER.warning(ex) + _LOGGER.warning('Could not render template %s,' + ' the state is unknown.', self._name) return - _LOGGER.error(ex) + _LOGGER.error('Could not render template %s: %s', self._name, ex) self._state = False diff --git a/homeassistant/components/sensor/template.py b/homeassistant/components/sensor/template.py index 2535bea1539..aba42519e60 100644 --- a/homeassistant/components/sensor/template.py +++ b/homeassistant/components/sensor/template.py @@ -131,10 +131,11 @@ class SensorTemplate(Entity): if ex.args and ex.args[0].startswith( "UndefinedError: 'None' has no attribute"): # Common during HA startup - so just a warning - _LOGGER.warning(ex) + _LOGGER.warning('Could not render template %s,' + ' the state is unknown.', self._name) return self._state = None - _LOGGER.error(ex) + _LOGGER.error('Could not render template %s: %s', self._name, ex) if self._icon_template is not None: try: @@ -143,7 +144,9 @@ class SensorTemplate(Entity): if ex.args and ex.args[0].startswith( "UndefinedError: 'None' has no attribute"): # Common during HA startup - so just a warning - _LOGGER.warning(ex) + _LOGGER.warning('Could not render icon template %s,' + ' the state is unknown.', self._name) return self._icon = super().icon - _LOGGER.error(ex) + _LOGGER.error('Could not render icon template %s: %s', + self._name, ex)