mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Bump python-bring-api to 3.0.0 (#109720)
This commit is contained in:
parent
ed7307cdaf
commit
53d46acc50
@ -14,6 +14,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import BringDataUpdateCoordinator
|
from .coordinator import BringDataUpdateCoordinator
|
||||||
@ -29,14 +30,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
email = entry.data[CONF_EMAIL]
|
email = entry.data[CONF_EMAIL]
|
||||||
password = entry.data[CONF_PASSWORD]
|
password = entry.data[CONF_PASSWORD]
|
||||||
|
|
||||||
bring = Bring(email, password)
|
session = async_get_clientsession(hass)
|
||||||
|
bring = Bring(email, password, sessionAsync=session)
|
||||||
def login_and_load_lists() -> None:
|
|
||||||
bring.login()
|
|
||||||
bring.loadLists()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await hass.async_add_executor_job(login_and_load_lists)
|
await bring.loginAsync()
|
||||||
|
await bring.loadListsAsync()
|
||||||
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}'"
|
||||||
|
@ -11,6 +11,7 @@ import voluptuous as vol
|
|||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.selector import (
|
from homeassistant.helpers.selector import (
|
||||||
TextSelector,
|
TextSelector,
|
||||||
TextSelectorConfig,
|
TextSelectorConfig,
|
||||||
@ -48,14 +49,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
bring = Bring(user_input[CONF_EMAIL], user_input[CONF_PASSWORD])
|
session = async_get_clientsession(self.hass)
|
||||||
|
bring = Bring(
|
||||||
def login_and_load_lists() -> None:
|
user_input[CONF_EMAIL], user_input[CONF_PASSWORD], sessionAsync=session
|
||||||
bring.login()
|
)
|
||||||
bring.loadLists()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.hass.async_add_executor_job(login_and_load_lists)
|
await bring.loginAsync()
|
||||||
|
await bring.loadListsAsync()
|
||||||
except BringRequestException:
|
except BringRequestException:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except BringAuthException:
|
except BringAuthException:
|
||||||
|
@ -40,9 +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.hass.async_add_executor_job(
|
lists_response = await self.bring.loadListsAsync()
|
||||||
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:
|
||||||
@ -51,9 +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.hass.async_add_executor_job(
|
items = await self.bring.getItemsAsync(lst["listUuid"])
|
||||||
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==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:
|
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.hass.async_add_executor_job(
|
await self.coordinator.bring.saveItemAsync(
|
||||||
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:
|
||||||
raise HomeAssistantError("Unable to save todo item for bring") from e
|
raise HomeAssistantError("Unable to save todo item for bring") from e
|
||||||
@ -126,16 +123,14 @@ class BringTodoListEntity(
|
|||||||
assert item.uid
|
assert item.uid
|
||||||
|
|
||||||
if item.status == TodoItemStatus.COMPLETED:
|
if item.status == TodoItemStatus.COMPLETED:
|
||||||
await self.hass.async_add_executor_job(
|
await self.coordinator.bring.removeItemAsync(
|
||||||
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.hass.async_add_executor_job(
|
await self.coordinator.bring.updateItemAsync(
|
||||||
self.coordinator.bring.updateItem,
|
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
item.uid,
|
||||||
item.description or "",
|
item.description or "",
|
||||||
@ -144,13 +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.hass.async_add_executor_job(
|
await self.coordinator.bring.removeItemAsync(
|
||||||
self.coordinator.bring.removeItem,
|
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.uid,
|
item.uid,
|
||||||
)
|
)
|
||||||
await self.hass.async_add_executor_job(
|
await self.coordinator.bring.saveItemAsync(
|
||||||
self.coordinator.bring.saveItem,
|
|
||||||
bring_list["listUuid"],
|
bring_list["listUuid"],
|
||||||
item.summary,
|
item.summary,
|
||||||
item.description or "",
|
item.description or "",
|
||||||
@ -164,8 +157,8 @@ 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.hass.async_add_executor_job(
|
await self.coordinator.bring.removeItemAsync(
|
||||||
self.coordinator.bring.removeItem, self.bring_list["listUuid"], uid
|
self.bring_list["listUuid"], uid
|
||||||
)
|
)
|
||||||
except BringRequestException as e:
|
except BringRequestException as e:
|
||||||
raise HomeAssistantError("Unable to delete todo item for bring") from 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
|
python-blockchain-api==0.0.2
|
||||||
|
|
||||||
# homeassistant.components.bring
|
# homeassistant.components.bring
|
||||||
python-bring-api==2.0.0
|
python-bring-api==3.0.0
|
||||||
|
|
||||||
# homeassistant.components.bsblan
|
# homeassistant.components.bsblan
|
||||||
python-bsblan==0.5.18
|
python-bsblan==0.5.18
|
||||||
|
@ -1684,7 +1684,7 @@ python-MotionMount==0.3.1
|
|||||||
python-awair==0.2.4
|
python-awair==0.2.4
|
||||||
|
|
||||||
# homeassistant.components.bring
|
# homeassistant.components.bring
|
||||||
python-bring-api==2.0.0
|
python-bring-api==3.0.0
|
||||||
|
|
||||||
# homeassistant.components.bsblan
|
# homeassistant.components.bsblan
|
||||||
python-bsblan==0.5.18
|
python-bsblan==0.5.18
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Common fixtures for the Bring! tests."""
|
"""Common fixtures for the Bring! tests."""
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ UUID = "00000000-00000000-00000000-00000000"
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_setup_entry() -> Generator[Mock, None, None]:
|
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
|
||||||
"""Override async_setup_entry."""
|
"""Override async_setup_entry."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.bring.async_setup_entry", return_value=True
|
"homeassistant.components.bring.async_setup_entry", return_value=True
|
||||||
@ -25,7 +25,7 @@ def mock_setup_entry() -> Generator[Mock, None, None]:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_bring_client() -> Generator[Mock, None, None]:
|
def mock_bring_client() -> Generator[AsyncMock, None, None]:
|
||||||
"""Mock a Bring client."""
|
"""Mock a Bring client."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.bring.Bring",
|
"homeassistant.components.bring.Bring",
|
||||||
@ -36,8 +36,8 @@ def mock_bring_client() -> Generator[Mock, None, None]:
|
|||||||
):
|
):
|
||||||
client = mock_client.return_value
|
client = mock_client.return_value
|
||||||
client.uuid = UUID
|
client.uuid = UUID
|
||||||
client.login.return_value = True
|
client.loginAsync.return_value = True
|
||||||
client.loadLists.return_value = {"lists": []}
|
client.loadListsAsync.return_value = {"lists": []}
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Test the Bring! config flow."""
|
"""Test the Bring! config flow."""
|
||||||
from unittest.mock import AsyncMock, Mock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from python_bring_api.exceptions import (
|
from python_bring_api.exceptions import (
|
||||||
@ -25,7 +25,7 @@ MOCK_DATA_STEP = {
|
|||||||
|
|
||||||
|
|
||||||
async def test_form(
|
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:
|
) -> None:
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
result = await hass.config_entries.flow.async_init(
|
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(
|
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:
|
) -> None:
|
||||||
"""Test unknown errors."""
|
"""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(
|
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.login.side_effect = None
|
mock_bring_client.loginAsync.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"}
|
||||||
)
|
)
|
||||||
@ -92,7 +92,9 @@ async def test_flow_user_init_data_unknown_error_and_recover(
|
|||||||
|
|
||||||
|
|
||||||
async def test_flow_user_init_data_already_configured(
|
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:
|
) -> None:
|
||||||
"""Test we abort user data set when entry is already configured."""
|
"""Test we abort user data set when entry is already configured."""
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Unit tests for the bring integration."""
|
"""Unit tests for the bring integration."""
|
||||||
from unittest.mock import Mock
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ async def setup_integration(
|
|||||||
|
|
||||||
async def test_load_unload(
|
async def test_load_unload(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_bring_client: Mock,
|
mock_bring_client: AsyncMock,
|
||||||
bring_config_entry: MockConfigEntry,
|
bring_config_entry: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test loading and unloading of the config entry."""
|
"""Test loading and unloading of the config entry."""
|
||||||
@ -52,12 +52,12 @@ async def test_load_unload(
|
|||||||
)
|
)
|
||||||
async def test_init_failure(
|
async def test_init_failure(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_bring_client: Mock,
|
mock_bring_client: AsyncMock,
|
||||||
status: ConfigEntryState,
|
status: ConfigEntryState,
|
||||||
exception: Exception,
|
exception: Exception,
|
||||||
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.login.side_effect = exception
|
mock_bring_client.loginAsync.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