mirror of
https://github.com/home-assistant/core.git
synced 2026-12-04 04:41:30 -04:00
Bump pyicloud to 2026.10.0 (#186146)
This commit is contained in:
@@ -7,6 +7,7 @@ from typing import TYPE_CHECKING, Any
|
||||
|
||||
from pyicloud import PyiCloudService
|
||||
from pyicloud.exceptions import (
|
||||
PyiCloudConnectionException,
|
||||
PyiCloudFailedLoginException,
|
||||
PyiCloudNoDevicesException,
|
||||
PyiCloudServiceNotActivatedException,
|
||||
@@ -113,8 +114,18 @@ class IcloudAccount:
|
||||
self._password,
|
||||
self._icloud_dir.path,
|
||||
with_family=self._with_family,
|
||||
refresh_interval=None,
|
||||
)
|
||||
|
||||
except PyiCloudConnectionException as err:
|
||||
# iCloud is unreachable; this says nothing about the credentials, so
|
||||
# let the config entry retry instead of asking the user to log in.
|
||||
raise ConfigEntryNotReady(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="cannot_connect",
|
||||
translation_placeholders={"error": str(err)},
|
||||
) from err
|
||||
|
||||
except PyiCloudFailedLoginException:
|
||||
self.api = None
|
||||
# Login failed which means credentials/2fa need to be updated.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Config flow to configure the iCloud integration."""
|
||||
|
||||
from collections.abc import Mapping
|
||||
from functools import partial
|
||||
import logging
|
||||
import os
|
||||
from typing import TYPE_CHECKING, Any, override
|
||||
@@ -8,6 +9,7 @@ from typing import TYPE_CHECKING, Any, override
|
||||
import probatio
|
||||
from pyicloud import PyiCloudService
|
||||
from pyicloud.exceptions import (
|
||||
PyiCloudConnectionException,
|
||||
PyiCloudException,
|
||||
PyiCloudFailedLoginException,
|
||||
PyiCloudNoDevicesException,
|
||||
@@ -147,19 +149,25 @@ class IcloudFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
if self.api is None:
|
||||
try:
|
||||
self.api = await self.hass.async_add_executor_job(
|
||||
PyiCloudService,
|
||||
self._username,
|
||||
self._password,
|
||||
Store(self.hass, STORAGE_VERSION, STORAGE_KEY).path,
|
||||
True,
|
||||
None,
|
||||
self._with_family,
|
||||
partial(
|
||||
PyiCloudService,
|
||||
self._username,
|
||||
self._password,
|
||||
Store(self.hass, STORAGE_VERSION, STORAGE_KEY).path,
|
||||
with_family=self._with_family,
|
||||
refresh_interval=None,
|
||||
)
|
||||
)
|
||||
except PyiCloudFailedLoginException as error:
|
||||
_LOGGER.error("Error logging into iCloud service: %s", error)
|
||||
self.api = None
|
||||
errors = {CONF_PASSWORD: "invalid_auth"}
|
||||
return self._show_setup_form(user_input, errors, step_id)
|
||||
except PyiCloudConnectionException as error:
|
||||
_LOGGER.error("Error connecting to iCloud service: %s", error)
|
||||
self.api = None
|
||||
errors = {"base": "cannot_connect"}
|
||||
return self._show_setup_form(user_input, errors, step_id)
|
||||
|
||||
if self.api.requires_2fa:
|
||||
return await self.async_step_verification_code()
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
"integration_type": "hub",
|
||||
"iot_class": "cloud_polling",
|
||||
"loggers": ["keyrings.alt", "pyicloud"],
|
||||
"requirements": ["pyicloud==2.7.0"]
|
||||
"requirements": ["pyicloud==2026.10.0"]
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"send_verification_code": "Failed to send verification code",
|
||||
"validate_verification_code": "Failed to verify your verification code, try again"
|
||||
@@ -55,6 +56,9 @@
|
||||
"album_type_not_specified": {
|
||||
"message": "Album type not specified"
|
||||
},
|
||||
"cannot_connect": {
|
||||
"message": "An error occurred while connecting to iCloud: {error}"
|
||||
},
|
||||
"config_entry_not_found": {
|
||||
"message": "Config entry not found for account: {entry}"
|
||||
},
|
||||
|
||||
Generated
+1
-1
@@ -2311,7 +2311,7 @@ pyhomeworks==1.1.2
|
||||
pyialarm==2.2.0
|
||||
|
||||
# homeassistant.components.icloud
|
||||
pyicloud==2.7.0
|
||||
pyicloud==2026.10.0
|
||||
|
||||
# homeassistant.components.imou
|
||||
pyimouapi==1.4.0
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from pyicloud.exceptions import PyiCloudConnectionException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.icloud.account import IcloudAccount
|
||||
@@ -135,7 +136,41 @@ def mock_icloud_service_fixture():
|
||||
service_instance.requires_2fa = False
|
||||
|
||||
service_mock.return_value = service_instance
|
||||
yield service_instance
|
||||
yield service_mock
|
||||
|
||||
|
||||
async def test_setup_connection_error(
|
||||
hass: HomeAssistant,
|
||||
mock_store: Mock,
|
||||
) -> None:
|
||||
"""Test a transport failure during setup asks for a retry."""
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data=MOCK_CONFIG, entry_id="test", unique_id=USERNAME
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
account = IcloudAccount(
|
||||
hass,
|
||||
MOCK_CONFIG[CONF_USERNAME],
|
||||
MOCK_CONFIG[CONF_PASSWORD],
|
||||
mock_store,
|
||||
MOCK_CONFIG[CONF_WITH_FAMILY],
|
||||
MOCK_CONFIG[CONF_MAX_INTERVAL],
|
||||
MOCK_CONFIG[CONF_GPS_ACCURACY_THRESHOLD],
|
||||
config_entry,
|
||||
)
|
||||
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.icloud.account.PyiCloudService",
|
||||
side_effect=PyiCloudConnectionException(reason="Connection error"),
|
||||
),
|
||||
pytest.raises(ConfigEntryNotReady) as err,
|
||||
):
|
||||
account.setup()
|
||||
|
||||
assert err.value.translation_key == "cannot_connect"
|
||||
|
||||
|
||||
async def test_setup_success_with_devices(
|
||||
@@ -172,5 +207,7 @@ async def test_setup_success_with_devices(
|
||||
assert account.family_members_fullname["johntravolta"] == "John TRAVOLTA"
|
||||
# An active locate must be requested on every poll (pyicloud >= 2.3.0
|
||||
# only locates at service creation, so the account has to ask for it)
|
||||
assert mock_icloud_service.devices.refresh_calls == [True]
|
||||
assert mock_icloud_service.return_value.devices.refresh_calls == [True]
|
||||
assert "device1" in account.devices
|
||||
# The account polls devices itself, so pyicloud's own Find My monitor is disabled.
|
||||
assert mock_icloud_service.call_args.kwargs["refresh_interval"] is None
|
||||
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from pyicloud.exceptions import (
|
||||
PyiCloudAPIResponseException,
|
||||
PyiCloudConnectionException,
|
||||
PyiCloudFailedLoginException,
|
||||
)
|
||||
import pytest
|
||||
@@ -282,6 +283,53 @@ async def test_login_failed(hass: HomeAssistant) -> None:
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("service_authenticated")
|
||||
async def test_connection_error(hass: HomeAssistant) -> None:
|
||||
"""Test when iCloud is unreachable during login."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.icloud.config_flow.PyiCloudService",
|
||||
side_effect=PyiCloudConnectionException(reason="Connection error"),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
|
||||
|
||||
async def test_user_disables_pyicloud_monitor(
|
||||
hass: HomeAssistant, service_authenticated: MagicMock
|
||||
) -> None:
|
||||
"""Test the config flow disables pyicloud's own Find My monitor."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": SOURCE_USER},
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
user_input={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
|
||||
)
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == USERNAME
|
||||
assert service_authenticated.call_args.kwargs["refresh_interval"] is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("service_authenticated_no_device")
|
||||
async def test_no_device(hass: HomeAssistant) -> None:
|
||||
"""Test when we have no devices."""
|
||||
|
||||
Reference in New Issue
Block a user