Add devices check to iCloud config flow (#31950)
* Add devices check to iCloud config flow * Some test rename * Bump pyicloud to catch KeyError
This commit is contained in:
1 parent
8c52e2c923
commit
2e802c88f8
8 files changed
+64
-15
No files matched your search
@@ -1,7 +1,8 @@
|
||||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"already_configured": "Account already configured"
|
||||
"already_configured": "Account already configured",
|
||||
"no_device": "None of your devices have \"Find my iPhone\" activated"
|
||||
},
|
||||
"error": {
|
||||
"login": "Login error: please check your email & password",
|
||||
|
||||
@@ -5,7 +5,11 @@ import operator
|
||||
from typing import Dict
|
||||
|
||||
from pyicloud import PyiCloudService
|
||||
from pyicloud.exceptions import PyiCloudFailedLoginException, PyiCloudNoDevicesException
|
||||
from pyicloud.exceptions import (
|
||||
PyiCloudFailedLoginException,
|
||||
PyiCloudNoDevicesException,
|
||||
PyiCloudServiceNotActivatedException,
|
||||
)
|
||||
from pyicloud.services.findmyiphone import AppleDevice
|
||||
|
||||
from homeassistant.components.zone import async_active_zone
|
||||
@@ -109,7 +113,7 @@ class IcloudAccount:
|
||||
api_devices = self.api.devices
|
||||
# Gets device owners infos
|
||||
user_info = api_devices.response["userInfo"]
|
||||
except (KeyError, PyiCloudNoDevicesException):
|
||||
except (PyiCloudServiceNotActivatedException, PyiCloudNoDevicesException):
|
||||
_LOGGER.error("No iCloud device found")
|
||||
raise ConfigEntryNotReady
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@ import logging
|
||||
import os
|
||||
|
||||
from pyicloud import PyiCloudService
|
||||
from pyicloud.exceptions import PyiCloudException, PyiCloudFailedLoginException
|
||||
from pyicloud.exceptions import (
|
||||
PyiCloudException,
|
||||
PyiCloudFailedLoginException,
|
||||
PyiCloudNoDevicesException,
|
||||
PyiCloudServiceNotActivatedException,
|
||||
)
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
@@ -101,6 +106,17 @@ class IcloudFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
if self.api.requires_2sa:
|
||||
return await self.async_step_trusted_device()
|
||||
|
||||
try:
|
||||
devices = await self.hass.async_add_executor_job(
|
||||
getattr, self.api, "devices"
|
||||
)
|
||||
if not devices:
|
||||
raise PyiCloudNoDevicesException()
|
||||
except (PyiCloudServiceNotActivatedException, PyiCloudNoDevicesException):
|
||||
_LOGGER.error("No device found in the iCloud account: %s", self._username)
|
||||
self.api = None
|
||||
return self.async_abort(reason="no_device")
|
||||
|
||||
return self.async_create_entry(
|
||||
title=self._username,
|
||||
data={
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Apple iCloud",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/icloud",
|
||||
"requirements": ["pyicloud==0.9.3"],
|
||||
"requirements": ["pyicloud==0.9.4"],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@Quentame"]
|
||||
}
|
||||
@@ -31,7 +31,8 @@
|
||||
"validate_verification_code": "Failed to verify your verification code, choose a trust device and start the verification again"
|
||||
},
|
||||
"abort": {
|
||||
"already_configured": "Account already configured"
|
||||
"already_configured": "Account already configured",
|
||||
"no_device": "None of your devices have \"Find my iPhone\" activated"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user