1 """Climate platform for Teslemetry 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 TeslemetryConfigEntry
27 from .const
import DOMAIN, TeslemetryClimateSide
28 from .entity
import TeslemetryVehicleEntity
29 from .helpers
import handle_vehicle_command
30 from .models
import TeslemetryVehicleData
40 entry: TeslemetryConfigEntry,
41 async_add_entities: AddEntitiesCallback,
43 """Set up the Teslemetry Climate platform from a config entry."""
49 vehicle, TeslemetryClimateSide.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 """Telemetry 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: TeslemetryVehicleData,
82 side: TeslemetryClimateSide,
85 """Initialize the climate."""
86 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
98 """Update the attributes of the entity."""
99 value = self.
getget(
"climate_state_is_climate_on")
115 float, self.
getget(
"climate_state_min_avail_temp", DEFAULT_MIN_TEMP)
118 float, self.
getget(
"climate_state_max_avail_temp", DEFAULT_MAX_TEMP)
122 """Set the climate state to on."""
132 """Set the climate state to off."""
143 """Set the climate temperature."""
144 if temp := kwargs.get(ATTR_TEMPERATURE):
154 if mode := kwargs.get(ATTR_HVAC_MODE):
161 """Set the climate mode and state."""
162 if hvac_mode == HVACMode.OFF:
168 """Set the climate preset mode."""
185 "FanOnly": HVACMode.FAN_ONLY,
197 30: CabinOverheatProtectionTemp.LOW,
198 35: CabinOverheatProtectionTemp.MEDIUM,
199 40: CabinOverheatProtectionTemp.HIGH,
204 """Telemetry vehicle cabin overheat protection entity."""
206 _attr_precision = PRECISION_WHOLE
207 _attr_target_temperature_step = 5
208 _attr_min_temp = COP_LEVELS[
"Low"]
209 _attr_max_temp = COP_LEVELS[
"High"]
210 _attr_temperature_unit = UnitOfTemperature.CELSIUS
211 _attr_hvac_modes =
list(COP_MODES.values())
212 _enable_turn_on_off_backwards_compatibility =
False
213 _attr_entity_registry_enabled_default =
False
217 data: TeslemetryVehicleData,
220 """Initialize the climate."""
222 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
225 ClimateEntityFeature.TURN_ON | ClimateEntityFeature.TURN_OFF
231 super().
__init__(data,
"climate_state_cabin_overheat_protection")
234 if self.
scopedscoped
and self.
getget(
"vehicle_config_cop_user_set_temp_supported"):
238 """Update the attributes of the entity."""
240 if (state := self.
getget(
"climate_state_cabin_overheat_protection"))
is None:
249 if (level := self.
getget(
"climate_state_cop_activation_temperature"))
is None:
257 """Set the climate state to on."""
261 """Set the climate state to off."""
265 """Set the climate temperature."""
268 if (temp := kwargs.get(ATTR_TEMPERATURE))
is None or (
269 cop_mode := TEMP_LEVELS.get(temp)
272 translation_domain=DOMAIN,
273 translation_key=
"invalid_cop_temp",
280 if mode := kwargs.get(ATTR_HVAC_MODE):
286 if hvac_mode == HVACMode.OFF:
288 self.
apiapiapiapiapiapi.set_cabin_overheat_protection(on=
False, fan_only=
False)
290 elif hvac_mode == HVACMode.COOL:
292 self.
apiapiapiapiapiapi.set_cabin_overheat_protection(on=
True, fan_only=
False)
294 elif hvac_mode == HVACMode.FAN_ONLY:
296 self.
apiapiapiapiapiapi.set_cabin_overheat_protection(on=
True, fan_only=
True)
302 """Set the climate mode and state."""
None async_set_hvac_mode(self, HVACMode hvac_mode)
None async_turn_off(self)
None async_turn_off(self)
_attr_current_temperature
None async_set_temperature(self, **Any kwargs)
None _async_update_attrs(self)
None __init__(self, TeslemetryVehicleData data, Scope scopes)
None async_set_hvac_mode(self, HVACMode hvac_mode)
None _async_set_cop(self, HVACMode hvac_mode)
None async_set_temperature(self, **Any kwargs)
tuple _attr_supported_features
_attr_current_temperature
None _async_update_attrs(self)
None async_turn_off(self)
None __init__(self, TeslemetryVehicleData data, TeslemetryClimateSide side, Scope scopes)
None async_set_preset_mode(self, str preset_mode)
None async_set_hvac_mode(self, HVACMode hvac_mode)
def raise_for_scope(self, Scope scope)
Any|None get(self, str key, Any|None default=None)
None wake_up_if_asleep(self)
None async_write_ha_state(self)
bool handle_vehicle_command(Awaitable command)
None async_setup_entry(HomeAssistant hass, TeslemetryConfigEntry entry, AddEntitiesCallback async_add_entities)