2020-09-04 13:33:54 +00:00
|
|
|
"""Platform for climate integration."""
|
2021-03-17 22:43:55 +00:00
|
|
|
from __future__ import annotations
|
2020-09-04 13:33:54 +00:00
|
|
|
|
2021-07-02 16:37:18 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2020-09-04 13:33:54 +00:00
|
|
|
from homeassistant.components.climate import (
|
|
|
|
ATTR_TEMPERATURE,
|
|
|
|
HVAC_MODE_HEAT,
|
|
|
|
SUPPORT_TARGET_TEMPERATURE,
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
ClimateEntity,
|
|
|
|
)
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-07-20 12:13:51 +00:00
|
|
|
from homeassistant.const import PRECISION_HALVES, PRECISION_TENTHS
|
2021-04-17 10:48:03 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2021-07-02 16:37:18 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-09-04 13:33:54 +00:00
|
|
|
|
|
|
|
from .const import DOMAIN
|
2020-09-24 15:57:52 +00:00
|
|
|
from .devolo_multi_level_switch import DevoloMultiLevelSwitchDeviceEntity
|
2020-09-04 13:33:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
2021-07-02 16:37:18 +00:00
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
2020-09-04 13:33:54 +00:00
|
|
|
) -> None:
|
|
|
|
"""Get all cover devices and setup them via config entry."""
|
|
|
|
entities = []
|
|
|
|
|
2020-10-28 19:54:57 +00:00
|
|
|
for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]:
|
2020-10-22 13:01:44 +00:00
|
|
|
for device in gateway.multi_level_switch_devices:
|
|
|
|
for multi_level_switch in device.multi_level_switch_property:
|
|
|
|
if device.device_model_uid in [
|
|
|
|
"devolo.model.Thermostat:Valve",
|
|
|
|
"devolo.model.Room:Thermostat",
|
|
|
|
"devolo.model.Eurotronic:Spirit:Device",
|
|
|
|
]:
|
|
|
|
entities.append(
|
|
|
|
DevoloClimateDeviceEntity(
|
|
|
|
homecontrol=gateway,
|
|
|
|
device_instance=device,
|
|
|
|
element_uid=multi_level_switch,
|
|
|
|
)
|
2020-09-04 13:33:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
async_add_entities(entities, False)
|
|
|
|
|
|
|
|
|
2020-09-24 15:57:52 +00:00
|
|
|
class DevoloClimateDeviceEntity(DevoloMultiLevelSwitchDeviceEntity, ClimateEntity):
|
2020-09-04 13:33:54 +00:00
|
|
|
"""Representation of a climate/thermostat device within devolo Home Control."""
|
|
|
|
|
|
|
|
@property
|
2021-03-17 22:43:55 +00:00
|
|
|
def current_temperature(self) -> float | None:
|
2020-10-13 00:21:59 +00:00
|
|
|
"""Return the current temperature."""
|
|
|
|
if hasattr(self._device_instance, "multi_level_sensor_property"):
|
|
|
|
return next(
|
|
|
|
(
|
|
|
|
multi_level_sensor.value
|
|
|
|
for multi_level_sensor in self._device_instance.multi_level_sensor_property.values()
|
|
|
|
if multi_level_sensor.sensor_type == "temperature"
|
|
|
|
),
|
|
|
|
None,
|
|
|
|
)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
@property
|
2021-03-17 22:43:55 +00:00
|
|
|
def target_temperature(self) -> float | None:
|
2020-10-22 08:06:16 +00:00
|
|
|
"""Return the target temperature."""
|
2020-09-24 15:57:52 +00:00
|
|
|
return self._value
|
2020-09-04 13:33:54 +00:00
|
|
|
|
2020-10-22 08:06:16 +00:00
|
|
|
@property
|
|
|
|
def target_temperature_step(self) -> float:
|
|
|
|
"""Return the precision of the target temperature."""
|
|
|
|
return PRECISION_HALVES
|
|
|
|
|
2020-09-04 13:33:54 +00:00
|
|
|
@property
|
|
|
|
def hvac_mode(self) -> str:
|
|
|
|
"""Return the supported HVAC mode."""
|
|
|
|
return HVAC_MODE_HEAT
|
|
|
|
|
|
|
|
@property
|
2021-03-17 22:43:55 +00:00
|
|
|
def hvac_modes(self) -> list[str]:
|
2020-09-04 13:33:54 +00:00
|
|
|
"""Return the list of available hvac operation modes."""
|
|
|
|
return [HVAC_MODE_HEAT]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def min_temp(self) -> float:
|
|
|
|
"""Return the minimum set temperature value."""
|
2021-07-02 16:37:18 +00:00
|
|
|
min_temp: float = self._multi_level_switch_property.min
|
|
|
|
return min_temp
|
2020-09-04 13:33:54 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def max_temp(self) -> float:
|
|
|
|
"""Return the maximum set temperature value."""
|
2021-07-02 16:37:18 +00:00
|
|
|
max_temp: float = self._multi_level_switch_property.max
|
|
|
|
return max_temp
|
2020-09-04 13:33:54 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def precision(self) -> float:
|
|
|
|
"""Return the precision of the set temperature."""
|
2020-10-22 08:06:16 +00:00
|
|
|
return PRECISION_TENTHS
|
2020-09-04 13:33:54 +00:00
|
|
|
|
|
|
|
@property
|
2021-07-02 16:37:18 +00:00
|
|
|
def supported_features(self) -> int:
|
2020-09-04 13:33:54 +00:00
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_TARGET_TEMPERATURE
|
|
|
|
|
|
|
|
@property
|
2021-07-20 12:13:51 +00:00
|
|
|
def temperature_unit(self) -> str:
|
2020-09-04 13:33:54 +00:00
|
|
|
"""Return the supported unit of temperature."""
|
|
|
|
return TEMP_CELSIUS
|
|
|
|
|
2020-10-13 00:21:59 +00:00
|
|
|
def set_hvac_mode(self, hvac_mode: str) -> None:
|
|
|
|
"""Do nothing as devolo devices do not support changing the hvac mode."""
|
|
|
|
|
2021-07-02 16:37:18 +00:00
|
|
|
def set_temperature(self, **kwargs: Any) -> None:
|
2020-09-04 13:33:54 +00:00
|
|
|
"""Set new target temperature."""
|
|
|
|
self._multi_level_switch_property.set(kwargs[ATTR_TEMPERATURE])
|