Skip to content

Commit

Permalink
Remove unneeded str() in StrEnum backport (#96509)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Jul 14, 2023
1 parent 3e429ae commit 7a1f0a0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 3 additions & 1 deletion homeassistant/backports/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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):
Expand All @@ -18,7 +20,7 @@ def __new__(cls, value: str, *args: Any, **kwargs: Any) -> Self:

def __str__(self) -> str:
"""Return self.value."""
return str(self.value)
return self.value

@staticmethod
def _generate_next_value_(
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/demo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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],
),
]
)
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/isy994/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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,
Expand Down Expand Up @@ -131,15 +132,20 @@ def hvac_mode(self) -> HVACMode:
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:
"""Return the current running hvac operation if supported."""
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:
Expand Down

0 comments on commit 7a1f0a0

Please sign in to comment.