1 """Climate platform for Tesla Fleet integration."""
3 from __future__
import annotations
5 from itertools
import chain
6 from typing
import Any, cast
8 from tesla_fleet_api.const
import CabinOverheatProtectionTemp, Scope
26 from .
import TeslaFleetConfigEntry
27 from .const
import DOMAIN, TeslaFleetClimateSide
28 from .entity
import TeslaFleetVehicleEntity
29 from .helpers
import handle_vehicle_command
30 from .models
import TeslaFleetVehicleData
40 entry: TeslaFleetConfigEntry,
41 async_add_entities: AddEntitiesCallback,
43 """Set up the Tesla Fleet Climate platform from a config entry."""
49 vehicle, TeslaFleetClimateSide.DRIVER, entry.runtime_data.scopes
51 for vehicle
in entry.runtime_data.vehicles
55 vehicle, entry.runtime_data.scopes
57 for vehicle
in entry.runtime_data.vehicles
64 """Tesla Fleet vehicle climate entity."""
66 _attr_precision = PRECISION_HALVES
68 _attr_temperature_unit = UnitOfTemperature.CELSIUS
69 _attr_hvac_modes = [HVACMode.HEAT_COOL, HVACMode.OFF]
70 _attr_supported_features = (
71 ClimateEntityFeature.TURN_ON
72 | ClimateEntityFeature.TURN_OFF
73 | ClimateEntityFeature.TARGET_TEMPERATURE
74 | ClimateEntityFeature.PRESET_MODE
76 _attr_preset_modes = [
"off",
"keep",
"dog",
"camp"]
77 _enable_turn_on_off_backwards_compatibility =
False
81 data: TeslaFleetVehicleData,
82 side: TeslaFleetClimateSide,
85 """Initialize the climate."""
87 self.
read_onlyread_only = Scope.VEHICLE_CMDS
not in scopes
99 """Update the attributes of the entity."""
100 value = self.
getget(
"climate_state_is_climate_on")
116 float, self.
getget(
"climate_state_min_avail_temp", DEFAULT_MIN_TEMP)
119 float, self.
getget(
"climate_state_max_avail_temp", DEFAULT_MAX_TEMP)
123 """Set the climate state to on."""
132 """Set the climate state to off."""
142 """Set the climate temperature."""
144 if ATTR_TEMPERATURE
not in kwargs:
146 translation_domain=DOMAIN,
147 translation_key=
"missing_temperature",
150 temp = kwargs[ATTR_TEMPERATURE]
160 if mode := kwargs.get(ATTR_HVAC_MODE):
167 """Set the climate mode and state."""
168 if hvac_mode
not in self.
hvac_modeshvac_modes:
170 translation_domain=DOMAIN,
171 translation_key=
"invalid_hvac_mode",
172 translation_placeholders={
"hvac_mode": hvac_mode},
174 if hvac_mode == HVACMode.OFF:
180 """Set the climate preset mode."""
196 "FanOnly": HVACMode.FAN_ONLY,
208 30: CabinOverheatProtectionTemp.LOW,
209 35: CabinOverheatProtectionTemp.MEDIUM,
210 40: CabinOverheatProtectionTemp.HIGH,
215 """Tesla Fleet vehicle cabin overheat protection entity."""
217 _attr_precision = PRECISION_WHOLE
218 _attr_target_temperature_step = 5
219 _attr_min_temp = COP_LEVELS[
"Low"]
220 _attr_max_temp = COP_LEVELS[
"High"]
221 _attr_temperature_unit = UnitOfTemperature.CELSIUS
222 _attr_hvac_modes =
list(COP_MODES.values())
223 _enable_turn_on_off_backwards_compatibility =
False
224 _attr_entity_registry_enabled_default =
False
228 data: TeslaFleetVehicleData,
231 """Initialize the cabin overheat climate entity."""
234 self.
read_onlyread_only = Scope.VEHICLE_CMDS
not in scopes
242 ClimateEntityFeature.TURN_ON | ClimateEntityFeature.TURN_OFF
245 super().
__init__(data,
"climate_state_cabin_overheat_protection")
248 """Update the attributes of the entity."""
250 if (state := self.
getget(
"climate_state_cabin_overheat_protection"))
is None:
259 if (level := self.
getget(
"climate_state_cop_activation_temperature"))
is None:
268 """Return the list of supported features."""
270 "vehicle_config_cop_user_set_temp_supported"
278 """Set the climate state to on."""
282 """Set the climate state to off."""
286 """Set the climate temperature."""
288 if ATTR_TEMPERATURE
not in kwargs:
290 translation_domain=DOMAIN,
291 translation_key=
"missing_temperature",
294 temp = kwargs[ATTR_TEMPERATURE]
295 if (cop_mode := TEMP_LEVELS.get(temp))
is None:
297 translation_domain=DOMAIN,
298 translation_key=
"invalid_cop_temp",
305 if mode := kwargs.get(ATTR_HVAC_MODE):
311 """Set the climate mode and state."""
317 if hvac_mode == HVACMode.OFF:
319 self.
apiapiapiapiapi.set_cabin_overheat_protection(on=
False, fan_only=
False)
321 elif hvac_mode == HVACMode.COOL:
323 self.
apiapiapiapiapi.set_cabin_overheat_protection(on=
True, fan_only=
False)
325 elif hvac_mode == HVACMode.FAN_ONLY:
327 self.
apiapiapiapiapi.set_cabin_overheat_protection(on=
True, fan_only=
True)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_turn_off(self)
list[HVACMode] hvac_modes(self)
None async_set_temperature(self, **Any kwargs)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None _async_update_attrs(self)
None __init__(self, TeslaFleetVehicleData data, Scope scopes)
ClimateEntityFeature supported_features(self)
None async_turn_off(self)
None _async_set_cop(self, HVACMode hvac_mode)
_attr_current_temperature
None _async_update_attrs(self)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_turn_off(self)
tuple _attr_supported_features
_attr_current_temperature
None __init__(self, TeslaFleetVehicleData data, TeslaFleetClimateSide side, Scope scopes)
None async_set_temperature(self, **Any kwargs)
None async_set_preset_mode(self, str preset_mode)
Any|None get(self, str key, Any|None default=None)
None wake_up_if_asleep(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, TeslaFleetConfigEntry entry, AddEntitiesCallback async_add_entities)
bool handle_vehicle_command(Awaitable command)