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.bring import Bring
|
||||||
from bring_api.exceptions import BringParseException, BringRequestException
|
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.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -20,8 +20,8 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
class BringData(BringList):
|
class BringData(BringList):
|
||||||
"""Coordinator data class."""
|
"""Coordinator data class."""
|
||||||
|
|
||||||
purchase_items: list[BringItemsResponse]
|
purchase_items: list[BringPurchase]
|
||||||
recently_items: list[BringItemsResponse]
|
recently_items: list[BringPurchase]
|
||||||
|
|
||||||
|
|
||||||
class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"documentation": "https://www.home-assistant.io/integrations/bring",
|
"documentation": "https://www.home-assistant.io/integrations/bring",
|
||||||
"integration_type": "service",
|
"integration_type": "service",
|
||||||
"iot_class": "cloud_polling",
|
"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 __future__ import annotations
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
import uuid
|
||||||
|
|
||||||
from bring_api.exceptions import BringRequestException
|
from bring_api.exceptions import BringRequestException
|
||||||
|
from bring_api.types import BringItem, BringItemOperation
|
||||||
|
|
||||||
from homeassistant.components.todo import (
|
from homeassistant.components.todo import (
|
||||||
TodoItem,
|
TodoItem,
|
||||||
|
@ -76,7 +78,7 @@ class BringTodoListEntity(
|
||||||
return [
|
return [
|
||||||
*(
|
*(
|
||||||
TodoItem(
|
TodoItem(
|
||||||
uid=item["itemId"],
|
uid=item["uuid"],
|
||||||
summary=item["itemId"],
|
summary=item["itemId"],
|
||||||
description=item["specification"] or "",
|
description=item["specification"] or "",
|
||||||
status=TodoItemStatus.NEEDS_ACTION,
|
status=TodoItemStatus.NEEDS_ACTION,
|
||||||
|
@ -85,7 +87,7 @@ class BringTodoListEntity(
|
||||||
),
|
),
|
||||||
*(
|
*(
|
||||||
TodoItem(
|
TodoItem(
|
||||||
uid=item["itemId"],
|
uid=item["uuid"],
|
||||||
summary=item["itemId"],
|
summary=item["itemId"],
|
||||||
description=item["specification"] or "",
|
description=item["specification"] or "",
|
||||||
status=TodoItemStatus.COMPLETED,
|
status=TodoItemStatus.COMPLETED,
|
||||||
|
@ -103,7 +105,10 @@ class BringTodoListEntity(
|
||||||
"""Add an item to the To-do list."""
|
"""Add an item to the To-do list."""
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.save_item(
|
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:
|
except BringRequestException as e:
|
||||||
raise HomeAssistantError("Unable to save todo item for bring") from 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
|
- Completed items will move to the "completed" section in home assistant todo
|
||||||
list and get moved to the recently list in bring
|
list and get moved to the recently list in bring
|
||||||
- Bring items do not have unique identifiers and are using the
|
- Bring shows some odd behaviour when renaming items. This is because Bring
|
||||||
name/summery/title. Therefore the name is not to be changed! Should a name
|
did not have unique identifiers for items in the past and this is still
|
||||||
be changed anyway, a new item will be created instead and no update for
|
a relic from it. Therefore the name is not to be changed! Should a name
|
||||||
this item is performed and on the next cloud pull update, it will get
|
be changed anyway, the item will be deleted and a new item will be created
|
||||||
cleared and replaced seamlessly
|
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_list = self.bring_list
|
||||||
|
|
||||||
bring_purchase_item = next(
|
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,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
bring_recently_item = next(
|
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,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
current_item = bring_purchase_item or bring_recently_item
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert item.uid
|
assert item.uid
|
||||||
|
assert current_item
|
||||||
|
|
||||||
if item.status == TodoItemStatus.COMPLETED and bring_purchase_item:
|
if item.summary == current_item["itemId"]:
|
||||||
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:
|
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.update_item(
|
await self.coordinator.bring.batch_update_list(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
BringItem(
|
||||||
item.description or "",
|
itemId=item.summary,
|
||||||
|
spec=item.description,
|
||||||
|
uuid=item.uid,
|
||||||
|
),
|
||||||
|
BringItemOperation.ADD
|
||||||
|
if item.status == TodoItemStatus.NEEDS_ACTION
|
||||||
|
else BringItemOperation.COMPLETE,
|
||||||
)
|
)
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
raise HomeAssistantError("Unable to update todo item for bring") from e
|
raise HomeAssistantError("Unable to update todo item for bring") from e
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.remove_item(
|
await self.coordinator.bring.batch_update_list(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
[
|
||||||
)
|
BringItem(
|
||||||
await self.coordinator.bring.save_tem(
|
itemId=current_item["itemId"],
|
||||||
bring_list["listUuid"],
|
spec=item.description,
|
||||||
item.summary,
|
uuid=item.uid,
|
||||||
item.description or "",
|
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:
|
except BringRequestException as e:
|
||||||
raise HomeAssistantError("Unable to replace todo item for bring") from 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:
|
async def async_delete_todo_items(self, uids: list[str]) -> None:
|
||||||
"""Delete an item from the To-do list."""
|
"""Delete an item from the To-do list."""
|
||||||
for uid in uids:
|
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.remove_item(
|
await self.coordinator.bring.batch_update_list(
|
||||||
self.bring_list["listUuid"], uid
|
self.bring_list["listUuid"],
|
||||||
)
|
[
|
||||||
except BringRequestException as e:
|
BringItem(
|
||||||
raise HomeAssistantError("Unable to delete todo item for bring") from e
|
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()
|
await self.coordinator.async_refresh()
|
||||||
|
|
|
@ -603,7 +603,7 @@ boschshcpy==0.2.75
|
||||||
boto3==1.33.13
|
boto3==1.33.13
|
||||||
|
|
||||||
# homeassistant.components.bring
|
# homeassistant.components.bring
|
||||||
bring-api==0.4.1
|
bring-api==0.5.4
|
||||||
|
|
||||||
# homeassistant.components.broadlink
|
# homeassistant.components.broadlink
|
||||||
broadlink==0.18.3
|
broadlink==0.18.3
|
||||||
|
|
|
@ -514,7 +514,7 @@ bond-async==0.2.1
|
||||||
boschshcpy==0.2.75
|
boschshcpy==0.2.75
|
||||||
|
|
||||||
# homeassistant.components.bring
|
# homeassistant.components.bring
|
||||||
bring-api==0.4.1
|
bring-api==0.5.4
|
||||||
|
|
||||||
# homeassistant.components.broadlink
|
# homeassistant.components.broadlink
|
||||||
broadlink==0.18.3
|
broadlink==0.18.3
|
||||||
|
|
Loading…
Reference in New Issue