From 1b11062b278a125fbacdf0a565d6bbf7957e69a9 Mon Sep 17 00:00:00 2001 From: Nicolas van de Walle Date: Sun, 8 Oct 2023 19:40:42 +0200 Subject: [PATCH] Improved debugging for "Failed to set state" (#101657) --- homeassistant/helpers/entity.py | 4 +++- tests/helpers/test_entity.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index 542841f7f7c..f0a05f7aded 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -907,7 +907,9 @@ class Entity(ABC): self._state_info, ) except InvalidStateError: - _LOGGER.exception("Failed to set state, fall back to %s", STATE_UNKNOWN) + _LOGGER.exception( + "Failed to set state for %s, fall back to %s", entity_id, STATE_UNKNOWN + ) hass.states.async_set( entity_id, STATE_UNKNOWN, {}, self.force_update, self._context ) diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index ff9ad99435f..572a2afaa5d 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -1500,7 +1500,7 @@ async def test_invalid_state( assert ( "homeassistant.helpers.entity", logging.ERROR, - f"Failed to set state, fall back to {STATE_UNKNOWN}", + f"Failed to set state for test.test, fall back to {STATE_UNKNOWN}", ) in caplog.record_tuples ent._attr_state = "x" * 255