Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
class PyiCloudException(Exception):
pass
class PyiCloudNoDevicesException(PyiCloudException):
pass
class PyiCloudAPIResponseError(PyiCloudException):
def __init__(self, reason, code):
self.reason = reason
self.code = code
message = reason
if code:
message += " (%s)" % code
super(PyiCloudAPIResponseError, self).__init__(message)
class PyiCloudFailedLoginException(PyiCloudException):
pass
class PyiCloud2SARequiredError(PyiCloudException):
def __init__(self, url):
class PyiCloudException(Exception):
pass
class PyiCloudNoDevicesException(PyiCloudException):
pass
class PyiCloudAPIResponseError(PyiCloudException):
def __init__(self, reason, code):
self.reason = reason
self.code = code
message = reason
if code:
message += " (%s)" % code
super(PyiCloudAPIResponseError, self).__init__(message)
class PyiCloudFailedLoginException(PyiCloudException):
pass
try:
if self._trusted_device is None:
self.icloud_need_trusted_device()
return
if self._verification_code is None:
self.icloud_need_verification_code()
return
self.api.authenticate()
if self.api.requires_2fa:
raise Exception("Unknown failure")
self._trusted_device = None
self._verification_code = None
except PyiCloudException as error:
_LOGGER.error("Error setting up 2FA: %s", error)
else:
self.api.authenticate()
currentminutes = dt_util.now().hour * 60 + dt_util.now().minute
try:
for devicename in self.devices:
interval = self._intervals.get(devicename, 1)
if (currentminutes % interval == 0) or (
interval > 10 and currentminutes % interval in [2, 4]
):
self.update_device(devicename)
except ValueError:
_LOGGER.debug("iCloud API returned an error")
class PyiCloudFailedLoginException(PyiCloudException):
pass
class PyiCloud2SARequiredError(PyiCloudException):
def __init__(self, url):
message = "Two-step authentication required for %s" % url
super(PyiCloud2SARequiredError, self).__init__(message)
class PyiCloudNoDevicesException(Exception):
pass
class NoStoredPasswordAvailable(PyiCloudException):
pass
class PyiCloudServiceNotActivatedErrror(PyiCloudAPIResponseError):
pass
class PyiCloudNoDevicesException(PyiCloudException):
pass
class PyiCloudAPIResponseError(PyiCloudException):
def __init__(self, reason, code):
self.reason = reason
self.code = code
message = reason
if code:
message += " (%s)" % code
super(PyiCloudAPIResponseError, self).__init__(message)
class PyiCloudFailedLoginException(PyiCloudException):
pass
class PyiCloud2SARequiredError(PyiCloudException):
def __init__(self, url):
message = "Two-step authentication required for %s" % url
super(PyiCloud2SARequiredError, self).__init__(message)
class PyiCloudNoDevicesException(Exception):
pass
class NoStoredPasswordAvailable(PyiCloudException):
pass
def icloud_verification_callback(self, callback_data):
"""Handle the chosen trusted device."""
self._verification_code = callback_data.get("code")
try:
if not self.api.validate_verification_code(
self._trusted_device, self._verification_code
):
raise PyiCloudException("Unknown failure")
except PyiCloudException as error:
# Reset to the initial 2FA state to allow the user to retry
_LOGGER.error("Failed to verify verification code: %s", error)
self._trusted_device = None
self._verification_code = None
# Trigger the next step immediately
self.icloud_need_trusted_device()
if self.accountname in _CONFIGURING:
request_id = _CONFIGURING.pop(self.accountname)
configurator = self.hass.components.configurator
configurator.request_done(request_id)