Skip to content

Commit

Permalink
Revert UUID types back to str
Browse files Browse the repository at this point in the history
  • Loading branch information
tr4nt0r committed Jan 20, 2025
1 parent e5a59cb commit 1b42f6c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 65 deletions.
71 changes: 33 additions & 38 deletions bring_api/bring.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging
import os
import time
from uuid import UUID

import aiohttp
from mashumaro.exceptions import MissingField
Expand Down Expand Up @@ -64,12 +63,12 @@ def __init__(
self.mail = mail
self.password = password

self.public_uuid: UUID | None = None
self.public_uuid: str = ""
self.user_list_settings: dict[str, dict[str, str]] = {}
self.user_locale = BRING_DEFAULT_LOCALE

self.__translations: dict[str, dict[str, str]] = {}
self.uuid: UUID | None = None
self.uuid: str = ""

self.url = URL(API_BASE_URL)

Expand Down Expand Up @@ -164,8 +163,8 @@ async def login(self) -> BringAuthResponse:

self.uuid = data.uuid
self.public_uuid = data.publicUuid
self.headers["X-BRING-USER-UUID"] = str(self.uuid)
self.headers["X-BRING-PUBLIC-USER-UUID"] = str(self.public_uuid)
self.headers["X-BRING-USER-UUID"] = self.uuid
self.headers["X-BRING-PUBLIC-USER-UUID"] = self.public_uuid
self.headers["Authorization"] = f"{data.token_type} {data.access_token}"
self.refresh_token = data.refresh_token
self.expires_in = data.expires_in
Expand Down Expand Up @@ -220,7 +219,7 @@ async def load_lists(self) -> BringListResponse:
"""
try:
url = self.url / "bringusers" / str(self.uuid) / "lists"
url = self.url / "bringusers" / self.uuid / "lists"
async with self._session.get(url, headers=self.headers) as r:
_LOGGER.debug(
"Response from %s [%s]: %s", url, r.status, await r.text()
Expand Down Expand Up @@ -262,7 +261,7 @@ async def load_lists(self) -> BringListResponse:
"Loading lists failed due to request exception."
) from e

async def get_list(self, list_uuid: UUID) -> BringItemsResponse:
async def get_list(self, list_uuid: str) -> BringItemsResponse:
"""Get all items from a shopping list.
Parameters
Expand All @@ -286,7 +285,7 @@ async def get_list(self, list_uuid: UUID) -> BringItemsResponse:
"""
try:
url = self.url / "v2/bringlists" / str(list_uuid)
url = self.url / "v2/bringlists" / list_uuid
async with self._session.get(url, headers=self.headers) as r:
_LOGGER.debug(
"Response from %s [%s]: %s", url, r.status, await r.text()
Expand Down Expand Up @@ -438,10 +437,10 @@ async def get_all_item_details(

async def save_item(
self,
list_uuid: UUID,
list_uuid: str,
item_name: str,
specification: str = "",
item_uuid: UUID | None = None,
item_uuid: str | None = None,
) -> aiohttp.ClientResponse:
"""Save an item to a shopping list.
Expand Down Expand Up @@ -469,11 +468,7 @@ async def save_item(
If the request fails.
"""
data = BringItem(
itemId=item_name,
spec=specification,
uuid=str(item_uuid) if item_uuid else None,
)
data = BringItem(itemId=item_name, spec=specification, uuid=item_uuid)
try:
return await self.batch_update_list(list_uuid, data, BringItemOperation.ADD)
except BringRequestException as e:
Expand All @@ -491,10 +486,10 @@ async def save_item(

async def update_item(
self,
list_uuid: UUID,
list_uuid: str,
item_name: str,
specification: str = "",
item_uuid: UUID | None = None,
item_uuid: str | None = None,
) -> aiohttp.ClientResponse:
"""Update an existing list item.
Expand Down Expand Up @@ -528,7 +523,7 @@ async def update_item(
data = BringItem(
itemId=item_name,
spec=specification,
uuid=str(item_uuid) if item_uuid else None,
uuid=item_uuid,
)
try:
return await self.batch_update_list(list_uuid, data, BringItemOperation.ADD)
Expand All @@ -546,7 +541,7 @@ async def update_item(
) from e

async def remove_item(
self, list_uuid: UUID, item_name: str, item_uuid: UUID | None = None
self, list_uuid: str, item_name: str, item_uuid: str | None = None
) -> aiohttp.ClientResponse:
"""Remove an item from a shopping list.
Expand Down Expand Up @@ -574,7 +569,7 @@ async def remove_item(
data = BringItem(
itemId=item_name,
spec="",
uuid=str(item_uuid) if item_uuid else None,
uuid=item_uuid,
)
try:
return await self.batch_update_list(
Expand All @@ -594,10 +589,10 @@ async def remove_item(

async def complete_item(
self,
list_uuid: UUID,
list_uuid: str,
item_name: str,
specification: str = "",
item_uuid: UUID | None = None,
item_uuid: str | None = None,
) -> aiohttp.ClientResponse:
"""Complete an item from a shopping list. This will add it to recent items.
Expand Down Expand Up @@ -628,7 +623,7 @@ async def complete_item(
data = BringItem(
itemId=item_name,
spec=specification,
uuid=str(item_uuid) if item_uuid else None,
uuid=item_uuid,
)
try:
return await self.batch_update_list(
Expand All @@ -648,7 +643,7 @@ async def complete_item(

async def notify(
self,
list_uuid: UUID,
list_uuid: str,
notification_type: BringNotificationType,
item_name: str | None = None,
) -> aiohttp.ClientResponse:
Expand Down Expand Up @@ -684,7 +679,7 @@ async def notify(
json_data = BringNotificationsConfigType(
arguments=[],
listNotificationType=notification_type.value,
senderPublicUserUuid=str(self.public_uuid),
senderPublicUserUuid=self.public_uuid,
)

if not isinstance(notification_type, BringNotificationType):
Expand All @@ -700,7 +695,7 @@ async def notify(

json_data["arguments"] = [item_name]
try:
url = self.url / "v2/bringnotifications/lists" / str(list_uuid)
url = self.url / "v2/bringnotifications/lists" / list_uuid
async with self._session.post(
url, headers=self.headers, json=json_data
) as r:
Expand Down Expand Up @@ -1018,7 +1013,7 @@ async def get_all_user_settings(self) -> BringUserSettingsResponse:
"""
try:
url = self.url / "bringusersettings" / str(self.uuid)
url = self.url / "bringusersettings" / self.uuid
async with self._session.get(url, headers=self.headers) as r:
_LOGGER.debug(
"Response from %s [%s]: %s", url, r.status, await r.text()
Expand Down Expand Up @@ -1075,7 +1070,7 @@ async def get_all_user_settings(self) -> BringUserSettingsResponse:
"Loading user settings failed due to request exception."
) from e

def __locale(self, list_uuid: UUID) -> str:
def __locale(self, list_uuid: str) -> str:
"""Get list or user locale.
Returns
Expand All @@ -1089,8 +1084,8 @@ def __locale(self, list_uuid: UUID) -> str:
If list locale could not be determined from the userlistsettings or user.
"""
if str(list_uuid) in self.user_list_settings:
return self.user_list_settings[str(list_uuid)].get(
if list_uuid in self.user_list_settings:
return self.user_list_settings[list_uuid].get(
"listArticleLanguage", self.user_locale
)
return self.user_locale
Expand Down Expand Up @@ -1146,7 +1141,7 @@ async def get_user_account(self) -> BringSyncCurrentUserResponse:
"""
try:
url = self.url / "v2/bringusers" / str(self.uuid)
url = self.url / "v2/bringusers" / self.uuid
async with self._session.get(url, headers=self.headers) as r:
_LOGGER.debug(
"Response from %s [%s]: %s", url, r.status, await r.text()
Expand Down Expand Up @@ -1194,7 +1189,7 @@ async def get_user_account(self) -> BringSyncCurrentUserResponse:

async def batch_update_list(
self,
list_uuid: UUID,
list_uuid: str,
items: BringItem | list[BringItem] | list[dict[str, str]],
operation: BringItemOperation | None = None,
) -> aiohttp.ClientResponse:
Expand Down Expand Up @@ -1255,7 +1250,7 @@ async def batch_update_list(
}

try:
url = self.url / "v2/bringlists" / str(list_uuid) / "items"
url = self.url / "v2/bringlists" / list_uuid / "items"
async with self._session.put(
url, headers=self.headers, json=json_data
) as r:
Expand Down Expand Up @@ -1388,7 +1383,7 @@ async def retrieve_new_access_token(
return data

async def set_list_article_language(
self, list_uuid: UUID, language: str
self, list_uuid: str, language: str
) -> aiohttp.ClientResponse:
"""Set the article language for a specified list.
Expand Down Expand Up @@ -1420,8 +1415,8 @@ async def set_list_article_language(
url = (
self.url
/ "bringusersettings"
/ str(self.uuid)
/ str(list_uuid)
/ self.uuid
/ list_uuid
/ "listArticleLanguage"
)

Expand Down Expand Up @@ -1461,10 +1456,10 @@ async def set_list_article_language(
"Set list article language failed due to request exception."
) from e

async def get_activity(self, list_uuid: UUID) -> BringActivityResponse:
async def get_activity(self, list_uuid: str) -> BringActivityResponse:
"""Get activity for given list."""
try:
url = self.url / "v2/bringlists" / str(list_uuid) / "activity"
url = self.url / "v2/bringlists" / list_uuid / "activity"
async with self._session.get(url, headers=self.headers) as r:
_LOGGER.debug(
"Response from %s [%s]: %s", url, r.status, await r.text()
Expand Down
26 changes: 12 additions & 14 deletions bring_api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from datetime import datetime
from enum import Enum, StrEnum
from typing import Literal, NotRequired, TypedDict
from uuid import UUID

from mashumaro.mixins.orjson import DataClassORJSONMixin

Expand All @@ -13,7 +12,7 @@
class BringList(DataClassORJSONMixin):
"""A list class. Represents a single list."""

listUuid: UUID
listUuid: str
name: str
theme: str

Expand All @@ -39,7 +38,7 @@ class Attribute(DataClassORJSONMixin):
class BringPurchase(DataClassORJSONMixin):
"""A purchase class. Represents a single item."""

uuid: UUID
uuid: str
itemId: str
specification: str
attributes: list[Attribute] = field(default_factory=list)
Expand All @@ -53,9 +52,9 @@ class BringListItemDetails(DataClassORJSONMixin):
Caution: This does not have to be an item that is currently marked as 'to buy'.
"""

uuid: UUID
uuid: str
itemId: str
listUuid: UUID
listUuid: str
userIconItemId: str
userSectionId: str
assignedTo: str
Expand All @@ -66,10 +65,9 @@ class BringListItemDetails(DataClassORJSONMixin):
class BringAuthResponse(DataClassORJSONMixin):
"""An auth response class."""

uuid: UUID
publicUuid: UUID

bringListUUID: UUID
uuid: str
publicUuid: str
bringListUUID: str
access_token: str
refresh_token: str
token_type: str
Expand Down Expand Up @@ -98,7 +96,7 @@ class Items(DataClassORJSONMixin):
class BringItemsResponse(DataClassORJSONMixin):
"""An items response class."""

uuid: UUID
uuid: str
status: str
items: Items

Expand Down Expand Up @@ -184,9 +182,9 @@ class BringSyncCurrentUserResponse(DataClassORJSONMixin):
email: str
emailVerified: bool
premiumConfiguration: dict[str, bool]
publicUserUuid: UUID
publicUserUuid: str
userLocale: UserLocale
userUuid: UUID
userUuid: str
name: str = ""
photoPath: str = ""

Expand Down Expand Up @@ -247,9 +245,9 @@ class ActivityType(StrEnum):
class ActivityContent:
"""An activity content entry."""

uuid: UUID
uuid: str
sessionDate: datetime
publicUserUuid: UUID
publicUserUuid: str
items: list[BringPurchase] = field(default_factory=list)
purchase: list[BringPurchase] = field(default_factory=list)
recently: list[BringPurchase] = field(default_factory=list)
Expand Down
Loading

0 comments on commit 1b42f6c

Please sign in to comment.