From 596bc89ee6643962c108ae9a43824a875b73b52a Mon Sep 17 00:00:00 2001 From: "Teemu R." Date: Tue, 11 Nov 2025 14:06:29 +0100 Subject: [PATCH] tplink: handle repeated, unknown thermostat modes gracefully (#156310) --- homeassistant/components/tplink/climate.py | 17 ++++++++--------- tests/components/tplink/test_climate.py | 8 ++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/tplink/climate.py b/homeassistant/components/tplink/climate.py index 45e4575b4e31..c8e7dee8d737 100644 --- a/homeassistant/components/tplink/climate.py +++ b/homeassistant/components/tplink/climate.py @@ -181,15 +181,14 @@ class TPLinkClimateEntity(CoordinatedTPLinkModuleEntity, ClimateEntity): HVACMode.HEAT if self._thermostat_module.state else HVACMode.OFF ) - if ( - self._thermostat_module.mode not in STATE_TO_ACTION - and self._attr_hvac_action is not HVACAction.OFF - ): - _LOGGER.warning( - "Unknown thermostat state, defaulting to OFF: %s", - self._thermostat_module.mode, - ) - self._attr_hvac_action = HVACAction.OFF + if self._thermostat_module.mode not in STATE_TO_ACTION: + # Report a warning on the first non-default unknown mode + if self._attr_hvac_action is not HVACAction.OFF: + _LOGGER.warning( + "Unknown thermostat state, defaulting to OFF: %s", + self._thermostat_module.mode, + ) + self._attr_hvac_action = HVACAction.OFF return True self._attr_hvac_action = STATE_TO_ACTION[self._thermostat_module.mode] diff --git a/tests/components/tplink/test_climate.py b/tests/components/tplink/test_climate.py index 6d5b498b922d..4d4e005fc16e 100644 --- a/tests/components/tplink/test_climate.py +++ b/tests/components/tplink/test_climate.py @@ -225,6 +225,14 @@ async def test_unknown_mode( assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.OFF assert "Unknown thermostat state, defaulting to OFF" in caplog.text + # Second update, make sure the warning is not logged again + caplog.clear() + async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=30)) + await hass.async_block_till_done() + state = hass.states.get(ENTITY_ID) + assert state.attributes[ATTR_HVAC_ACTION] == HVACAction.OFF + assert "Unknown thermostat state, defaulting to OFF" not in caplog.text + async def test_missing_feature_attributes( hass: HomeAssistant,