Skip to content

Commit

Permalink
Add ability to control ventilated seats with Tessie integration (home…
Browse files Browse the repository at this point in the history
  • Loading branch information
atinsley authored Jul 10, 2024
1 parent 417abda commit 90af40b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
9 changes: 9 additions & 0 deletions homeassistant/components/tessie/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class TessieSeatHeaterOptions(StrEnum):
HIGH = "high"


class TessieSeatCoolerOptions(StrEnum):
"""Tessie seat cooler options."""

OFF = "off"
LOW = "low"
MEDIUM = "medium"
HIGH = "high"


class TessieClimateKeeper(StrEnum):
"""Tessie Climate Keeper Modes."""

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tessie/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/tessie",
"iot_class": "cloud_polling",
"loggers": ["tessie"],
"requirements": ["tessie-api==0.0.9", "tesla-fleet-api==0.6.2"]
"requirements": ["tessie-api==0.1.1", "tesla-fleet-api==0.6.2"]
}
38 changes: 36 additions & 2 deletions homeassistant/components/tessie/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from itertools import chain

from tesla_fleet_api.const import EnergyExportMode, EnergyOperationMode
from tessie_api import set_seat_heat
from tessie_api import set_seat_cool, set_seat_heat

from homeassistant.components.select import SelectEntity
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import TessieConfigEntry
from .const import TessieSeatHeaterOptions
from .const import TessieSeatCoolerOptions, TessieSeatHeaterOptions
from .entity import TessieEnergyEntity, TessieEntity
from .helpers import handle_command
from .models import TessieEnergyData
Expand All @@ -27,6 +27,11 @@
"climate_state_seat_heater_third_row_right": "third_row_right",
}

SEAT_COOLERS = {
"climate_state_seat_fan_front_left": "front_left",
"climate_state_seat_fan_front_right": "front_right",
}


async def async_setup_entry(
hass: HomeAssistant,
Expand All @@ -44,6 +49,13 @@ async def async_setup_entry(
if key
in vehicle.data_coordinator.data # not all vehicles have rear center or third row
),
(
TessieSeatCoolerSelectEntity(vehicle, key)
for vehicle in entry.runtime_data.vehicles
for key in SEAT_COOLERS
if key
in vehicle.data_coordinator.data # not all vehicles have ventilated seats
),
(
TessieOperationSelectEntity(energysite)
for energysite in entry.runtime_data.energysites
Expand Down Expand Up @@ -81,6 +93,28 @@ async def async_select_option(self, option: str) -> None:
self.set((self.key, level))


class TessieSeatCoolerSelectEntity(TessieEntity, SelectEntity):
"""Select entity for cooled seat."""

_attr_options = [
TessieSeatCoolerOptions.OFF,
TessieSeatCoolerOptions.LOW,
TessieSeatCoolerOptions.MEDIUM,
TessieSeatCoolerOptions.HIGH,
]

@property
def current_option(self) -> str | None:
"""Return the current selected option."""
return self._attr_options[self._value]

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
level = self._attr_options.index(option)
await self.run(set_seat_cool, seat=SEAT_COOLERS[self.key], level=level)
self.set((self.key, level))


class TessieOperationSelectEntity(TessieEnergyEntity, SelectEntity):
"""Select entity for operation mode select entities."""

Expand Down
18 changes: 18 additions & 0 deletions homeassistant/components/tessie/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@
"high": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::high%]"
}
},
"climate_state_seat_fan_front_left": {
"name": "Seat cooler left",
"state": {
"off": "[%key:common::state::off%]",
"low": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::low%]",
"medium": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::medium%]",
"high": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::high%]"
}
},
"climate_state_seat_fan_front_right": {
"name": "Seat cooler right",
"state": {
"off": "[%key:common::state::off%]",
"low": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::low%]",
"medium": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::medium%]",
"high": "[%key:component::tessie::entity::select::climate_state_seat_heater_left::state::high%]"
}
},
"components_customer_preferred_export_rule": {
"name": "Allow export",
"state": {
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,7 @@ tesla-powerwall==0.5.2
tesla-wall-connector==1.0.2

# homeassistant.components.tessie
tessie-api==0.0.9
tessie-api==0.1.1

# homeassistant.components.tensorflow
# tf-models-official==2.5.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ tesla-powerwall==0.5.2
tesla-wall-connector==1.0.2

# homeassistant.components.tessie
tessie-api==0.0.9
tessie-api==0.1.1

# homeassistant.components.thermobeacon
thermobeacon-ble==0.7.0
Expand Down

0 comments on commit 90af40b

Please sign in to comment.