Skip to content

Commit

Permalink
feat: add remote start command (#367)
Browse files Browse the repository at this point in the history
* add window control

* add tests and update authors

* tweaks after testing

* missing s in function names

* fix boolean and lat lon parameters

* window open to window close

* add remote start command

* update command response, add parameter
  • Loading branch information
InTheDaylight14 committed Nov 30, 2022
1 parent 5e7c69f commit 350f48b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
22 changes: 22 additions & 0 deletions teslajsonpy/car.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ def is_window_closed(self) -> bool:
return False
return True

@property
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."""
Expand Down Expand Up @@ -1051,3 +1056,20 @@ async def valet_mode(self, enable, pin) -> None:
else:
params = {"valet_mode": False}
self._vehicle_data["vehicle_state"].update(params)

async def remote_start(self) -> None:
"""Remote start."""
data = await self._send_command(
"REMOTE_START",
path_vars={"vehicle_id": self.id},
wake_if_asleep=True,
)

if data and data["response"]:
_LOGGER.debug("Remote start response: %s", data["response"])
result = data["response"]["result"]
reason = data["response"]["reason"]
if result is False:
_LOGGER.debug("Error calling remote start: %s", reason)
else:
self._vehicle_data["vehicle_state"].update({"remote_start": True})
13 changes: 13 additions & 0 deletions tests/unit_tests/test_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ 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"]


Expand Down Expand Up @@ -543,3 +545,14 @@ 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."""
TeslaMock(monkeypatch)
_controller = Controller(None)
await _controller.connect()
await _controller.generate_car_objects()
_car = _controller.cars[VIN]

assert await _car.remote_start() is None

0 comments on commit 350f48b

Please sign in to comment.