Fix some typing errors in Bring integration (#115641)

Fix typing errors
pull/118301/head
Mr. Bubbles 2024-05-28 10:25:39 +02:00 committed by GitHub
parent 3b938e592f
commit 98710e6c91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 19 deletions

View File

@ -11,7 +11,7 @@ from bring_api.exceptions import (
BringParseException,
BringRequestException,
)
from bring_api.types import BringList, BringPurchase
from bring_api.types import BringItemsResponse, BringList
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -22,12 +22,9 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
class BringData(BringList):
class BringData(BringList, BringItemsResponse):
"""Coordinator data class."""
purchase_items: list[BringPurchase]
recently_items: list[BringPurchase]
class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
"""A Bring Data Update Coordinator."""
@ -56,7 +53,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
"Unable to retrieve data from bring, authentication failed"
) from e
list_dict = {}
list_dict: dict[str, BringData] = {}
for lst in lists_response["lists"]:
try:
items = await self.bring.get_list(lst["listUuid"])
@ -66,8 +63,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
) from e
except BringParseException as e:
raise UpdateFailed("Unable to parse response from bring") from e
lst["purchase_items"] = items["purchase"]
lst["recently_items"] = items["recently"]
list_dict[lst["listUuid"]] = lst
else:
list_dict[lst["listUuid"]] = BringData(**lst, **items)
return list_dict

View File

@ -107,7 +107,7 @@ class BringTodoListEntity(
description=item["specification"] or "",
status=TodoItemStatus.NEEDS_ACTION,
)
for item in self.bring_list["purchase_items"]
for item in self.bring_list["purchase"]
),
*(
TodoItem(
@ -116,7 +116,7 @@ class BringTodoListEntity(
description=item["specification"] or "",
status=TodoItemStatus.COMPLETED,
)
for item in self.bring_list["recently_items"]
for item in self.bring_list["recently"]
),
]
@ -130,7 +130,7 @@ class BringTodoListEntity(
try:
await self.coordinator.bring.save_item(
self.bring_list["listUuid"],
item.summary,
item.summary or "",
item.description or "",
str(uuid.uuid4()),
)
@ -165,12 +165,12 @@ class BringTodoListEntity(
bring_list = self.bring_list
bring_purchase_item = next(
(i for i in bring_list["purchase_items"] if i["uuid"] == item.uid),
(i for i in bring_list["purchase"] if i["uuid"] == item.uid),
None,
)
bring_recently_item = next(
(i for i in bring_list["recently_items"] if i["uuid"] == item.uid),
(i for i in bring_list["recently"] if i["uuid"] == item.uid),
None,
)
@ -185,8 +185,8 @@ class BringTodoListEntity(
await self.coordinator.bring.batch_update_list(
bring_list["listUuid"],
BringItem(
itemId=item.summary,
spec=item.description,
itemId=item.summary or "",
spec=item.description or "",
uuid=item.uid,
),
BringItemOperation.ADD
@ -206,13 +206,13 @@ class BringTodoListEntity(
[
BringItem(
itemId=current_item["itemId"],
spec=item.description,
spec=item.description or "",
uuid=item.uid,
operation=BringItemOperation.REMOVE,
),
BringItem(
itemId=item.summary,
spec=item.description,
itemId=item.summary or "",
spec=item.description or "",
uuid=str(uuid.uuid4()),
operation=BringItemOperation.ADD
if item.status == TodoItemStatus.NEEDS_ACTION