mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Switch to new Bring! lib (#110355)
* switch to new bring lib * rename lib again
This commit is contained in:
parent
4d39a85553
commit
6812596cd7
@ -3,8 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from python_bring_api.bring import Bring
|
from bring_api.bring import Bring
|
||||||
from python_bring_api.exceptions import (
|
from bring_api.exceptions import (
|
||||||
BringAuthException,
|
BringAuthException,
|
||||||
BringParseException,
|
BringParseException,
|
||||||
BringRequestException,
|
BringRequestException,
|
||||||
@ -31,11 +31,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
password = entry.data[CONF_PASSWORD]
|
password = entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
bring = Bring(email, password, sessionAsync=session)
|
bring = Bring(session, email, password)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await bring.loginAsync()
|
await bring.login()
|
||||||
await bring.loadListsAsync()
|
await bring.loadLists()
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
f"Timeout while connecting for email '{email}'"
|
f"Timeout while connecting for email '{email}'"
|
||||||
|
@ -4,8 +4,8 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from python_bring_api.bring import Bring
|
from bring_api.bring import Bring
|
||||||
from python_bring_api.exceptions import BringAuthException, BringRequestException
|
from bring_api.exceptions import BringAuthException, BringRequestException
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -50,13 +50,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
session = async_get_clientsession(self.hass)
|
session = async_get_clientsession(self.hass)
|
||||||
bring = Bring(
|
bring = Bring(session, user_input[CONF_EMAIL], user_input[CONF_PASSWORD])
|
||||||
user_input[CONF_EMAIL], user_input[CONF_PASSWORD], sessionAsync=session
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await bring.loginAsync()
|
await bring.login()
|
||||||
await bring.loadListsAsync()
|
await bring.loadLists()
|
||||||
except BringRequestException:
|
except BringRequestException:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except BringAuthException:
|
except BringAuthException:
|
||||||
|
@ -4,9 +4,9 @@ from __future__ import annotations
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from python_bring_api.bring import Bring
|
from bring_api.bring import Bring
|
||||||
from python_bring_api.exceptions import BringParseException, BringRequestException
|
from bring_api.exceptions import BringParseException, BringRequestException
|
||||||
from python_bring_api.types import BringItemsResponse, BringList
|
from bring_api.types import BringItemsResponse, BringList
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -40,7 +40,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
|||||||
|
|
||||||
async def _async_update_data(self) -> dict[str, BringData]:
|
async def _async_update_data(self) -> dict[str, BringData]:
|
||||||
try:
|
try:
|
||||||
lists_response = await self.bring.loadListsAsync()
|
lists_response = await self.bring.loadLists()
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
raise UpdateFailed("Unable to connect and retrieve data from bring") from e
|
raise UpdateFailed("Unable to connect and retrieve data from bring") from e
|
||||||
except BringParseException as e:
|
except BringParseException as e:
|
||||||
@ -49,7 +49,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
|||||||
list_dict = {}
|
list_dict = {}
|
||||||
for lst in lists_response["lists"]:
|
for lst in lists_response["lists"]:
|
||||||
try:
|
try:
|
||||||
items = await self.bring.getItemsAsync(lst["listUuid"])
|
items = await self.bring.getItems(lst["listUuid"])
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
raise UpdateFailed(
|
raise UpdateFailed(
|
||||||
"Unable to connect and retrieve data from bring"
|
"Unable to connect and retrieve data from bring"
|
||||||
|
@ -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": ["python-bring-api==3.0.0"]
|
"requirements": ["bring-api==0.1.1"]
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from python_bring_api.exceptions import BringRequestException
|
from bring_api.exceptions import BringRequestException
|
||||||
|
|
||||||
from homeassistant.components.todo import (
|
from homeassistant.components.todo import (
|
||||||
TodoItem,
|
TodoItem,
|
||||||
@ -75,8 +75,8 @@ class BringTodoListEntity(
|
|||||||
"""Return the todo items."""
|
"""Return the todo items."""
|
||||||
return [
|
return [
|
||||||
TodoItem(
|
TodoItem(
|
||||||
uid=item["name"],
|
uid=item["itemId"],
|
||||||
summary=item["name"],
|
summary=item["itemId"],
|
||||||
description=item["specification"] or "",
|
description=item["specification"] or "",
|
||||||
status=TodoItemStatus.NEEDS_ACTION,
|
status=TodoItemStatus.NEEDS_ACTION,
|
||||||
)
|
)
|
||||||
@ -91,7 +91,7 @@ class BringTodoListEntity(
|
|||||||
async def async_create_todo_item(self, item: TodoItem) -> None:
|
async def async_create_todo_item(self, item: TodoItem) -> None:
|
||||||
"""Add an item to the To-do list."""
|
"""Add an item to the To-do list."""
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.saveItemAsync(
|
await self.coordinator.bring.saveItem(
|
||||||
self.bring_list["listUuid"], item.summary, item.description or ""
|
self.bring_list["listUuid"], item.summary, item.description or ""
|
||||||
)
|
)
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
@ -123,14 +123,14 @@ class BringTodoListEntity(
|
|||||||
assert item.uid
|
assert item.uid
|
||||||
|
|
||||||
if item.status == TodoItemStatus.COMPLETED:
|
if item.status == TodoItemStatus.COMPLETED:
|
||||||
await self.coordinator.bring.removeItemAsync(
|
await self.coordinator.bring.removeItem(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
item.uid,
|
||||||
)
|
)
|
||||||
|
|
||||||
elif item.summary == item.uid:
|
elif item.summary == item.uid:
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.updateItemAsync(
|
await self.coordinator.bring.updateItem(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
item.uid,
|
||||||
item.description or "",
|
item.description or "",
|
||||||
@ -139,11 +139,11 @@ class BringTodoListEntity(
|
|||||||
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.removeItemAsync(
|
await self.coordinator.bring.removeItem(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
item.uid,
|
||||||
)
|
)
|
||||||
await self.coordinator.bring.saveItemAsync(
|
await self.coordinator.bring.saveItem(
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.summary,
|
item.summary,
|
||||||
item.description or "",
|
item.description or "",
|
||||||
@ -157,7 +157,7 @@ class BringTodoListEntity(
|
|||||||
"""Delete an item from the To-do list."""
|
"""Delete an item from the To-do list."""
|
||||||
for uid in uids:
|
for uid in uids:
|
||||||
try:
|
try:
|
||||||
await self.coordinator.bring.removeItemAsync(
|
await self.coordinator.bring.removeItem(
|
||||||
self.bring_list["listUuid"], uid
|
self.bring_list["listUuid"], uid
|
||||||
)
|
)
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
|
@ -599,6 +599,9 @@ boschshcpy==0.2.75
|
|||||||
# homeassistant.components.route53
|
# homeassistant.components.route53
|
||||||
boto3==1.33.13
|
boto3==1.33.13
|
||||||
|
|
||||||
|
# homeassistant.components.bring
|
||||||
|
bring-api==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.broadlink
|
# homeassistant.components.broadlink
|
||||||
broadlink==0.18.3
|
broadlink==0.18.3
|
||||||
|
|
||||||
@ -2186,9 +2189,6 @@ python-awair==0.2.4
|
|||||||
# homeassistant.components.blockchain
|
# homeassistant.components.blockchain
|
||||||
python-blockchain-api==0.0.2
|
python-blockchain-api==0.0.2
|
||||||
|
|
||||||
# homeassistant.components.bring
|
|
||||||
python-bring-api==3.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.bsblan
|
# homeassistant.components.bsblan
|
||||||
python-bsblan==0.5.18
|
python-bsblan==0.5.18
|
||||||
|
|
||||||
|
@ -507,6 +507,9 @@ bond-async==0.2.1
|
|||||||
# homeassistant.components.bosch_shc
|
# homeassistant.components.bosch_shc
|
||||||
boschshcpy==0.2.75
|
boschshcpy==0.2.75
|
||||||
|
|
||||||
|
# homeassistant.components.bring
|
||||||
|
bring-api==0.1.1
|
||||||
|
|
||||||
# homeassistant.components.broadlink
|
# homeassistant.components.broadlink
|
||||||
broadlink==0.18.3
|
broadlink==0.18.3
|
||||||
|
|
||||||
@ -1689,9 +1692,6 @@ python-MotionMount==0.3.1
|
|||||||
# homeassistant.components.awair
|
# homeassistant.components.awair
|
||||||
python-awair==0.2.4
|
python-awair==0.2.4
|
||||||
|
|
||||||
# homeassistant.components.bring
|
|
||||||
python-bring-api==3.0.0
|
|
||||||
|
|
||||||
# homeassistant.components.bsblan
|
# homeassistant.components.bsblan
|
||||||
python-bsblan==0.5.18
|
python-bsblan==0.5.18
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ def mock_bring_client() -> Generator[AsyncMock, None, None]:
|
|||||||
):
|
):
|
||||||
client = mock_client.return_value
|
client = mock_client.return_value
|
||||||
client.uuid = UUID
|
client.uuid = UUID
|
||||||
client.loginAsync.return_value = True
|
client.login.return_value = True
|
||||||
client.loadListsAsync.return_value = {"lists": []}
|
client.loadLists.return_value = {"lists": []}
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
"""Test the Bring! config flow."""
|
"""Test the Bring! config flow."""
|
||||||
from unittest.mock import AsyncMock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
import pytest
|
from bring_api.exceptions import (
|
||||||
from python_bring_api.exceptions import (
|
|
||||||
BringAuthException,
|
BringAuthException,
|
||||||
BringParseException,
|
BringParseException,
|
||||||
BringRequestException,
|
BringRequestException,
|
||||||
)
|
)
|
||||||
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components.bring.const import DOMAIN
|
from homeassistant.components.bring.const import DOMAIN
|
||||||
@ -62,7 +62,7 @@ async def test_flow_user_init_data_unknown_error_and_recover(
|
|||||||
hass: HomeAssistant, mock_bring_client: AsyncMock, raise_error, text_error
|
hass: HomeAssistant, mock_bring_client: AsyncMock, raise_error, text_error
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unknown errors."""
|
"""Test unknown errors."""
|
||||||
mock_bring_client.loginAsync.side_effect = raise_error
|
mock_bring_client.login.side_effect = raise_error
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
@ -76,7 +76,7 @@ async def test_flow_user_init_data_unknown_error_and_recover(
|
|||||||
assert result["errors"]["base"] == text_error
|
assert result["errors"]["base"] == text_error
|
||||||
|
|
||||||
# Recover
|
# Recover
|
||||||
mock_bring_client.loginAsync.side_effect = None
|
mock_bring_client.login.side_effect = None
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": "user"}
|
DOMAIN, context={"source": "user"}
|
||||||
)
|
)
|
||||||
|
@ -58,6 +58,6 @@ async def test_init_failure(
|
|||||||
bring_config_entry: MockConfigEntry | None,
|
bring_config_entry: MockConfigEntry | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test an initialization error on integration load."""
|
"""Test an initialization error on integration load."""
|
||||||
mock_bring_client.loginAsync.side_effect = exception
|
mock_bring_client.login.side_effect = exception
|
||||||
await setup_integration(hass, bring_config_entry)
|
await setup_integration(hass, bring_config_entry)
|
||||||
assert bring_config_entry.state == status
|
assert bring_config_entry.state == status
|
||||||
|
Loading…
x
Reference in New Issue
Block a user