Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some typing errors in Bring integration #115641

Merged
merged 1 commit into from
May 28, 2024
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
14 changes: 5 additions & 9 deletions homeassistant/components/bring/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
Expand All @@ -22,12 +22,9 @@
_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."""
Expand Down Expand Up @@ -56,7 +53,7 @@ async def _async_update_data(self) -> 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"])
Expand All @@ -66,8 +63,7 @@ async def _async_update_data(self) -> 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
20 changes: 10 additions & 10 deletions homeassistant/components/bring/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def todo_items(self) -> list[TodoItem]:
description=item["specification"] or "",
status=TodoItemStatus.NEEDS_ACTION,
)
for item in self.bring_list["purchase_items"]
for item in self.bring_list["purchase"]
),
*(
TodoItem(
Expand All @@ -116,7 +116,7 @@ def todo_items(self) -> list[TodoItem]:
description=item["specification"] or "",
status=TodoItemStatus.COMPLETED,
)
for item in self.bring_list["recently_items"]
for item in self.bring_list["recently"]
),
]

Expand All @@ -130,7 +130,7 @@ async def async_create_todo_item(self, item: TodoItem) -> None:
try:
await self.coordinator.bring.save_item(
self.bring_list["listUuid"],
item.summary,
item.summary or "",
item.description or "",
str(uuid.uuid4()),
)
Expand Down Expand Up @@ -165,12 +165,12 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
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,
)

Expand All @@ -185,8 +185,8 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
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
Expand All @@ -206,13 +206,13 @@ async def async_update_todo_item(self, item: TodoItem) -> None:
[
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
Expand Down