2020-05-25 19:45:01 +00:00
|
|
|
"""BleBox climate entity."""
|
2022-04-25 11:17:46 +00:00
|
|
|
from homeassistant.components.climate import ClimateEntity
|
2020-05-25 19:45:01 +00:00
|
|
|
from homeassistant.components.climate.const import (
|
2022-04-25 11:17:46 +00:00
|
|
|
ClimateEntityFeature,
|
|
|
|
HVACAction,
|
|
|
|
HVACMode,
|
2020-05-25 19:45:01 +00:00
|
|
|
)
|
2022-01-03 12:26:32 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-05-25 19:45:01 +00:00
|
|
|
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
2022-01-03 12:26:32 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
from . import BleBoxEntity, create_blebox_entities
|
|
|
|
|
|
|
|
|
2022-01-03 12:26:32 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-05-25 19:45:01 +00:00
|
|
|
"""Set up a BleBox climate entity."""
|
|
|
|
|
|
|
|
create_blebox_entities(
|
|
|
|
hass, config_entry, async_add_entities, BleBoxClimateEntity, "climates"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-05-26 11:29:19 +00:00
|
|
|
class BleBoxClimateEntity(BleBoxEntity, ClimateEntity):
|
2020-05-25 19:45:01 +00:00
|
|
|
"""Representation of a BleBox climate feature (saunaBox)."""
|
|
|
|
|
2022-04-05 21:53:45 +00:00
|
|
|
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
|
2022-04-25 11:17:46 +00:00
|
|
|
_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT]
|
2021-07-12 20:52:38 +00:00
|
|
|
_attr_temperature_unit = TEMP_CELSIUS
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def hvac_mode(self):
|
|
|
|
"""Return the desired HVAC mode."""
|
|
|
|
if self._feature.is_on is None:
|
|
|
|
return None
|
|
|
|
|
2022-04-25 11:17:46 +00:00
|
|
|
return HVACMode.HEAT if self._feature.is_on else HVACMode.OFF
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def hvac_action(self):
|
|
|
|
"""Return the actual current HVAC action."""
|
2021-10-17 17:56:00 +00:00
|
|
|
if not (is_on := self._feature.is_on):
|
2022-04-25 11:17:46 +00:00
|
|
|
return None if is_on is None else HVACAction.OFF
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
# NOTE: In practice, there's no need to handle case when is_heating is None
|
2022-04-25 11:17:46 +00:00
|
|
|
return HVACAction.HEATING if self._feature.is_heating else HVACAction.IDLE
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self):
|
|
|
|
"""Return the maximum temperature supported."""
|
|
|
|
return self._feature.max_temp
|
|
|
|
|
|
|
|
@property
|
|
|
|
def min_temp(self):
|
|
|
|
"""Return the maximum temperature supported."""
|
|
|
|
return self._feature.min_temp
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self):
|
|
|
|
"""Return the current temperature."""
|
|
|
|
return self._feature.current
|
|
|
|
|
|
|
|
@property
|
|
|
|
def target_temperature(self):
|
|
|
|
"""Return the desired thermostat temperature."""
|
|
|
|
return self._feature.desired
|
|
|
|
|
|
|
|
async def async_set_hvac_mode(self, hvac_mode):
|
|
|
|
"""Set the climate entity mode."""
|
2022-04-25 11:17:46 +00:00
|
|
|
if hvac_mode == HVACMode.HEAT:
|
2020-05-26 11:29:19 +00:00
|
|
|
await self._feature.async_on()
|
|
|
|
return
|
2020-05-25 19:45:01 +00:00
|
|
|
|
2020-05-26 11:29:19 +00:00
|
|
|
await self._feature.async_off()
|
2020-05-25 19:45:01 +00:00
|
|
|
|
|
|
|
async def async_set_temperature(self, **kwargs):
|
|
|
|
"""Set the thermostat temperature."""
|
|
|
|
value = kwargs[ATTR_TEMPERATURE]
|
|
|
|
await self._feature.async_set_temperature(value)
|