Bump bring-api to 0.5.4 (#111654)
parent
6aae44dbb3
commit
34d25cf9e6
|
@ -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]]):
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -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,10 +196,19 @@ 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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue