1 """Support for TP-Link thermostats."""
3 from __future__
import annotations
6 from typing
import Any, cast
8 from kasa
import Device, DeviceType
9 from kasa.smart.modules.temperaturecontrol
import ThermostatState
23 from .
import TPLinkConfigEntry
24 from .const
import UNIT_MAPPING
25 from .coordinator
import TPLinkDataUpdateCoordinator
26 from .entity
import CoordinatedTPLinkEntity, async_refresh_after
30 ThermostatState.Idle: HVACAction.IDLE,
31 ThermostatState.Heating: HVACAction.HEATING,
32 ThermostatState.Off: HVACAction.OFF,
36 _LOGGER = logging.getLogger(__name__)
41 config_entry: TPLinkConfigEntry,
42 async_add_entities: AddEntitiesCallback,
44 """Set up climate entities."""
45 data = config_entry.runtime_data
46 parent_coordinator = data.parent_coordinator
47 device = parent_coordinator.device
52 for child
in device.children
53 if child.device_type
is DeviceType.Thermostat
58 """Representation of a TPLink thermostat."""
61 _attr_supported_features = (
62 ClimateEntityFeature.TARGET_TEMPERATURE
63 | ClimateEntityFeature.TURN_OFF
64 | ClimateEntityFeature.TURN_ON
66 _attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF]
67 _attr_precision = PRECISION_TENTHS
70 _enable_turn_on_off_backwards_compatibility =
False
75 coordinator: TPLinkDataUpdateCoordinator,
79 """Initialize the climate entity."""
89 super().
__init__(device, coordinator, parent=parent)
93 """Set target temperature."""
98 """Set hvac mode (heat/off)."""
99 if hvac_mode
is HVACMode.HEAT:
101 elif hvac_mode
is HVACMode.OFF:
108 """Turn heating on."""
113 """Turn heating off."""
118 """Update the entity's attributes."""
123 HVACMode.HEAT
if self.
_state_feature_state_feature.value
else HVACMode.OFF
131 "Unknown thermostat state, defaulting to OFF: %s",
142 """Return unique id."""
143 return f
"{self._device.device_id}_climate"
_attr_current_temperature
None async_set_temperature(self, **Any kwargs)
None async_turn_off(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None _async_update_attrs(self)
None __init__(self, Device device, TPLinkDataUpdateCoordinator coordinator, *Device parent)
None async_setup_entry(HomeAssistant hass, TPLinkConfigEntry config_entry, AddEntitiesCallback async_add_entities)