Skip to content

Commit

Permalink
Add user route
Browse files Browse the repository at this point in the history
  • Loading branch information
Prior99 committed Sep 16, 2024
1 parent 802c32d commit 0eeaaf4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions myskoda/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,20 @@ async def driving_range(ctx: Context, vin: str) -> None:
)


@cli.command()
@click.pass_context
async def user(ctx: Context) -> None:
"""Print information about currently logged in user."""
async with ClientSession() as session:
hub = RestApi(session)
await hub.authenticate(ctx.obj["username"], ctx.obj["password"])
user = await hub.get_user()

print(f"{colored("id:", "blue")} {user.id}")
print(f"{colored("name:", "blue")} {user.first_name} {user.last_name}")
print(f"{colored("email:", "blue")} {user.email}")


@cli.command()
@click.argument("vin")
@click.pass_context
Expand Down
1 change: 0 additions & 1 deletion myskoda/models/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from datetime import date
from enum import StrEnum
from typing import Any

from pydantic import BaseModel, Field

Expand Down
10 changes: 10 additions & 0 deletions myskoda/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .models.position import Positions, PositionType
from .models.status import Status
from .models.trip_statistics import TripStatistics
from .models.user import User

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -147,6 +148,15 @@ async def get_health(self, vin: str) -> Health:
_LOGGER.debug("vin %s: Received health")
return Health(**await response.json())

async def get_user(self) -> User:
"""Retrieve user information about logged in user."""
async with self.session.get(
f"{BASE_URL_SKODA}/api/v1/users",
headers=await self._headers(),
) as response:
_LOGGER.debug("vin %s: Received user")
return User(**await response.json())

async def list_vehicles(self) -> list[str]:
"""List all vehicles by their vins."""
async with self.session.get(
Expand Down

0 comments on commit 0eeaaf4

Please sign in to comment.