mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Use climate enums in shelly (#70736)
This commit is contained in:
parent
98d757b2b2
commit
a3938deb24
@ -8,18 +8,12 @@ from typing import Any, cast
|
||||
from aioshelly.block_device import Block
|
||||
import async_timeout
|
||||
|
||||
from homeassistant.components.climate import (
|
||||
DOMAIN as CLIMATE_DOMAIN,
|
||||
ClimateEntity,
|
||||
ClimateEntityFeature,
|
||||
)
|
||||
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, ClimateEntity
|
||||
from homeassistant.components.climate.const import (
|
||||
CURRENT_HVAC_HEAT,
|
||||
CURRENT_HVAC_IDLE,
|
||||
CURRENT_HVAC_OFF,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
PRESET_NONE,
|
||||
ClimateEntityFeature,
|
||||
HVACAction,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
@ -116,7 +110,7 @@ class BlockSleepingClimate(
|
||||
):
|
||||
"""Representation of a Shelly climate device."""
|
||||
|
||||
_attr_hvac_modes = [HVAC_MODE_OFF, HVAC_MODE_HEAT]
|
||||
_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]
|
||||
_attr_icon = "mdi:thermostat"
|
||||
_attr_max_temp = SHTRV_01_TEMPERATURE_SETTINGS["max"]
|
||||
_attr_min_temp = SHTRV_01_TEMPERATURE_SETTINGS["min"]
|
||||
@ -191,14 +185,14 @@ class BlockSleepingClimate(
|
||||
return self.wrapper.last_update_success
|
||||
|
||||
@property
|
||||
def hvac_mode(self) -> str:
|
||||
def hvac_mode(self) -> HVACMode:
|
||||
"""HVAC current mode."""
|
||||
if self.device_block is None:
|
||||
return self.last_state.state if self.last_state else HVAC_MODE_OFF
|
||||
return HVACMode(self.last_state.state) if self.last_state else HVACMode.OFF
|
||||
if self.device_block.mode is None or self._check_is_off():
|
||||
return HVAC_MODE_OFF
|
||||
return HVACMode.OFF
|
||||
|
||||
return HVAC_MODE_HEAT
|
||||
return HVACMode.HEAT
|
||||
|
||||
@property
|
||||
def preset_mode(self) -> str | None:
|
||||
@ -210,18 +204,16 @@ class BlockSleepingClimate(
|
||||
return self._preset_modes[cast(int, self.device_block.mode)]
|
||||
|
||||
@property
|
||||
def hvac_action(self) -> str | None:
|
||||
def hvac_action(self) -> HVACAction:
|
||||
"""HVAC current action."""
|
||||
if (
|
||||
self.device_block is None
|
||||
or self.device_block.status is None
|
||||
or self._check_is_off()
|
||||
):
|
||||
return CURRENT_HVAC_OFF
|
||||
return HVACAction.OFF
|
||||
|
||||
return (
|
||||
CURRENT_HVAC_HEAT if bool(self.device_block.status) else CURRENT_HVAC_IDLE
|
||||
)
|
||||
return HVACAction.HEATING if bool(self.device_block.status) else HVACAction.IDLE
|
||||
|
||||
@property
|
||||
def preset_modes(self) -> list[str]:
|
||||
@ -266,9 +258,9 @@ class BlockSleepingClimate(
|
||||
return
|
||||
await self.set_state_full_path(target_t_enabled=1, target_t=f"{current_temp}")
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set hvac mode."""
|
||||
if hvac_mode == HVAC_MODE_OFF:
|
||||
if hvac_mode == HVACMode.OFF:
|
||||
await self.set_state_full_path(
|
||||
target_t_enabled=1, target_t=f"{self._attr_min_temp}"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user