Skip to content

Commit 6ea7610

Browse files
committed
Revert UUID types back to str (#126)
1 parent 9f480b1 commit 6ea7610

File tree

4 files changed

+57
-65
lines changed

4 files changed

+57
-65
lines changed

bring_api/bring.py

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import logging
99
import os
1010
import time
11-
from uuid import UUID
1211

1312
import aiohttp
1413
from mashumaro.exceptions import MissingField
@@ -64,12 +63,12 @@ def __init__(
6463
self.mail = mail
6564
self.password = password
6665

67-
self.public_uuid: UUID | None = None
66+
self.public_uuid: str = ""
6867
self.user_list_settings: dict[str, dict[str, str]] = {}
6968
self.user_locale = BRING_DEFAULT_LOCALE
7069

7170
self.__translations: dict[str, dict[str, str]] = {}
72-
self.uuid: UUID | None = None
71+
self.uuid: str = ""
7372

7473
self.url = URL(API_BASE_URL)
7574

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

165164
self.uuid = data.uuid
166165
self.public_uuid = data.publicUuid
167-
self.headers["X-BRING-USER-UUID"] = str(self.uuid)
168-
self.headers["X-BRING-PUBLIC-USER-UUID"] = str(self.public_uuid)
166+
self.headers["X-BRING-USER-UUID"] = self.uuid
167+
self.headers["X-BRING-PUBLIC-USER-UUID"] = self.public_uuid
169168
self.headers["Authorization"] = f"{data.token_type} {data.access_token}"
170169
self.refresh_token = data.refresh_token
171170
self.expires_in = data.expires_in
@@ -220,7 +219,7 @@ async def load_lists(self) -> BringListResponse:
220219
221220
"""
222221
try:
223-
url = self.url / "bringusers" / str(self.uuid) / "lists"
222+
url = self.url / "bringusers" / self.uuid / "lists"
224223
async with self._session.get(url, headers=self.headers) as r:
225224
_LOGGER.debug(
226225
"Response from %s [%s]: %s", url, r.status, await r.text()
@@ -262,7 +261,7 @@ async def load_lists(self) -> BringListResponse:
262261
"Loading lists failed due to request exception."
263262
) from e
264263

265-
async def get_list(self, list_uuid: UUID) -> BringItemsResponse:
264+
async def get_list(self, list_uuid: str) -> BringItemsResponse:
266265
"""Get all items from a shopping list.
267266
268267
Parameters
@@ -286,7 +285,7 @@ async def get_list(self, list_uuid: UUID) -> BringItemsResponse:
286285
287286
"""
288287
try:
289-
url = self.url / "v2/bringlists" / str(list_uuid)
288+
url = self.url / "v2/bringlists" / list_uuid
290289
async with self._session.get(url, headers=self.headers) as r:
291290
_LOGGER.debug(
292291
"Response from %s [%s]: %s", url, r.status, await r.text()
@@ -438,10 +437,10 @@ async def get_all_item_details(
438437

439438
async def save_item(
440439
self,
441-
list_uuid: UUID,
440+
list_uuid: str,
442441
item_name: str,
443442
specification: str = "",
444-
item_uuid: UUID | None = None,
443+
item_uuid: str | None = None,
445444
) -> aiohttp.ClientResponse:
446445
"""Save an item to a shopping list.
447446
@@ -469,11 +468,7 @@ async def save_item(
469468
If the request fails.
470469
471470
"""
472-
data = BringItem(
473-
itemId=item_name,
474-
spec=specification,
475-
uuid=str(item_uuid) if item_uuid else None,
476-
)
471+
data = BringItem(itemId=item_name, spec=specification, uuid=item_uuid)
477472
try:
478473
return await self.batch_update_list(list_uuid, data, BringItemOperation.ADD)
479474
except BringRequestException as e:
@@ -491,10 +486,10 @@ async def save_item(
491486

492487
async def update_item(
493488
self,
494-
list_uuid: UUID,
489+
list_uuid: str,
495490
item_name: str,
496491
specification: str = "",
497-
item_uuid: UUID | None = None,
492+
item_uuid: str | None = None,
498493
) -> aiohttp.ClientResponse:
499494
"""Update an existing list item.
500495
@@ -528,7 +523,7 @@ async def update_item(
528523
data = BringItem(
529524
itemId=item_name,
530525
spec=specification,
531-
uuid=str(item_uuid) if item_uuid else None,
526+
uuid=item_uuid,
532527
)
533528
try:
534529
return await self.batch_update_list(list_uuid, data, BringItemOperation.ADD)
@@ -546,7 +541,7 @@ async def update_item(
546541
) from e
547542

548543
async def remove_item(
549-
self, list_uuid: UUID, item_name: str, item_uuid: UUID | None = None
544+
self, list_uuid: str, item_name: str, item_uuid: str | None = None
550545
) -> aiohttp.ClientResponse:
551546
"""Remove an item from a shopping list.
552547
@@ -574,7 +569,7 @@ async def remove_item(
574569
data = BringItem(
575570
itemId=item_name,
576571
spec="",
577-
uuid=str(item_uuid) if item_uuid else None,
572+
uuid=item_uuid,
578573
)
579574
try:
580575
return await self.batch_update_list(
@@ -594,10 +589,10 @@ async def remove_item(
594589

595590
async def complete_item(
596591
self,
597-
list_uuid: UUID,
592+
list_uuid: str,
598593
item_name: str,
599594
specification: str = "",
600-
item_uuid: UUID | None = None,
595+
item_uuid: str | None = None,
601596
) -> aiohttp.ClientResponse:
602597
"""Complete an item from a shopping list. This will add it to recent items.
603598
@@ -628,7 +623,7 @@ async def complete_item(
628623
data = BringItem(
629624
itemId=item_name,
630625
spec=specification,
631-
uuid=str(item_uuid) if item_uuid else None,
626+
uuid=item_uuid,
632627
)
633628
try:
634629
return await self.batch_update_list(
@@ -648,7 +643,7 @@ async def complete_item(
648643

649644
async def notify(
650645
self,
651-
list_uuid: UUID,
646+
list_uuid: str,
652647
notification_type: BringNotificationType,
653648
item_name: str | None = None,
654649
) -> aiohttp.ClientResponse:
@@ -684,7 +679,7 @@ async def notify(
684679
json_data = BringNotificationsConfigType(
685680
arguments=[],
686681
listNotificationType=notification_type.value,
687-
senderPublicUserUuid=str(self.public_uuid),
682+
senderPublicUserUuid=self.public_uuid,
688683
)
689684

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

701696
json_data["arguments"] = [item_name]
702697
try:
703-
url = self.url / "v2/bringnotifications/lists" / str(list_uuid)
698+
url = self.url / "v2/bringnotifications/lists" / list_uuid
704699
async with self._session.post(
705700
url, headers=self.headers, json=json_data
706701
) as r:
@@ -1018,7 +1013,7 @@ async def get_all_user_settings(self) -> BringUserSettingsResponse:
10181013
10191014
"""
10201015
try:
1021-
url = self.url / "bringusersettings" / str(self.uuid)
1016+
url = self.url / "bringusersettings" / self.uuid
10221017
async with self._session.get(url, headers=self.headers) as r:
10231018
_LOGGER.debug(
10241019
"Response from %s [%s]: %s", url, r.status, await r.text()
@@ -1075,7 +1070,7 @@ async def get_all_user_settings(self) -> BringUserSettingsResponse:
10751070
"Loading user settings failed due to request exception."
10761071
) from e
10771072

1078-
def __locale(self, list_uuid: UUID) -> str:
1073+
def __locale(self, list_uuid: str) -> str:
10791074
"""Get list or user locale.
10801075
10811076
Returns
@@ -1089,8 +1084,8 @@ def __locale(self, list_uuid: UUID) -> str:
10891084
If list locale could not be determined from the userlistsettings or user.
10901085
10911086
"""
1092-
if str(list_uuid) in self.user_list_settings:
1093-
return self.user_list_settings[str(list_uuid)].get(
1087+
if list_uuid in self.user_list_settings:
1088+
return self.user_list_settings[list_uuid].get(
10941089
"listArticleLanguage", self.user_locale
10951090
)
10961091
return self.user_locale
@@ -1146,7 +1141,7 @@ async def get_user_account(self) -> BringSyncCurrentUserResponse:
11461141
11471142
"""
11481143
try:
1149-
url = self.url / "v2/bringusers" / str(self.uuid)
1144+
url = self.url / "v2/bringusers" / self.uuid
11501145
async with self._session.get(url, headers=self.headers) as r:
11511146
_LOGGER.debug(
11521147
"Response from %s [%s]: %s", url, r.status, await r.text()
@@ -1194,7 +1189,7 @@ async def get_user_account(self) -> BringSyncCurrentUserResponse:
11941189

11951190
async def batch_update_list(
11961191
self,
1197-
list_uuid: UUID,
1192+
list_uuid: str,
11981193
items: BringItem | list[BringItem] | list[dict[str, str]],
11991194
operation: BringItemOperation | None = None,
12001195
) -> aiohttp.ClientResponse:
@@ -1255,7 +1250,7 @@ async def batch_update_list(
12551250
}
12561251

12571252
try:
1258-
url = self.url / "v2/bringlists" / str(list_uuid) / "items"
1253+
url = self.url / "v2/bringlists" / list_uuid / "items"
12591254
async with self._session.put(
12601255
url, headers=self.headers, json=json_data
12611256
) as r:
@@ -1388,7 +1383,7 @@ async def retrieve_new_access_token(
13881383
return data
13891384

13901385
async def set_list_article_language(
1391-
self, list_uuid: UUID, language: str
1386+
self, list_uuid: str, language: str
13921387
) -> aiohttp.ClientResponse:
13931388
"""Set the article language for a specified list.
13941389
@@ -1420,8 +1415,8 @@ async def set_list_article_language(
14201415
url = (
14211416
self.url
14221417
/ "bringusersettings"
1423-
/ str(self.uuid)
1424-
/ str(list_uuid)
1418+
/ self.uuid
1419+
/ list_uuid
14251420
/ "listArticleLanguage"
14261421
)
14271422

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

1464-
async def get_activity(self, list_uuid: UUID) -> BringActivityResponse:
1459+
async def get_activity(self, list_uuid: str) -> BringActivityResponse:
14651460
"""Get activity for given list."""
14661461
try:
1467-
url = self.url / "v2/bringlists" / str(list_uuid) / "activity"
1462+
url = self.url / "v2/bringlists" / list_uuid / "activity"
14681463
async with self._session.get(url, headers=self.headers) as r:
14691464
_LOGGER.debug(
14701465
"Response from %s [%s]: %s", url, r.status, await r.text()

bring_api/types.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from datetime import datetime
55
from enum import Enum, StrEnum
66
from typing import Literal, NotRequired, TypedDict
7-
from uuid import UUID
87

98
from mashumaro.mixins.orjson import DataClassORJSONMixin
109

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

16-
listUuid: UUID
15+
listUuid: str
1716
name: str
1817
theme: str
1918

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

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

56-
uuid: UUID
55+
uuid: str
5756
itemId: str
58-
listUuid: UUID
57+
listUuid: str
5958
userIconItemId: str
6059
userSectionId: str
6160
assignedTo: str
@@ -66,10 +65,9 @@ class BringListItemDetails(DataClassORJSONMixin):
6665
class BringAuthResponse(DataClassORJSONMixin):
6766
"""An auth response class."""
6867

69-
uuid: UUID
70-
publicUuid: UUID
71-
72-
bringListUUID: UUID
68+
uuid: str
69+
publicUuid: str
70+
bringListUUID: str
7371
access_token: str
7472
refresh_token: str
7573
token_type: str
@@ -98,7 +96,7 @@ class Items(DataClassORJSONMixin):
9896
class BringItemsResponse(DataClassORJSONMixin):
9997
"""An items response class."""
10098

101-
uuid: UUID
99+
uuid: str
102100
status: str
103101
items: Items
104102

@@ -184,9 +182,9 @@ class BringSyncCurrentUserResponse(DataClassORJSONMixin):
184182
email: str
185183
emailVerified: bool
186184
premiumConfiguration: dict[str, bool]
187-
publicUserUuid: UUID
185+
publicUserUuid: str
188186
userLocale: UserLocale
189-
userUuid: UUID
187+
userUuid: str
190188
name: str = ""
191189
photoPath: str = ""
192190

@@ -247,9 +245,9 @@ class ActivityType(StrEnum):
247245
class ActivityContent:
248246
"""An activity content entry."""
249247

250-
uuid: UUID
248+
uuid: str
251249
sessionDate: datetime
252-
publicUserUuid: UUID
250+
publicUserUuid: str
253251
items: list[BringPurchase] = field(default_factory=list)
254252
purchase: list[BringPurchase] = field(default_factory=list)
255253
recently: list[BringPurchase] = field(default_factory=list)

0 commit comments

Comments
 (0)