Skip to content

Commit

Permalink
Merge pull request #472 from zabuldon/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jun 6, 2024
2 parents 89d8e89 + d4fe98b commit 39af0fc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
35 changes: 34 additions & 1 deletion teslajsonpy/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ def rear_seat_heaters(self) -> int:
"""
return self._vehicle_data.get("vehicle_config", {}).get("rear_seat_heaters")

@property
def has_seat_cooling(self) -> bool:
"""Return if car has cooled seats."""
return self._vehicle_data.get("vehicle_config", {}).get("has_seat_cooling")

@property
def sentry_mode(self) -> bool:
"""Return sentry mode."""
Expand Down Expand Up @@ -874,7 +879,7 @@ async def remote_seat_heater_request(self, level: int, seat_id: int) -> None:
wake_if_asleep = level > 0
data = await self._send_command(
"REMOTE_SEAT_HEATER_REQUEST",
heater=seat_id,
seat_position=seat_id,
level=level,
wake_if_asleep=wake_if_asleep,
)
Expand All @@ -888,6 +893,33 @@ def get_seat_heater_status(self, seat_id: int) -> int:
if self.data_available:
return self._vehicle_data.get("climate_state", {}).get(seat_id)
return None

async def remote_seat_cooler_request(self, level: int, seat_id: int) -> None:
"""Send command to change seat cooler.
Args
level: 1 (off), 2 (low), 3 (medium), 4 (high)
seat_id: 1 (front left), 2 (front right)
"""
# If car is asleep the cooler is already off
wake_if_asleep = level > 1
data = await self._send_command(
"REMOTE_SEAT_COOLING_REQUEST",
seat_position=seat_id,
seat_cooler_level=level,
wake_if_asleep=wake_if_asleep,
)
if data and data["response"]["result"] is True:
params = {f"seat_fan_front_{SEAT_ID_MAP[seat_id]}": level}
self._vehicle_data["climate_state"].update(params)

def get_seat_cooler_status(self, seat_id: int) -> int:
"""Return status of seat heater for a given seat."""
seat_id = f"seat_fan_front_{SEAT_ID_MAP[seat_id]}"
if self.data_available:
return self._vehicle_data.get("climate_state", {}).get(seat_id)
return None

async def schedule_software_update(self, offset_sec: Optional[int] = 0) -> None:
"""Send command to install software update."""
Expand Down Expand Up @@ -995,6 +1027,7 @@ async def remote_auto_seat_climate_request(
data = await self._send_command(
"REMOTE_AUTO_SEAT_CLIMATE_REQUEST",
auto_seat_position=seat_id,
seat_position=seat_id,
auto_climate_on=enable,
)
if data and data["response"]["result"] is True:
Expand Down
3 changes: 3 additions & 0 deletions tests/tesla_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ def command_ok():
"right_temp_direction": -309,
"seat_heater_left": 0,
"seat_heater_right": 0,
"seat_heater_rear_center": 0,
"seat_heater_rear_left": 0,
"seat_heater_rear_right": 0,
"side_mirror_heaters": False,
"steering_wheel_heat_level": 1,
"steering_wheel_heater": True,
Expand Down
12 changes: 12 additions & 0 deletions tests/unit_tests/test_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,18 @@ async def test_remote_seat_heater_request(monkeypatch):
assert await _car.remote_seat_heater_request(3, 1) is None


@pytest.mark.asyncio
async def test_remote_seat_cooler_request(monkeypatch):
"""Test remote seat cooler request."""
TeslaMock(monkeypatch)
_controller = Controller(None)
await _controller.connect()
await _controller.generate_car_objects()
_car = _controller.cars[VIN]

assert await _car.remote_seat_cooler_request(1, 2) is None


@pytest.mark.asyncio
async def test_schedule_software_update(monkeypatch):
"""Test scheduling software update."""
Expand Down

0 comments on commit 39af0fc

Please sign in to comment.