Fix thermostat idle reporting on low battery (#1598)
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled

The `low_battery` state needs to be discarded before checking for an empty
list of states to avoid incorrect reporting when the battery is low and
there is no specific state set.
This commit is contained in:
Teemu R.
2025-10-31 11:13:30 +01:00
committed by GitHub
parent f30f38b887
commit adc291b62e
2 changed files with 14 additions and 2 deletions

View File

@@ -93,12 +93,14 @@ class TemperatureControl(SmartModule):
states = self.states
# Discard known non-mode states
states.discard("low_battery")
# If the states is empty, the device is idling
if not states:
return ThermostatState.Idle
# Discard known extra states, and report on unknown extra states
states.discard("low_battery")
# Report on unknown extra states
if len(states) > 1:
_LOGGER.warning("Got multiple states: %s", states)

View File

@@ -154,3 +154,13 @@ async def test_thermostat_heating_with_low_battery(dev):
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
temp_module.data["trv_states"] = ["low_battery", "heating"]
assert temp_module.mode is ThermostatState.Heating
@thermostats_smart
async def test_thermostat_idle_with_low_battery(dev, caplog):
"""Test that mode is reported correctly with extra states."""
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
temp_module.data["trv_states"] = ["low_battery"]
with caplog.at_level(logging.WARNING):
assert temp_module.mode is ThermostatState.Idle
assert not caplog.records