Add sunroof to Tessie (#121743)
parent
322553b8a9
commit
307ae53066
|
@ -2,14 +2,17 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from itertools import chain
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from tessie_api import (
|
from tessie_api import (
|
||||||
close_charge_port,
|
close_charge_port,
|
||||||
|
close_sunroof,
|
||||||
close_windows,
|
close_windows,
|
||||||
open_close_rear_trunk,
|
open_close_rear_trunk,
|
||||||
open_front_trunk,
|
open_front_trunk,
|
||||||
open_unlock_charge_port,
|
open_unlock_charge_port,
|
||||||
|
vent_sunroof,
|
||||||
vent_windows,
|
vent_windows,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -36,14 +39,25 @@ async def async_setup_entry(
|
||||||
data = entry.runtime_data
|
data = entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
klass(vehicle)
|
chain(
|
||||||
for klass in (
|
(
|
||||||
TessieWindowEntity,
|
klass(vehicle)
|
||||||
TessieChargePortEntity,
|
for klass in (
|
||||||
TessieFrontTrunkEntity,
|
TessieWindowEntity,
|
||||||
TessieRearTrunkEntity,
|
TessieChargePortEntity,
|
||||||
|
TessieFrontTrunkEntity,
|
||||||
|
TessieRearTrunkEntity,
|
||||||
|
)
|
||||||
|
for vehicle in data.vehicles
|
||||||
|
),
|
||||||
|
(
|
||||||
|
TessieSunroofEntity(vehicle)
|
||||||
|
for vehicle in data.vehicles
|
||||||
|
if vehicle.data_coordinator.data.get(
|
||||||
|
"vehicle_config_sun_roof_installed"
|
||||||
|
)
|
||||||
|
),
|
||||||
)
|
)
|
||||||
for vehicle in data.vehicles
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,3 +175,34 @@ class TessieRearTrunkEntity(TessieEntity, CoverEntity):
|
||||||
if self._value == TessieCoverStates.OPEN:
|
if self._value == TessieCoverStates.OPEN:
|
||||||
await self.run(open_close_rear_trunk)
|
await self.run(open_close_rear_trunk)
|
||||||
self.set((self.key, TessieCoverStates.CLOSED))
|
self.set((self.key, TessieCoverStates.CLOSED))
|
||||||
|
|
||||||
|
|
||||||
|
class TessieSunroofEntity(TessieEntity, CoverEntity):
|
||||||
|
"""Cover entity for the sunroof."""
|
||||||
|
|
||||||
|
_attr_device_class = CoverDeviceClass.WINDOW
|
||||||
|
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||||
|
|
||||||
|
def __init__(self, vehicle: TessieVehicleData) -> None:
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(vehicle, "vehicle_state_sun_roof_state")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_closed(self) -> bool | None:
|
||||||
|
"""Return if the cover is closed or not."""
|
||||||
|
return self._value == TessieCoverStates.CLOSED
|
||||||
|
|
||||||
|
@property
|
||||||
|
def current_cover_position(self) -> bool | None:
|
||||||
|
"""Return the percentage open."""
|
||||||
|
return self.get("vehicle_state_sun_roof_percent_open")
|
||||||
|
|
||||||
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Open sunroof."""
|
||||||
|
await self.run(vent_sunroof)
|
||||||
|
self.set((self.key, TessieCoverStates.OPEN))
|
||||||
|
|
||||||
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||||
|
"""Close sunroof."""
|
||||||
|
await self.run(close_sunroof)
|
||||||
|
self.set((self.key, TessieCoverStates.CLOSED))
|
||||||
|
|
|
@ -235,6 +235,9 @@
|
||||||
},
|
},
|
||||||
"vehicle_state_rt": {
|
"vehicle_state_rt": {
|
||||||
"name": "Trunk"
|
"name": "Trunk"
|
||||||
|
},
|
||||||
|
"vehicle_state_sun_roof_state": {
|
||||||
|
"name": "Sunroof"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"select": {
|
"select": {
|
||||||
|
|
|
@ -173,7 +173,7 @@
|
||||||
"roof_color": "RoofColorGlass",
|
"roof_color": "RoofColorGlass",
|
||||||
"seat_type": null,
|
"seat_type": null,
|
||||||
"spoiler_type": "None",
|
"spoiler_type": "None",
|
||||||
"sun_roof_installed": null,
|
"sun_roof_installed": true,
|
||||||
"supports_qr_pairing": false,
|
"supports_qr_pairing": false,
|
||||||
"third_row_seats": "None",
|
"third_row_seats": "None",
|
||||||
"timestamp": 1701139037461,
|
"timestamp": 1701139037461,
|
||||||
|
|
|
@ -190,7 +190,7 @@
|
||||||
"roof_color": "RoofColorGlass",
|
"roof_color": "RoofColorGlass",
|
||||||
"seat_type": null,
|
"seat_type": null,
|
||||||
"spoiler_type": "None",
|
"spoiler_type": "None",
|
||||||
"sun_roof_installed": null,
|
"sun_roof_installed": true,
|
||||||
"supports_qr_pairing": false,
|
"supports_qr_pairing": false,
|
||||||
"third_row_seats": "None",
|
"third_row_seats": "None",
|
||||||
"timestamp": 1701139037461,
|
"timestamp": 1701139037461,
|
||||||
|
|
|
@ -95,6 +95,87 @@
|
||||||
'state': 'closed',
|
'state': 'closed',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
|
# name: test_covers[cover.test_none-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_none',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.WINDOW: 'window'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'tessie',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'vehicle_state_sun_roof_state',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_sun_roof_state',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_covers[cover.test_sunroof-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'cover',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'cover.test_sunroof',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <CoverDeviceClass.WINDOW: 'window'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Sunroof',
|
||||||
|
'platform': 'tessie',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
'translation_key': 'vehicle_state_sun_roof_state',
|
||||||
|
'unique_id': 'VINVINVIN-vehicle_state_sun_roof_state',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_covers[cover.test_sunroof-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'window',
|
||||||
|
'friendly_name': 'Test Sunroof',
|
||||||
|
'supported_features': <CoverEntityFeature: 3>,
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'cover.test_sunroof',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'open',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_covers[cover.test_trunk-entry]
|
# name: test_covers[cover.test_trunk-entry]
|
||||||
EntityRegistryEntrySnapshot({
|
EntityRegistryEntrySnapshot({
|
||||||
'aliases': set({
|
'aliases': set({
|
||||||
|
|
|
@ -329,7 +329,7 @@
|
||||||
'vehicle_config_roof_color': 'RoofColorGlass',
|
'vehicle_config_roof_color': 'RoofColorGlass',
|
||||||
'vehicle_config_seat_type': None,
|
'vehicle_config_seat_type': None,
|
||||||
'vehicle_config_spoiler_type': 'None',
|
'vehicle_config_spoiler_type': 'None',
|
||||||
'vehicle_config_sun_roof_installed': None,
|
'vehicle_config_sun_roof_installed': True,
|
||||||
'vehicle_config_supports_qr_pairing': False,
|
'vehicle_config_supports_qr_pairing': False,
|
||||||
'vehicle_config_third_row_seats': 'None',
|
'vehicle_config_third_row_seats': 'None',
|
||||||
'vehicle_config_timestamp': 1701139037461,
|
'vehicle_config_timestamp': 1701139037461,
|
||||||
|
|
|
@ -42,6 +42,7 @@ async def test_covers(
|
||||||
("cover.test_charge_port_door", "open_unlock_charge_port", "close_charge_port"),
|
("cover.test_charge_port_door", "open_unlock_charge_port", "close_charge_port"),
|
||||||
("cover.test_frunk", "open_front_trunk", False),
|
("cover.test_frunk", "open_front_trunk", False),
|
||||||
("cover.test_trunk", "open_close_rear_trunk", "open_close_rear_trunk"),
|
("cover.test_trunk", "open_close_rear_trunk", "open_close_rear_trunk"),
|
||||||
|
("cover.test_sunroof", "vent_sunroof", "close_sunroof"),
|
||||||
):
|
):
|
||||||
# Test open windows
|
# Test open windows
|
||||||
if openfunc:
|
if openfunc:
|
||||||
|
|
Loading…
Reference in New Issue