Skip to content

Commit

Permalink
feat: add auto seat climate command and properties (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
InTheDaylight14 committed Dec 2, 2022
1 parent e190c5c commit 21c5ff3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
38 changes: 36 additions & 2 deletions teslajsonpy/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,24 @@ def is_window_closed(self) -> bool:
def is_remote_start(self) -> bool:
"""Return if remote start active."""
return self._vehicle_data.get("vehicle_state", {}).get("remote_start")

@property
def is_valet_mode(self) -> bool:
"""Return state of valet mode."""
return self._vehicle_data.get("vehicle_state", {}).get("valet_mode")

@property
def is_auto_seat_climate_left(self) -> bool:
"""Return state of valet mode."""
return self._vehicle_data.get("climate_state", {}).get("auto_seat_climate_left")

@property
def is_auto_seat_climate_right(self) -> bool:
"""Return state of valet mode."""
return self._vehicle_data.get("climate_state", {}).get(
"auto_seat_climate_right"
)

async def _send_command(
self, name: str, *, path_vars: dict, wake_if_asleep: bool = False, **kwargs
) -> dict:
Expand Down Expand Up @@ -780,6 +792,28 @@ async def set_climate_keeper_mode(self, keeper_id: int) -> None:
}
self._vehicle_data["climate_state"].update(params)

async def remote_auto_seat_climate_request(
self, seat_id: int, enable: bool
) -> None:
"""Send command to change seat climate to auto.
Args
seat_id: 0 (front left), 1 (front right)
enable: 'True' to enable, 'False' to diable
"""

data = await self._send_command(
"REMOTE_AUTO_SEAT_CLIMATE_REQUEST",
path_vars={"vehicle_id": self.id},
auto_seat_position=seat_id,
auto_climate_on=enable,
wake_if_asleep=True,
)
if data and data["response"]["result"] is True:
params = {f"auto_seat_climate_{SEAT_ID_MAP[seat_id]}": enable}
self._vehicle_data["climate_state"].update(params)

async def set_heated_steering_wheel(self, value: bool) -> None:
"""Send command to set heated steering wheel."""
data = await self._send_command(
Expand Down Expand Up @@ -1072,4 +1106,4 @@ async def remote_start(self) -> None:
if result is False:
_LOGGER.debug("Error calling remote start: %s", reason)
else:
self._vehicle_data["vehicle_state"].update({"remote_start": True})
self._vehicle_data["vehicle_state"].update({"remote_start": True})
4 changes: 3 additions & 1 deletion tests/tesla_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def command_ok():
"use_range_badging": False,
"utc_offset": -25200,
"wheel_type": "Base19",
}
},
},
{
"energy_site_id": 12345,
Expand Down Expand Up @@ -470,6 +470,8 @@ def command_ok():
},
"climate_state": {
"allow_cabin_overheat_protection": True,
"auto_seat_climate_left": True,
"auto_seat_climate_right": True,
"battery_heater": False,
"battery_heater_no_power": False,
"cabin_overheat_protection": "Off",
Expand Down
39 changes: 37 additions & 2 deletions tests/unit_tests/test_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,19 @@ async def test_car_properties(monkeypatch):
assert _car.window_rp == VEHICLE_DATA["vehicle_state"]["rp_window"]

assert _car.is_remote_start == VEHICLE_DATA["vehicle_state"]["remote_start"]

assert _car.is_valet_mode == VEHICLE_DATA["vehicle_state"]["valet_mode"]

assert (
_car.is_auto_seat_climate_left
== VEHICLE_DATA["climate_state"]["auto_seat_climate_left"]
)

assert (
_car.is_auto_seat_climate_right
== VEHICLE_DATA["climate_state"]["auto_seat_climate_right"]
)


@pytest.mark.asyncio
async def test_change_charge_limit(monkeypatch):
Expand Down Expand Up @@ -376,6 +386,30 @@ async def test_set_climate_keeper_mode(monkeypatch):
assert await _car.set_climate_keeper_mode(1) is None


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

assert await _car.remote_auto_seat_climate_request(1, False) is None


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

assert await _car.remote_auto_seat_climate_request(0, True) is None


@pytest.mark.asyncio
async def test_set_heated_steering_wheel(monkeypatch):
"""Test setting heated steering wheel."""
Expand Down Expand Up @@ -546,6 +580,7 @@ async def test_valet_mode(monkeypatch):
assert await _car.valet_mode(True, "0000") is None
assert await _car.valet_mode(False, "0000") is None


@pytest.mark.asyncio
async def test_remote_start(monkeypatch):
"""Test remote start."""
Expand All @@ -555,4 +590,4 @@ async def test_remote_start(monkeypatch):
await _controller.generate_car_objects()
_car = _controller.cars[VIN]

assert await _car.remote_start() is None
assert await _car.remote_start() is None

0 comments on commit 21c5ff3

Please sign in to comment.