Bump bring-api to 0.5.4 (#111654)

pull/112262/head
Mr. Bubbles 2024-03-04 15:57:37 +01:00 committed by GitHub
parent 6aae44dbb3
commit 34d25cf9e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 69 additions and 46 deletions

View File

@ -6,7 +6,7 @@ import logging
from bring_api.bring import Bring
from bring_api.exceptions import BringParseException, BringRequestException
from bring_api.types import BringItemsResponse, BringList
from bring_api.types import BringList, BringPurchase
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -20,8 +20,8 @@ _LOGGER = logging.getLogger(__name__)
class BringData(BringList):
"""Coordinator data class."""
purchase_items: list[BringItemsResponse]
recently_items: list[BringItemsResponse]
purchase_items: list[BringPurchase]
recently_items: list[BringPurchase]
class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/bring",
"integration_type": "service",
"iot_class": "cloud_polling",
"requirements": ["bring-api==0.4.1"]
"requirements": ["bring-api==0.5.4"]
}

View File

@ -2,8 +2,10 @@
from __future__ import annotations
from typing import TYPE_CHECKING
import uuid
from bring_api.exceptions import BringRequestException
from bring_api.types import BringItem, BringItemOperation
from homeassistant.components.todo import (
TodoItem,
@ -76,7 +78,7 @@ class BringTodoListEntity(
return [
*(
TodoItem(
uid=item["itemId"],
uid=item["uuid"],
summary=item["itemId"],
description=item["specification"] or "",
status=TodoItemStatus.NEEDS_ACTION,
@ -85,7 +87,7 @@ class BringTodoListEntity(
),
*(
TodoItem(
uid=item["itemId"],
uid=item["uuid"],
summary=item["itemId"],
description=item["specification"] or "",
status=TodoItemStatus.COMPLETED,
@ -103,7 +105,10 @@ class BringTodoListEntity(
"""Add an item to the To-do list."""
try:
await self.coordinator.bring.save_item(
self.bring_list["listUuid"], item.summary, item.description or ""
self.bring_list["listUuid"],
item.summary,
item.description or "",
str(uuid.uuid4()),
)
except BringRequestException as e:
raise HomeAssistantError("Unable to save todo item for bring") from e
@ -121,60 +126,69 @@ class BringTodoListEntity(
- Completed items will move to the "completed" section in home assistant todo
list and get moved to the recently list in bring
- Bring items do not have unique identifiers and are using the
name/summery/title. Therefore the name is not to be changed! Should a name
be changed anyway, a new item will be created instead and no update for
this item is performed and on the next cloud pull update, it will get
cleared and replaced seamlessly
- Bring shows some odd behaviour when renaming items. This is because Bring
did not have unique identifiers for items in the past and this is still
a relic from it. Therefore the name is not to be changed! Should a name
be changed anyway, the item will be deleted and a new item will be created
instead and no update for this item is performed and on the next cloud pull
update, it will get cleared and replaced seamlessly.
"""
bring_list = self.bring_list
bring_purchase_item = next(
(i for i in bring_list["purchase_items"] if i["itemId"] == item.uid),
(i for i in bring_list["purchase_items"] if i["uuid"] == item.uid),
None,
)
bring_recently_item = next(
(i for i in bring_list["recently_items"] if i["itemId"] == item.uid),
(i for i in bring_list["recently_items"] if i["uuid"] == item.uid),
None,
)
current_item = bring_purchase_item or bring_recently_item
if TYPE_CHECKING:
assert item.uid
assert current_item
if item.status == TodoItemStatus.COMPLETED and bring_purchase_item:
await self.coordinator.bring.complete_item(
bring_list["listUuid"],
item.uid,
)
elif item.status == TodoItemStatus.NEEDS_ACTION and bring_recently_item:
await self.coordinator.bring.save_item(
bring_list["listUuid"],
item.uid,
)
elif item.summary == item.uid:
if item.summary == current_item["itemId"]:
try:
await self.coordinator.bring.update_item(
await self.coordinator.bring.batch_update_list(
bring_list["listUuid"],
item.uid,
item.description or "",
BringItem(
itemId=item.summary,
spec=item.description,
uuid=item.uid,
),
BringItemOperation.ADD
if item.status == TodoItemStatus.NEEDS_ACTION
else BringItemOperation.COMPLETE,
)
except BringRequestException as e:
raise HomeAssistantError("Unable to update todo item for bring") from e
else:
try:
await self.coordinator.bring.remove_item(
await self.coordinator.bring.batch_update_list(
bring_list["listUuid"],
item.uid,
)
await self.coordinator.bring.save_tem(
bring_list["listUuid"],
item.summary,
item.description or "",
[
BringItem(
itemId=current_item["itemId"],
spec=item.description,
uuid=item.uid,
operation=BringItemOperation.REMOVE,
),
BringItem(
itemId=item.summary,
spec=item.description,
uuid=str(uuid.uuid4()),
operation=BringItemOperation.ADD
if item.status == TodoItemStatus.NEEDS_ACTION
else BringItemOperation.COMPLETE,
),
],
)
except BringRequestException as e:
raise HomeAssistantError("Unable to replace todo item for bring") from e
@ -182,12 +196,21 @@ class BringTodoListEntity(
async def async_delete_todo_items(self, uids: list[str]) -> None:
"""Delete an item from the To-do list."""
for uid in uids:
try:
await self.coordinator.bring.remove_item(
self.bring_list["listUuid"], uid
)
except BringRequestException as e:
raise HomeAssistantError("Unable to delete todo item for bring") from e
try:
await self.coordinator.bring.batch_update_list(
self.bring_list["listUuid"],
[
BringItem(
itemId=uid,
spec="",
uuid=uid,
)
for uid in uids
],
BringItemOperation.REMOVE,
)
except BringRequestException as e:
raise HomeAssistantError("Unable to delete todo item for bring") from e
await self.coordinator.async_refresh()

View File

@ -603,7 +603,7 @@ boschshcpy==0.2.75
boto3==1.33.13
# homeassistant.components.bring
bring-api==0.4.1
bring-api==0.5.4
# homeassistant.components.broadlink
broadlink==0.18.3

View File

@ -514,7 +514,7 @@ bond-async==0.2.1
boschshcpy==0.2.75
# homeassistant.components.bring
bring-api==0.4.1
bring-api==0.5.4
# homeassistant.components.broadlink
broadlink==0.18.3