Replace Climate HVAC_MODE_* constants with HVACMode enum#70286
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Looks like there are quite a few that expect I can think of two solutions that don't involve changing all the legacy right now: --- a/homeassistant/components/climate/__init__.py
+++ b/homeassistant/components/climate/__init__.py
@@ -211,8 +211,10 @@ class ClimateEntity(Entity):
@final
@property
- def state(self) -> str:
+ def state(self) -> str | None:
"""Return the current state."""
+ if self.hvac_mode is None:
+ return None
if not isinstance(self.hvac_mode, HVACMode):
return HVACMode(self.hvac_mode).value
return self.hvac_mode.value--- a/homeassistant/components/climate/__init__.py
+++ b/homeassistant/components/climate/__init__.py
@@ -9,6 +9,7 @@ from typing import Any, final
import voluptuous as vol
+from homeassistant.helpers.frame import report
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_TEMPERATURE,
@@ -208,11 +209,20 @@ class ClimateEntity(Entity):
_attr_target_temperature_step: float | None = None
_attr_target_temperature: float | None = None
_attr_temperature_unit: str
+ _reported_invalid_state = False
@final
@property
- def state(self) -> str:
+ def state(self) -> str | None:
"""Return the current state."""
+ if self.hvac_mode is None:
+ if not self._reported_invalid_state:
+ self._reported_invalid_state = True
+ report(
+ "Provided an HVACMode of 'None'; This will raise a ValueError exception in 2022.10 and later.",
+ exclude_integrations={"climate"},
+ )
+ return None
if not isinstance(self.hvac_mode, HVACMode):
return HVACMode(self.hvac_mode).value
return self.hvac_mode.value |
|
The changes look good 👍 Resolving the |
|
I think we should allow returning |
Agreed. Will adjust to that. |
|
Does the frontend handle unknown state ok in the climate card? |

Breaking change
Developers only: All
HVAC_MODE_*constants from the Climate platform, have been deprecated. Use the newHVACModeenum instead.Proposed change
See above.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: