mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +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
|
from aioshelly.block_device import Block
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN, ClimateEntity
|
||||||
DOMAIN as CLIMATE_DOMAIN,
|
|
||||||
ClimateEntity,
|
|
||||||
ClimateEntityFeature,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
CURRENT_HVAC_HEAT,
|
|
||||||
CURRENT_HVAC_IDLE,
|
|
||||||
CURRENT_HVAC_OFF,
|
|
||||||
HVAC_MODE_HEAT,
|
|
||||||
HVAC_MODE_OFF,
|
|
||||||
PRESET_NONE,
|
PRESET_NONE,
|
||||||
|
ClimateEntityFeature,
|
||||||
|
HVACAction,
|
||||||
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||||
@ -116,7 +110,7 @@ class BlockSleepingClimate(
|
|||||||
):
|
):
|
||||||
"""Representation of a Shelly climate device."""
|
"""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_icon = "mdi:thermostat"
|
||||||
_attr_max_temp = SHTRV_01_TEMPERATURE_SETTINGS["max"]
|
_attr_max_temp = SHTRV_01_TEMPERATURE_SETTINGS["max"]
|
||||||
_attr_min_temp = SHTRV_01_TEMPERATURE_SETTINGS["min"]
|
_attr_min_temp = SHTRV_01_TEMPERATURE_SETTINGS["min"]
|
||||||
@ -191,14 +185,14 @@ class BlockSleepingClimate(
|
|||||||
return self.wrapper.last_update_success
|
return self.wrapper.last_update_success
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> HVACMode:
|
||||||
"""HVAC current mode."""
|
"""HVAC current mode."""
|
||||||
if self.device_block is None:
|
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():
|
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
|
@property
|
||||||
def preset_mode(self) -> str | None:
|
def preset_mode(self) -> str | None:
|
||||||
@ -210,18 +204,16 @@ class BlockSleepingClimate(
|
|||||||
return self._preset_modes[cast(int, self.device_block.mode)]
|
return self._preset_modes[cast(int, self.device_block.mode)]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_action(self) -> str | None:
|
def hvac_action(self) -> HVACAction:
|
||||||
"""HVAC current action."""
|
"""HVAC current action."""
|
||||||
if (
|
if (
|
||||||
self.device_block is None
|
self.device_block is None
|
||||||
or self.device_block.status is None
|
or self.device_block.status is None
|
||||||
or self._check_is_off()
|
or self._check_is_off()
|
||||||
):
|
):
|
||||||
return CURRENT_HVAC_OFF
|
return HVACAction.OFF
|
||||||
|
|
||||||
return (
|
return HVACAction.HEATING if bool(self.device_block.status) else HVACAction.IDLE
|
||||||
CURRENT_HVAC_HEAT if bool(self.device_block.status) else CURRENT_HVAC_IDLE
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def preset_modes(self) -> list[str]:
|
def preset_modes(self) -> list[str]:
|
||||||
@ -266,9 +258,9 @@ class BlockSleepingClimate(
|
|||||||
return
|
return
|
||||||
await self.set_state_full_path(target_t_enabled=1, target_t=f"{current_temp}")
|
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."""
|
"""Set hvac mode."""
|
||||||
if hvac_mode == HVAC_MODE_OFF:
|
if hvac_mode == HVACMode.OFF:
|
||||||
await self.set_state_full_path(
|
await self.set_state_full_path(
|
||||||
target_t_enabled=1, target_t=f"{self._attr_min_temp}"
|
target_t_enabled=1, target_t=f"{self._attr_min_temp}"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user