mirror of
https://github.com/home-assistant/core.git
synced 2026-09-06 05:22:44 +01:00
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Models for the cloud integration."""
|
|
|
|
import dataclasses
|
|
|
|
from hass_nabucasa import AutoLoginController, LoginFailedReason
|
|
|
|
# Spelled out rather than derived from the reason, so the keys stay greppable and
|
|
# a reason hass_nabucasa adds later does not silently point at a missing string.
|
|
AUTO_LOGIN_FAILED_TRANSLATION_KEYS = {
|
|
LoginFailedReason.CLOUD_ERROR: "auto_login_failed_cloud_error",
|
|
LoginFailedReason.TIMEOUT: "auto_login_failed_timeout",
|
|
LoginFailedReason.UNEXPECTED_ERROR: "auto_login_failed_unexpected_error",
|
|
}
|
|
|
|
|
|
def auto_login_failure_key(reason: LoginFailedReason | None) -> str | None:
|
|
"""Return the string to render for an auto-login that gave up."""
|
|
if reason is None:
|
|
return None
|
|
return AUTO_LOGIN_FAILED_TRANSLATION_KEYS.get(
|
|
reason, "auto_login_failed_unexpected_error"
|
|
)
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class PendingAutoLogin:
|
|
"""A registration waiting for its email confirmation to log in."""
|
|
|
|
email: str
|
|
controller: AutoLoginController | None
|
|
failed_reason: LoginFailedReason | None = None
|
|
|
|
def mark_failed(self, reason: LoginFailedReason) -> None:
|
|
"""Record that the retry loop gave up before logging in."""
|
|
self.controller = None
|
|
self.failed_reason = reason
|