diff --git a/homeassistant/backports/enum.py b/homeassistant/backports/enum.py index 35562877bab..178859ecbe7 100644 --- a/homeassistant/backports/enum.py +++ b/homeassistant/backports/enum.py @@ -10,6 +10,8 @@ from typing_extensions import Self class StrEnum(str, Enum): """Partial backport of Python 3.11's StrEnum for our basic use cases.""" + value: str + def __new__(cls, value: str, *args: Any, **kwargs: Any) -> Self: """Create a new StrEnum instance.""" if not isinstance(value, str): @@ -18,7 +20,7 @@ class StrEnum(str, Enum): def __str__(self) -> str: """Return self.value.""" - return str(self.value) + return self.value @staticmethod def _generate_next_value_( diff --git a/homeassistant/components/demo/climate.py b/homeassistant/components/demo/climate.py index 407860526ae..bfc2cd1a2e7 100644 --- a/homeassistant/components/demo/climate.py +++ b/homeassistant/components/demo/climate.py @@ -64,7 +64,7 @@ async def async_setup_entry( aux=False, target_temp_high=None, target_temp_low=None, - hvac_modes=[cls.value for cls in HVACMode if cls != HVACMode.HEAT_COOL], + hvac_modes=[cls for cls in HVACMode if cls != HVACMode.HEAT_COOL], ), DemoClimate( unique_id="climate_3", @@ -83,7 +83,7 @@ async def async_setup_entry( aux=None, target_temp_high=24, target_temp_low=21, - hvac_modes=[cls.value for cls in HVACMode if cls != HVACMode.HEAT], + hvac_modes=[cls for cls in HVACMode if cls != HVACMode.HEAT], ), ] ) diff --git a/homeassistant/components/isy994/climate.py b/homeassistant/components/isy994/climate.py index 83fea57a9fa..8fc90efaabc 100644 --- a/homeassistant/components/isy994/climate.py +++ b/homeassistant/components/isy994/climate.py @@ -37,6 +37,7 @@ from homeassistant.const import ( from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback +from homeassistant.util.enum import try_parse_enum from .const import ( _LOGGER, @@ -131,7 +132,10 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity): if self._node.protocol == PROTO_INSTEON else UOM_HVAC_MODE_GENERIC ) - return UOM_TO_STATES[uom].get(hvac_mode.value, HVACMode.OFF) + return ( + try_parse_enum(HVACMode, UOM_TO_STATES[uom].get(hvac_mode.value)) + or HVACMode.OFF + ) @property def hvac_action(self) -> HVACAction | None: @@ -139,7 +143,9 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity): hvac_action = self._node.aux_properties.get(PROP_HEAT_COOL_STATE) if not hvac_action: return None - return UOM_TO_STATES[UOM_HVAC_ACTIONS].get(hvac_action.value) + return try_parse_enum( + HVACAction, UOM_TO_STATES[UOM_HVAC_ACTIONS].get(hvac_action.value) + ) @property def current_temperature(self) -> float | None: