1 """Cover platform for Tesla Fleet integration."""
3 from __future__
import annotations
7 from tesla_fleet_api.const
import Scope, SunRoofCommand, Trunk, WindowCommand
17 from .
import TeslaFleetConfigEntry
18 from .entity
import TeslaFleetVehicleEntity
19 from .helpers
import handle_vehicle_command
20 from .models
import TeslaFleetVehicleData
30 entry: TeslaFleetConfigEntry,
31 async_add_entities: AddEntitiesCallback,
33 """Set up the TeslaFleet cover platform from a config entry."""
36 klass(vehicle, entry.runtime_data.scopes)
38 TeslaFleetWindowEntity,
39 TeslaFleetChargePortEntity,
40 TeslaFleetFrontTrunkEntity,
41 TeslaFleetRearTrunkEntity,
42 TeslaFleetSunroofEntity,
44 for vehicle
in entry.runtime_data.vehicles
49 """Cover entity for the windows."""
51 _attr_device_class = CoverDeviceClass.WINDOW
53 def __init__(self, data: TeslaFleetVehicleData, scopes: list[Scope]) ->
None:
54 """Initialize the cover."""
56 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
58 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
64 """Update the entity attributes."""
65 fd = self.
getget(
"vehicle_state_fd_window")
66 fp = self.
getget(
"vehicle_state_fp_window")
67 rd = self.
getget(
"vehicle_state_rd_window")
68 rp = self.
getget(
"vehicle_state_rp_window")
71 if OPEN
in (fd, fp, rd, rp):
74 elif CLOSED == fd == fp == rd == rp:
84 self.
apiapiapiapiapi.window_control(command=WindowCommand.VENT)
93 self.
apiapiapiapiapi.window_control(command=WindowCommand.CLOSE)
100 """Cover entity for the charge port."""
102 _attr_device_class = CoverDeviceClass.DOOR
104 def __init__(self, vehicle: TeslaFleetVehicleData, scopes: list[Scope]) ->
None:
105 """Initialize the cover."""
106 super().
__init__(vehicle,
"charge_state_charge_port_door_open")
109 for scope
in (Scope.VEHICLE_CMDS, Scope.VEHICLE_CHARGING_CMDS)
112 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
118 """Update the entity attributes."""
122 """Open charge port."""
129 """Close charge port."""
137 """Cover entity for the front trunk."""
139 _attr_device_class = CoverDeviceClass.DOOR
141 def __init__(self, vehicle: TeslaFleetVehicleData, scopes: list[Scope]) ->
None:
142 """Initialize the cover."""
143 super().
__init__(vehicle,
"vehicle_state_ft")
145 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
151 """Update the entity attributes."""
155 """Open front trunk."""
163 """Cover entity for the rear trunk."""
165 _attr_device_class = CoverDeviceClass.DOOR
167 def __init__(self, vehicle: TeslaFleetVehicleData, scopes: list[Scope]) ->
None:
168 """Initialize the cover."""
169 super().
__init__(vehicle,
"vehicle_state_rt")
171 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
173 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
179 """Update the entity attributes."""
183 """Open rear trunk."""
191 """Close rear trunk."""
200 """Cover entity for the sunroof."""
202 _attr_device_class = CoverDeviceClass.WINDOW
203 _attr_supported_features = (
204 CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
206 _attr_entity_registry_enabled_default =
False
208 def __init__(self, vehicle: TeslaFleetVehicleData, scopes: list[Scope]) ->
None:
209 """Initialize the sensor."""
210 super().
__init__(vehicle,
"vehicle_state_sun_roof_state")
212 self.
scopedscoped = Scope.VEHICLE_CMDS
in scopes
217 """Update the entity attributes."""
219 if value
in (
None,
"unknown"):
225 "vehicle_state_sun_roof_percent_open"
bool|None is_closed(self)
None _async_update_attrs(self)
None async_close_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None __init__(self, TeslaFleetVehicleData vehicle, list[Scope] scopes)
None __init__(self, TeslaFleetVehicleData vehicle, list[Scope] scopes)
None async_open_cover(self, **Any kwargs)
None _async_update_attrs(self)
None async_open_cover(self, **Any kwargs)
None async_close_cover(self, **Any kwargs)
None __init__(self, TeslaFleetVehicleData vehicle, list[Scope] scopes)
None _async_update_attrs(self)
None __init__(self, TeslaFleetVehicleData vehicle, list[Scope] scopes)
None async_stop_cover(self, **Any kwargs)
_attr_current_cover_position
tuple _attr_supported_features
None _async_update_attrs(self)
None async_close_cover(self, **Any kwargs)
None async_open_cover(self, **Any kwargs)
None __init__(self, TeslaFleetVehicleData data, list[Scope] scopes)
None async_close_cover(self, **Any kwargs)
None _async_update_attrs(self)
None async_open_cover(self, **Any kwargs)
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)