mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove unneeded str() in StrEnum backport (#96509)
This commit is contained in:
parent
3e429ae081
commit
7a1f0a0b74
@ -10,6 +10,8 @@ from typing_extensions import Self
|
|||||||
class StrEnum(str, Enum):
|
class StrEnum(str, Enum):
|
||||||
"""Partial backport of Python 3.11's StrEnum for our basic use cases."""
|
"""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:
|
def __new__(cls, value: str, *args: Any, **kwargs: Any) -> Self:
|
||||||
"""Create a new StrEnum instance."""
|
"""Create a new StrEnum instance."""
|
||||||
if not isinstance(value, str):
|
if not isinstance(value, str):
|
||||||
@ -18,7 +20,7 @@ class StrEnum(str, Enum):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Return self.value."""
|
"""Return self.value."""
|
||||||
return str(self.value)
|
return self.value
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _generate_next_value_(
|
def _generate_next_value_(
|
||||||
|
@ -64,7 +64,7 @@ async def async_setup_entry(
|
|||||||
aux=False,
|
aux=False,
|
||||||
target_temp_high=None,
|
target_temp_high=None,
|
||||||
target_temp_low=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(
|
DemoClimate(
|
||||||
unique_id="climate_3",
|
unique_id="climate_3",
|
||||||
@ -83,7 +83,7 @@ async def async_setup_entry(
|
|||||||
aux=None,
|
aux=None,
|
||||||
target_temp_high=24,
|
target_temp_high=24,
|
||||||
target_temp_low=21,
|
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],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -37,6 +37,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
from homeassistant.util.enum import try_parse_enum
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
@ -131,7 +132,10 @@ class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
|||||||
if self._node.protocol == PROTO_INSTEON
|
if self._node.protocol == PROTO_INSTEON
|
||||||
else UOM_HVAC_MODE_GENERIC
|
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
|
@property
|
||||||
def hvac_action(self) -> HVACAction | None:
|
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)
|
hvac_action = self._node.aux_properties.get(PROP_HEAT_COOL_STATE)
|
||||||
if not hvac_action:
|
if not hvac_action:
|
||||||
return None
|
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
|
@property
|
||||||
def current_temperature(self) -> float | None:
|
def current_temperature(self) -> float | None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user