mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Move icloud imports at top-level (#29089)
This commit is contained in:
parent
c47ed743f1
commit
78d5184186
@ -1,25 +1,31 @@
|
|||||||
"""Platform that supports scanning iCloud."""
|
"""Platform that supports scanning iCloud."""
|
||||||
import logging
|
import logging
|
||||||
import random
|
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
|
from pyicloud import PyiCloudService
|
||||||
|
from pyicloud.exceptions import (
|
||||||
|
PyiCloudException,
|
||||||
|
PyiCloudFailedLoginException,
|
||||||
|
PyiCloudNoDevicesException,
|
||||||
|
)
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
|
||||||
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
|
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
|
||||||
from homeassistant.components.device_tracker.const import (
|
from homeassistant.components.device_tracker.const import (
|
||||||
DOMAIN,
|
|
||||||
ATTR_ATTRIBUTES,
|
ATTR_ATTRIBUTES,
|
||||||
|
DOMAIN,
|
||||||
ENTITY_ID_FORMAT,
|
ENTITY_ID_FORMAT,
|
||||||
)
|
)
|
||||||
from homeassistant.components.device_tracker.legacy import DeviceScanner
|
from homeassistant.components.device_tracker.legacy import DeviceScanner
|
||||||
from homeassistant.components.zone import async_active_zone
|
from homeassistant.components.zone import async_active_zone
|
||||||
from homeassistant.helpers.event import track_utc_time_change
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
from homeassistant.helpers.event import track_utc_time_change
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
|
from homeassistant.util.async_ import run_callback_threadsafe
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
from homeassistant.util.location import distance
|
from homeassistant.util.location import distance
|
||||||
from homeassistant.util.async_ import run_callback_threadsafe
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -214,12 +220,6 @@ class Icloud(DeviceScanner):
|
|||||||
|
|
||||||
def reset_account_icloud(self):
|
def reset_account_icloud(self):
|
||||||
"""Reset an iCloud account."""
|
"""Reset an iCloud account."""
|
||||||
from pyicloud import PyiCloudService
|
|
||||||
from pyicloud.exceptions import (
|
|
||||||
PyiCloudFailedLoginException,
|
|
||||||
PyiCloudNoDevicesException,
|
|
||||||
)
|
|
||||||
|
|
||||||
icloud_dir = self.hass.config.path("icloud")
|
icloud_dir = self.hass.config.path("icloud")
|
||||||
if not os.path.exists(icloud_dir):
|
if not os.path.exists(icloud_dir):
|
||||||
os.makedirs(icloud_dir)
|
os.makedirs(icloud_dir)
|
||||||
@ -297,8 +297,6 @@ class Icloud(DeviceScanner):
|
|||||||
|
|
||||||
def icloud_verification_callback(self, callback_data):
|
def icloud_verification_callback(self, callback_data):
|
||||||
"""Handle the chosen trusted device."""
|
"""Handle the chosen trusted device."""
|
||||||
from pyicloud.exceptions import PyiCloudException
|
|
||||||
|
|
||||||
self._verification_code = callback_data.get("code")
|
self._verification_code = callback_data.get("code")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -344,8 +342,6 @@ class Icloud(DeviceScanner):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.api.requires_2fa:
|
if self.api.requires_2fa:
|
||||||
from pyicloud.exceptions import PyiCloudException
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self._trusted_device is None:
|
if self._trusted_device is None:
|
||||||
self.icloud_need_trusted_device()
|
self.icloud_need_trusted_device()
|
||||||
@ -436,8 +432,6 @@ class Icloud(DeviceScanner):
|
|||||||
|
|
||||||
def update_device(self, devicename):
|
def update_device(self, devicename):
|
||||||
"""Update the device_tracker entity."""
|
"""Update the device_tracker entity."""
|
||||||
from pyicloud.exceptions import PyiCloudNoDevicesException
|
|
||||||
|
|
||||||
# An entity will not be created by see() when track=false in
|
# An entity will not be created by see() when track=false in
|
||||||
# 'known_devices.yaml', but we need to see() it at least once
|
# 'known_devices.yaml', but we need to see() it at least once
|
||||||
entity = self.hass.states.get(ENTITY_ID_FORMAT.format(devicename))
|
entity = self.hass.states.get(ENTITY_ID_FORMAT.format(devicename))
|
||||||
@ -503,8 +497,6 @@ class Icloud(DeviceScanner):
|
|||||||
|
|
||||||
def update_icloud(self, devicename=None):
|
def update_icloud(self, devicename=None):
|
||||||
"""Request device information from iCloud and update device_tracker."""
|
"""Request device information from iCloud and update device_tracker."""
|
||||||
from pyicloud.exceptions import PyiCloudNoDevicesException
|
|
||||||
|
|
||||||
if self.api is None:
|
if self.api is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user