Bump python-bring-api to 3.0.0 (#109720)
This commit is contained in:
parent
ed7307cdaf
commit
53d46acc50
10 changed files with 42 additions and 51 deletions
|
@ -14,6 +14,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import BringDataUpdateCoordinator
|
||||
|
@ -29,14 +30,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
email = entry.data[CONF_EMAIL]
|
||||
password = entry.data[CONF_PASSWORD]
|
||||
|
||||
bring = Bring(email, password)
|
||||
|
||||
def login_and_load_lists() -> None:
|
||||
bring.login()
|
||||
bring.loadLists()
|
||||
session = async_get_clientsession(hass)
|
||||
bring = Bring(email, password, sessionAsync=session)
|
||||
|
||||
try:
|
||||
await hass.async_add_executor_job(login_and_load_lists)
|
||||
await bring.loginAsync()
|
||||
await bring.loadListsAsync()
|
||||
except BringRequestException as e:
|
||||
raise ConfigEntryNotReady(
|
||||
f"Timeout while connecting for email '{email}'"
|
||||
|
|
|
@ -11,6 +11,7 @@ import voluptuous as vol
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.selector import (
|
||||
TextSelector,
|
||||
TextSelectorConfig,
|
||||
|
@ -48,14 +49,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"""Handle the initial step."""
|
||||
errors: dict[str, str] = {}
|
||||
if user_input is not None:
|
||||
bring = Bring(user_input[CONF_EMAIL], user_input[CONF_PASSWORD])
|
||||
|
||||
def login_and_load_lists() -> None:
|
||||
bring.login()
|
||||
bring.loadLists()
|
||||
session = async_get_clientsession(self.hass)
|
||||
bring = Bring(
|
||||
user_input[CONF_EMAIL], user_input[CONF_PASSWORD], sessionAsync=session
|
||||
)
|
||||
|
||||
try:
|
||||
await self.hass.async_add_executor_job(login_and_load_lists)
|
||||
await bring.loginAsync()
|
||||
await bring.loadListsAsync()
|
||||
except BringRequestException:
|
||||
errors["base"] = "cannot_connect"
|
||||
except BringAuthException:
|
||||
|
|
|
@ -40,9 +40,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
|||
|
||||
async def _async_update_data(self) -> dict[str, BringData]:
|
||||
try:
|
||||
lists_response = await self.hass.async_add_executor_job(
|
||||
self.bring.loadLists
|
||||
)
|
||||
lists_response = await self.bring.loadListsAsync()
|
||||
except BringRequestException as e:
|
||||
raise UpdateFailed("Unable to connect and retrieve data from bring") from e
|
||||
except BringParseException as e:
|
||||
|
@ -51,9 +49,7 @@ class BringDataUpdateCoordinator(DataUpdateCoordinator[dict[str, BringData]]):
|
|||
list_dict = {}
|
||||
for lst in lists_response["lists"]:
|
||||
try:
|
||||
items = await self.hass.async_add_executor_job(
|
||||
self.bring.getItems, lst["listUuid"]
|
||||
)
|
||||
items = await self.bring.getItemsAsync(lst["listUuid"])
|
||||
except BringRequestException as e:
|
||||
raise UpdateFailed(
|
||||
"Unable to connect and retrieve data from bring"
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/bring",
|
||||
"integration_type": "service",
|
||||
"iot_class": "cloud_polling",
|
||||
"requirements": ["python-bring-api==2.0.0"]
|
||||
"requirements": ["python-bring-api==3.0.0"]
|
||||
}
|
||||
|
|
|
@ -91,11 +91,8 @@ class BringTodoListEntity(
|
|||
async def async_create_todo_item(self, item: TodoItem) -> None:
|
||||
"""Add an item to the To-do list."""
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.saveItem,
|
||||
self.bring_list["listUuid"],
|
||||
item.summary,
|
||||
item.description or "",
|
||||
await self.coordinator.bring.saveItemAsync(
|
||||
self.bring_list["listUuid"], item.summary, item.description or ""
|
||||
)
|
||||
except BringRequestException as e:
|
||||
raise HomeAssistantError("Unable to save todo item for bring") from e
|
||||
|
@ -126,16 +123,14 @@ class BringTodoListEntity(
|
|||
assert item.uid
|
||||
|
||||
if item.status == TodoItemStatus.COMPLETED:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.removeItem,
|
||||
await self.coordinator.bring.removeItemAsync(
|
||||
bring_list["listUuid"],
|
||||
item.uid,
|
||||
)
|
||||
|
||||
elif item.summary == item.uid:
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.updateItem,
|
||||
await self.coordinator.bring.updateItemAsync(
|
||||
bring_list["listUuid"],
|
||||
item.uid,
|
||||
item.description or "",
|
||||
|
@ -144,13 +139,11 @@ class BringTodoListEntity(
|
|||
raise HomeAssistantError("Unable to update todo item for bring") from e
|
||||
else:
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.removeItem,
|
||||
await self.coordinator.bring.removeItemAsync(
|
||||
bring_list["listUuid"],
|
||||
item.uid,
|
||||
)
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.saveItem,
|
||||
await self.coordinator.bring.saveItemAsync(
|
||||
bring_list["listUuid"],
|
||||
item.summary,
|
||||
item.description or "",
|
||||
|
@ -164,8 +157,8 @@ class BringTodoListEntity(
|
|||
"""Delete an item from the To-do list."""
|
||||
for uid in uids:
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
self.coordinator.bring.removeItem, self.bring_list["listUuid"], uid
|
||||
await self.coordinator.bring.removeItemAsync(
|
||||
self.bring_list["listUuid"], uid
|
||||
)
|
||||
except BringRequestException as e:
|
||||
raise HomeAssistantError("Unable to delete todo item for bring") from e
|
||||
|
|
|
@ -2181,7 +2181,7 @@ python-awair==0.2.4
|
|||
python-blockchain-api==0.0.2
|
||||
|
||||
# homeassistant.components.bring
|
||||
python-bring-api==2.0.0
|
||||
python-bring-api==3.0.0
|
||||
|
||||
# homeassistant.components.bsblan
|
||||
python-bsblan==0.5.18
|
||||
|
|
|
@ -1684,7 +1684,7 @@ python-MotionMount==0.3.1
|
|||
python-awair==0.2.4
|
||||
|
||||
# homeassistant.components.bring
|
||||
python-bring-api==2.0.0
|
||||
python-bring-api==3.0.0
|
||||
|
||||
# homeassistant.components.bsblan
|
||||
python-bsblan==0.5.18
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""Common fixtures for the Bring! tests."""
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -16,7 +16,7 @@ UUID = "00000000-00000000-00000000-00000000"
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[Mock, None, None]:
|
||||
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||
"""Override async_setup_entry."""
|
||||
with patch(
|
||||
"homeassistant.components.bring.async_setup_entry", return_value=True
|
||||
|
@ -25,7 +25,7 @@ def mock_setup_entry() -> Generator[Mock, None, None]:
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_bring_client() -> Generator[Mock, None, None]:
|
||||
def mock_bring_client() -> Generator[AsyncMock, None, None]:
|
||||
"""Mock a Bring client."""
|
||||
with patch(
|
||||
"homeassistant.components.bring.Bring",
|
||||
|
@ -36,8 +36,8 @@ def mock_bring_client() -> Generator[Mock, None, None]:
|
|||
):
|
||||
client = mock_client.return_value
|
||||
client.uuid = UUID
|
||||
client.login.return_value = True
|
||||
client.loadLists.return_value = {"lists": []}
|
||||
client.loginAsync.return_value = True
|
||||
client.loadListsAsync.return_value = {"lists": []}
|
||||
yield client
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Test the Bring! config flow."""
|
||||
from unittest.mock import AsyncMock, Mock
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
from python_bring_api.exceptions import (
|
||||
|
@ -25,7 +25,7 @@ MOCK_DATA_STEP = {
|
|||
|
||||
|
||||
async def test_form(
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_bring_client: Mock
|
||||
hass: HomeAssistant, mock_setup_entry: AsyncMock, mock_bring_client: AsyncMock
|
||||
) -> None:
|
||||
"""Test we get the form."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -59,10 +59,10 @@ async def test_form(
|
|||
],
|
||||
)
|
||||
async def test_flow_user_init_data_unknown_error_and_recover(
|
||||
hass: HomeAssistant, mock_bring_client: Mock, raise_error, text_error
|
||||
hass: HomeAssistant, mock_bring_client: AsyncMock, raise_error, text_error
|
||||
) -> None:
|
||||
"""Test unknown errors."""
|
||||
mock_bring_client.login.side_effect = raise_error
|
||||
mock_bring_client.loginAsync.side_effect = raise_error
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
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
|
||||
|
||||
# Recover
|
||||
mock_bring_client.login.side_effect = None
|
||||
mock_bring_client.loginAsync.side_effect = None
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": "user"}
|
||||
)
|
||||
|
@ -92,7 +92,9 @@ async def test_flow_user_init_data_unknown_error_and_recover(
|
|||
|
||||
|
||||
async def test_flow_user_init_data_already_configured(
|
||||
hass: HomeAssistant, mock_bring_client: Mock, bring_config_entry: MockConfigEntry
|
||||
hass: HomeAssistant,
|
||||
mock_bring_client: AsyncMock,
|
||||
bring_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test we abort user data set when entry is already configured."""
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
"""Unit tests for the bring integration."""
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -27,7 +27,7 @@ async def setup_integration(
|
|||
|
||||
async def test_load_unload(
|
||||
hass: HomeAssistant,
|
||||
mock_bring_client: Mock,
|
||||
mock_bring_client: AsyncMock,
|
||||
bring_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test loading and unloading of the config entry."""
|
||||
|
@ -52,12 +52,12 @@ async def test_load_unload(
|
|||
)
|
||||
async def test_init_failure(
|
||||
hass: HomeAssistant,
|
||||
mock_bring_client: Mock,
|
||||
mock_bring_client: AsyncMock,
|
||||
status: ConfigEntryState,
|
||||
exception: Exception,
|
||||
bring_config_entry: MockConfigEntry | None,
|
||||
) -> None:
|
||||
"""Test an initialization error on integration load."""
|
||||
mock_bring_client.login.side_effect = exception
|
||||
mock_bring_client.loginAsync.side_effect = exception
|
||||
await setup_integration(hass, bring_config_entry)
|
||||
assert bring_config_entry.state == status
|
||||
|
|
Loading…
Add table
Reference in a new issue