mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Improve toon climate (#25040)
* Renames internal climate state variable to preset * Shorten function comments * Updates local variables on preset and temp changes * Adds support for hvac_action
This commit is contained in:
parent
cf5a35a421
commit
36ed725ab4
@ -6,7 +6,8 @@ from typing import Any, Dict, List, Optional
|
|||||||
from homeassistant.components.climate import ClimateDevice
|
from homeassistant.components.climate import ClimateDevice
|
||||||
from homeassistant.components.climate.const import (
|
from homeassistant.components.climate.const import (
|
||||||
HVAC_MODE_HEAT, PRESET_AWAY, PRESET_COMFORT, PRESET_HOME, PRESET_SLEEP,
|
HVAC_MODE_HEAT, PRESET_AWAY, PRESET_COMFORT, PRESET_HOME, PRESET_SLEEP,
|
||||||
SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE)
|
SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, CURRENT_HVAC_HEAT,
|
||||||
|
CURRENT_HVAC_IDLE)
|
||||||
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
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
@ -42,10 +43,11 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
|
|||||||
"""Initialize the Toon climate device."""
|
"""Initialize the Toon climate device."""
|
||||||
self._client = toon_client
|
self._client = toon_client
|
||||||
|
|
||||||
self._state = None
|
|
||||||
self._current_temperature = None
|
self._current_temperature = None
|
||||||
self._target_temperature = None
|
self._target_temperature = None
|
||||||
|
self._heating = False
|
||||||
self._next_target_temperature = None
|
self._next_target_temperature = None
|
||||||
|
self._preset = None
|
||||||
|
|
||||||
self._heating_type = None
|
self._heating_type = None
|
||||||
|
|
||||||
@ -63,20 +65,21 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_mode(self) -> str:
|
def hvac_mode(self) -> str:
|
||||||
"""Return hvac operation ie. heat, cool mode.
|
"""Return hvac operation ie. heat, cool mode."""
|
||||||
|
|
||||||
Need to be one of HVAC_MODE_*.
|
|
||||||
"""
|
|
||||||
return HVAC_MODE_HEAT
|
return HVAC_MODE_HEAT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hvac_modes(self) -> List[str]:
|
def hvac_modes(self) -> List[str]:
|
||||||
"""Return the list of available hvac operation modes.
|
"""Return the list of available hvac operation modes."""
|
||||||
|
|
||||||
Need to be a subset of HVAC_MODES.
|
|
||||||
"""
|
|
||||||
return [HVAC_MODE_HEAT]
|
return [HVAC_MODE_HEAT]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hvac_action(self) -> Optional[str]:
|
||||||
|
"""Return the current running hvac operation."""
|
||||||
|
if self._heating:
|
||||||
|
return CURRENT_HVAC_HEAT
|
||||||
|
return CURRENT_HVAC_IDLE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self) -> str:
|
def temperature_unit(self) -> str:
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
@ -85,8 +88,8 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
|
|||||||
@property
|
@property
|
||||||
def preset_mode(self) -> Optional[str]:
|
def preset_mode(self) -> Optional[str]:
|
||||||
"""Return the current preset mode, e.g., home, away, temp."""
|
"""Return the current preset mode, e.g., home, away, temp."""
|
||||||
if self._state is not None:
|
if self._preset is not None:
|
||||||
return self._state.lower()
|
return self._preset.lower()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -122,13 +125,13 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
|
|||||||
def set_temperature(self, **kwargs) -> None:
|
def set_temperature(self, **kwargs) -> None:
|
||||||
"""Change the setpoint of the thermostat."""
|
"""Change the setpoint of the thermostat."""
|
||||||
temperature = kwargs.get(ATTR_TEMPERATURE)
|
temperature = kwargs.get(ATTR_TEMPERATURE)
|
||||||
self._client.thermostat = temperature
|
self._client.thermostat = self._target_temperature = temperature
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_preset_mode(self, preset_mode: str) -> None:
|
def set_preset_mode(self, preset_mode: str) -> None:
|
||||||
"""Set new preset mode."""
|
"""Set new preset mode."""
|
||||||
if preset_mode is not None:
|
if preset_mode is not None:
|
||||||
self._client.thermostat_state = preset_mode
|
self._client.thermostat_state = self._preset = preset_mode
|
||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
def set_hvac_mode(self, hvac_mode: str) -> None:
|
def set_hvac_mode(self, hvac_mode: str) -> None:
|
||||||
@ -138,10 +141,11 @@ class ToonThermostatDevice(ToonDisplayDeviceEntity, ClimateDevice):
|
|||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update local state."""
|
"""Update local state."""
|
||||||
if self.toon.thermostat_state is None:
|
if self.toon.thermostat_state is None:
|
||||||
self._state = None
|
self._preset = None
|
||||||
else:
|
else:
|
||||||
self._state = self.toon.thermostat_state.name
|
self._preset = self.toon.thermostat_state.name
|
||||||
|
|
||||||
self._current_temperature = self.toon.temperature
|
self._current_temperature = self.toon.temperature
|
||||||
self._target_temperature = self.toon.thermostat
|
self._target_temperature = self.toon.thermostat
|
||||||
self._heating_type = self.toon.agreement.heating_type
|
self._heating_type = self.toon.agreement.heating_type
|
||||||
|
self._heating = self.toon.thermostat_info.burner_info == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user