Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/tessie.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ async def main():
response = await vehicle.delete_driver(id=1)
print(response)

response = await vehicle.set_roles(role="SUBSCRIPTION", account_id="555555555")
print(response)

response = await vehicle.get_fleet_telemetry_config()
print(response)

Expand Down
14 changes: 14 additions & 0 deletions tesla_fleet_api/tessie/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,20 @@ async def revoke_invitation(self, id: str | int) -> dict[str, Any]:
f"{self.vin}/invitations/{id}/revoke",
)

async def set_roles(
self,
role: str,
account_id: str | None = None,
federation_id: str | None = None,
) -> dict[str, Any]:
"""Assign the subscription or charging payer role (requires a Tesla Business account)."""
payload: dict[str, str] = {"role": role}
if account_id is not None:
payload["account_id"] = account_id
if federation_id is not None:
payload["federation_id"] = federation_id
return await self._request(Method.POST, f"{self.vin}/roles", json=payload)

# Fleet Telemetry
async def get_fleet_telemetry_config(self) -> dict[str, Any]:
"""Retrieve telemetry configuration."""
Expand Down
35 changes: 34 additions & 1 deletion tests/test_tessie_vehicle_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,40 @@ async def test_tessie_add_charge_schedule_validates_enabled_times(self) -> None:
lon=4.56,
)

async def test_tessie_add_precondition_schedule_uses_documented_parameters(self) -> None:
async def test_set_roles_uses_documented_parameters(self) -> None:
"""set_roles should send the documented JSON body with only provided fields."""

vehicle, request = self.create_vehicle()

response = await vehicle.set_roles(
role="SUBSCRIPTION",
account_id="555555555",
)

self.assertEqual(response, {"result": True})
request.assert_awaited_once_with(
Method.POST,
f"{self.VIN}/roles",
json={"role": "SUBSCRIPTION", "account_id": "555555555"},
)

async def test_set_roles_omits_unset_optional_fields(self) -> None:
"""set_roles should omit account_id/federation_id when not provided."""

vehicle, request = self.create_vehicle()

response = await vehicle.set_roles(role="CHARGING")

self.assertEqual(response, {"result": True})
request.assert_awaited_once_with(
Method.POST,
f"{self.VIN}/roles",
json={"role": "CHARGING"},
)

async def test_tessie_add_precondition_schedule_uses_documented_parameters(
self,
) -> None:
"""Precondition schedule requests should follow the Tessie schema."""

vehicle, request = self.create_vehicle()
Expand Down
Loading