Move imports in cloud component (#27881)

This commit is contained in:
bouni 2019-10-19 00:39:37 +02:00 committed by Paulus Schoutsen
parent b2b140e8d0
commit 1d8e366278
2 changed files with 14 additions and 17 deletions

View file

@ -1,6 +1,7 @@
"""Component to integrate the Home Assistant cloud.""" """Component to integrate the Home Assistant cloud."""
import logging import logging
from hass_nabucasa import Cloud
import voluptuous as vol import voluptuous as vol
from homeassistant.auth.const import GROUP_ID_ADMIN from homeassistant.auth.const import GROUP_ID_ADMIN
@ -20,25 +21,26 @@ from homeassistant.loader import bind_hass
from homeassistant.util.aiohttp import MockRequest from homeassistant.util.aiohttp import MockRequest
from . import http_api from . import http_api
from .client import CloudClient
from .const import ( from .const import (
CONF_ACME_DIRECTORY_SERVER, CONF_ACME_DIRECTORY_SERVER,
CONF_ALEXA, CONF_ALEXA,
CONF_ALEXA_ACCESS_TOKEN_URL,
CONF_ALIASES, CONF_ALIASES,
CONF_CLOUDHOOK_CREATE_URL, CONF_CLOUDHOOK_CREATE_URL,
CONF_COGNITO_CLIENT_ID, CONF_COGNITO_CLIENT_ID,
CONF_ENTITY_CONFIG, CONF_ENTITY_CONFIG,
CONF_FILTER, CONF_FILTER,
CONF_GOOGLE_ACTIONS, CONF_GOOGLE_ACTIONS,
CONF_GOOGLE_ACTIONS_REPORT_STATE_URL,
CONF_GOOGLE_ACTIONS_SYNC_URL, CONF_GOOGLE_ACTIONS_SYNC_URL,
CONF_RELAYER, CONF_RELAYER,
CONF_REMOTE_API_URL, CONF_REMOTE_API_URL,
CONF_SUBSCRIPTION_INFO_URL, CONF_SUBSCRIPTION_INFO_URL,
CONF_USER_POOL_ID, CONF_USER_POOL_ID,
CONF_GOOGLE_ACTIONS_REPORT_STATE_URL,
DOMAIN, DOMAIN,
MODE_DEV, MODE_DEV,
MODE_PROD, MODE_PROD,
CONF_ALEXA_ACCESS_TOKEN_URL,
) )
from .prefs import CloudPreferences from .prefs import CloudPreferences
@ -166,8 +168,6 @@ def is_cloudhook_request(request):
async def async_setup(hass, config): async def async_setup(hass, config):
"""Initialize the Home Assistant cloud.""" """Initialize the Home Assistant cloud."""
from hass_nabucasa import Cloud
from .client import CloudClient
# Process configs # Process configs
if DOMAIN in config: if DOMAIN in config:

View file

@ -3,33 +3,34 @@ import asyncio
from functools import wraps from functools import wraps
import logging import logging
import attr
import aiohttp import aiohttp
import async_timeout import async_timeout
import attr
from hass_nabucasa import Cloud, auth
from hass_nabucasa.const import STATE_DISCONNECTED
import voluptuous as vol import voluptuous as vol
from hass_nabucasa import Cloud
from homeassistant.core import callback
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components import websocket_api from homeassistant.components import websocket_api
from homeassistant.components.websocket_api import const as ws_const
from homeassistant.components.alexa import ( from homeassistant.components.alexa import (
entities as alexa_entities, entities as alexa_entities,
errors as alexa_errors, errors as alexa_errors,
) )
from homeassistant.components.google_assistant import helpers as google_helpers from homeassistant.components.google_assistant import helpers as google_helpers
from homeassistant.components.http import HomeAssistantView
from homeassistant.components.http.data_validator import RequestDataValidator
from homeassistant.components.websocket_api import const as ws_const
from homeassistant.core import callback
from .const import ( from .const import (
DOMAIN, DOMAIN,
REQUEST_TIMEOUT, PREF_ALEXA_REPORT_STATE,
PREF_ENABLE_ALEXA, PREF_ENABLE_ALEXA,
PREF_ENABLE_GOOGLE, PREF_ENABLE_GOOGLE,
PREF_GOOGLE_REPORT_STATE,
PREF_GOOGLE_SECURE_DEVICES_PIN, PREF_GOOGLE_SECURE_DEVICES_PIN,
REQUEST_TIMEOUT,
InvalidTrustedNetworks, InvalidTrustedNetworks,
InvalidTrustedProxies, InvalidTrustedProxies,
PREF_ALEXA_REPORT_STATE,
PREF_GOOGLE_REPORT_STATE,
RequireRelink, RequireRelink,
) )
@ -104,8 +105,6 @@ async def async_setup(hass):
hass.http.register_view(CloudResendConfirmView) hass.http.register_view(CloudResendConfirmView)
hass.http.register_view(CloudForgotPasswordView) hass.http.register_view(CloudForgotPasswordView)
from hass_nabucasa import auth
_CLOUD_ERRORS.update( _CLOUD_ERRORS.update(
{ {
auth.UserNotFound: (400, "User does not exist."), auth.UserNotFound: (400, "User does not exist."),
@ -320,7 +319,6 @@ def _require_cloud_login(handler):
@websocket_api.async_response @websocket_api.async_response
async def websocket_subscription(hass, connection, msg): async def websocket_subscription(hass, connection, msg):
"""Handle request for account info.""" """Handle request for account info."""
from hass_nabucasa.const import STATE_DISCONNECTED
cloud = hass.data[DOMAIN] cloud = hass.data[DOMAIN]
@ -417,7 +415,6 @@ async def websocket_hook_delete(hass, connection, msg):
def _account_data(cloud): def _account_data(cloud):
"""Generate the auth data JSON response.""" """Generate the auth data JSON response."""
from hass_nabucasa.const import STATE_DISCONNECTED
if not cloud.is_logged_in: if not cloud.is_logged_in:
return {"logged_in": False, "cloud": STATE_DISCONNECTED} return {"logged_in": False, "cloud": STATE_DISCONNECTED}