1 """Switch platform for Tessie integration."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
7 from itertools
import chain
10 from tessie_api
import (
17 start_steering_wheel_heater,
20 stop_steering_wheel_heater,
26 SwitchEntityDescription,
31 from .
import TessieConfigEntry
32 from .entity
import TessieEnergyEntity, TessieEntity
33 from .helpers
import handle_command
34 from .models
import TessieEnergyData, TessieVehicleData
37 @dataclass(frozen=True, kw_only=True)
39 """Describes Tessie Switch entity."""
45 DESCRIPTIONS: tuple[TessieSwitchEntityDescription, ...] = (
47 key=
"climate_state_defrost_mode",
48 on_func=
lambda: start_defrost,
49 off_func=
lambda: stop_defrost,
52 key=
"vehicle_state_sentry_mode",
53 on_func=
lambda: enable_sentry_mode,
54 off_func=
lambda: disable_sentry_mode,
57 key=
"vehicle_state_valet_mode",
58 on_func=
lambda: enable_valet_mode,
59 off_func=
lambda: disable_valet_mode,
62 key=
"climate_state_steering_wheel_heater",
63 on_func=
lambda: start_steering_wheel_heater,
64 off_func=
lambda: stop_steering_wheel_heater,
69 key=
"charge_state_charge_enable_request",
70 on_func=
lambda: start_charging,
71 off_func=
lambda: stop_charging,
79 entry: TessieConfigEntry,
80 async_add_entities: AddEntitiesCallback,
82 """Set up the Tessie Switch platform from a config entry."""
88 for vehicle
in entry.runtime_data.vehicles
89 for description
in DESCRIPTIONS
90 if description.key
in vehicle.data_coordinator.data
94 for vehicle
in entry.runtime_data.vehicles
98 for energysite
in entry.runtime_data.energysites
99 if energysite.info_coordinator.data.get(
"components_battery")
100 and energysite.info_coordinator.data.get(
"components_solar")
104 for energysite
in entry.runtime_data.energysites
105 if energysite.info_coordinator.data.get(
"components_storm_mode_capable")
112 """Base class for Tessie Switch."""
114 _attr_device_class = SwitchDeviceClass.SWITCH
115 entity_description: TessieSwitchEntityDescription
119 vehicle: TessieVehicleData,
120 description: TessieSwitchEntityDescription,
122 """Initialize the Switch."""
123 super().
__init__(vehicle, description.key)
128 """Return the state of the Switch."""
132 """Turn on the Switch."""
137 """Turn off the Switch."""
143 """Entity class for Tessie charge switch."""
147 """Return the state of the Switch."""
149 if (charge := self.
getget(
"charge_state_user_charge_enable_request"))
is not None:
155 """Entity class for Charge From Grid switch."""
159 data: TessieEnergyData,
161 """Initialize the switch."""
164 data.info_coordinator,
165 "components_disallow_charge_from_grid_with_solar_installed",
169 """Update the attributes of the entity."""
175 """Turn on the Switch."""
178 disallow_charge_from_grid_with_solar_installed=
False
185 """Turn off the Switch."""
188 disallow_charge_from_grid_with_solar_installed=
True
196 """Entity class for Storm Mode switch."""
200 data: TessieEnergyData,
202 """Initialize the switch."""
204 data, data.info_coordinator,
"user_settings_storm_mode_enabled"
208 """Update the attributes of the sensor."""
213 """Turn on the Switch."""
219 """Turn off the Switch."""
Any get(self, str|None key=None, Any|None default=None)
None set(self, *Any args)
None run(self, Callable[..., Awaitable[dict[str, Any]]] func, **Any kargs)
None async_turn_off(self, **Any kwargs)
None _async_update_attrs(self)
None __init__(self, TessieEnergyData data)
None async_turn_on(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None __init__(self, TessieEnergyData data)
None _async_update_attrs(self)
None async_turn_off(self, **Any kwargs)
None __init__(self, TessieVehicleData vehicle, TessieSwitchEntityDescription description)
None async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
dict[str, Any] handle_command(Awaitable command)
None async_setup_entry(HomeAssistant hass, TessieConfigEntry entry, AddEntitiesCallback async_add_entities)