Move imports to top for websocket_api (#29556)

* Move imports to top for websocket_api

* Move back an import because of circular dependency, add annotations
This commit is contained in:
springstan 2019-12-08 12:19:15 +01:00 committed by Paulus Schoutsen
parent 21cf6777bb
commit 6de8072e8a
10 changed files with 23 additions and 28 deletions

View file

@ -4,7 +4,6 @@ from homeassistant.loader import bind_hass
from . import commands, connection, const, decorators, http, messages from . import commands, connection, const, decorators, http, messages
# mypy: allow-untyped-calls, allow-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs
DOMAIN = const.DOMAIN DOMAIN = const.DOMAIN

View file

@ -3,13 +3,12 @@ import voluptuous as vol
from voluptuous.humanize import humanize_error from voluptuous.humanize import humanize_error
from homeassistant.auth.models import RefreshToken, User from homeassistant.auth.models import RefreshToken, User
from homeassistant.components.http.ban import process_wrong_login, process_success_login from homeassistant.components.http.ban import process_success_login, process_wrong_login
from homeassistant.const import __version__ from homeassistant.const import __version__
from .connection import ActiveConnection from .connection import ActiveConnection
from .error import Disconnect from .error import Disconnect
# mypy: allow-untyped-calls, allow-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs
TYPE_AUTH = "auth" TYPE_AUTH = "auth"

View file

@ -2,16 +2,15 @@
import voluptuous as vol import voluptuous as vol
from homeassistant.auth.permissions.const import POLICY_READ from homeassistant.auth.permissions.const import POLICY_READ
from homeassistant.const import MATCH_ALL, EVENT_TIME_CHANGED, EVENT_STATE_CHANGED from homeassistant.const import EVENT_STATE_CHANGED, EVENT_TIME_CHANGED, MATCH_ALL
from homeassistant.core import callback, DOMAIN as HASS_DOMAIN from homeassistant.core import DOMAIN as HASS_DOMAIN, callback
from homeassistant.exceptions import Unauthorized, ServiceNotFound, HomeAssistantError from homeassistant.exceptions import HomeAssistantError, ServiceNotFound, Unauthorized
from homeassistant.helpers import config_validation as cv from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.service import async_get_all_descriptions
from homeassistant.helpers.event import async_track_state_change from homeassistant.helpers.event import async_track_state_change
from homeassistant.helpers.service import async_get_all_descriptions
from . import const, decorators, messages from . import const, decorators, messages
# mypy: allow-untyped-calls, allow-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs
@ -45,6 +44,8 @@ def handle_subscribe_events(hass, connection, msg):
Async friendly. Async friendly.
""" """
# Circular dep
# pylint: disable=import-outside-toplevel
from .permissions import SUBSCRIBE_WHITELIST from .permissions import SUBSCRIBE_WHITELIST
event_type = msg["event_type"] event_type = msg["event_type"]

View file

@ -4,12 +4,11 @@ from typing import Any, Callable, Dict, Hashable
import voluptuous as vol import voluptuous as vol
from homeassistant.core import callback, Context from homeassistant.core import Context, callback
from homeassistant.exceptions import Unauthorized from homeassistant.exceptions import Unauthorized
from . import const, messages from . import const, messages
# mypy: allow-untyped-calls, allow-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs

View file

@ -3,6 +3,7 @@ import asyncio
from concurrent import futures from concurrent import futures
from functools import partial from functools import partial
import json import json
from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.json import JSONEncoder
DOMAIN = "websocket_api" DOMAIN = "websocket_api"

View file

@ -7,7 +7,6 @@ from homeassistant.exceptions import Unauthorized
from . import messages from . import messages
# mypy: allow-untyped-calls, allow-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -4,28 +4,27 @@ from contextlib import suppress
import logging import logging
from typing import Optional from typing import Optional
from aiohttp import web, WSMsgType from aiohttp import WSMsgType, web
import async_timeout import async_timeout
from homeassistant.components.http import HomeAssistantView
from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.components.http import HomeAssistantView
from .auth import AuthPhase, auth_required_message
from .const import ( from .const import (
MAX_PENDING_MSG,
CANCELLATION_ERRORS, CANCELLATION_ERRORS,
URL, DATA_CONNECTIONS,
ERR_UNKNOWN_ERROR, ERR_UNKNOWN_ERROR,
JSON_DUMP,
MAX_PENDING_MSG,
SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_CONNECTED,
SIGNAL_WEBSOCKET_DISCONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED,
DATA_CONNECTIONS, URL,
JSON_DUMP,
) )
from .auth import AuthPhase, auth_required_message
from .error import Disconnect from .error import Disconnect
from .messages import error_message from .messages import error_message
# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs

View file

@ -6,7 +6,6 @@ from homeassistant.helpers import config_validation as cv
from . import const from . import const
# mypy: allow-untyped-defs # mypy: allow-untyped-defs
# Minimal requirements of a message # Minimal requirements of a message

View file

@ -2,22 +2,22 @@
Separate file to avoid circular imports. Separate file to avoid circular imports.
""" """
from homeassistant.components.frontend import EVENT_PANELS_UPDATED
from homeassistant.components.lovelace import EVENT_LOVELACE_UPDATED
from homeassistant.components.persistent_notification import (
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED,
)
from homeassistant.const import ( from homeassistant.const import (
EVENT_COMPONENT_LOADED, EVENT_COMPONENT_LOADED,
EVENT_CORE_CONFIG_UPDATE,
EVENT_SERVICE_REGISTERED, EVENT_SERVICE_REGISTERED,
EVENT_SERVICE_REMOVED, EVENT_SERVICE_REMOVED,
EVENT_STATE_CHANGED, EVENT_STATE_CHANGED,
EVENT_THEMES_UPDATED, EVENT_THEMES_UPDATED,
EVENT_CORE_CONFIG_UPDATE,
) )
from homeassistant.components.persistent_notification import (
EVENT_PERSISTENT_NOTIFICATIONS_UPDATED,
)
from homeassistant.components.lovelace import EVENT_LOVELACE_UPDATED
from homeassistant.helpers.area_registry import EVENT_AREA_REGISTRY_UPDATED from homeassistant.helpers.area_registry import EVENT_AREA_REGISTRY_UPDATED
from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED from homeassistant.helpers.device_registry import EVENT_DEVICE_REGISTRY_UPDATED
from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED from homeassistant.helpers.entity_registry import EVENT_ENTITY_REGISTRY_UPDATED
from homeassistant.components.frontend import EVENT_PANELS_UPDATED
# These are events that do not contain any sensitive data # These are events that do not contain any sensitive data
# Except for state_changed, which is handled accordingly. # Except for state_changed, which is handled accordingly.

View file

@ -4,12 +4,11 @@ from homeassistant.core import callback
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from .const import ( from .const import (
DATA_CONNECTIONS,
SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_CONNECTED,
SIGNAL_WEBSOCKET_DISCONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED,
DATA_CONNECTIONS,
) )
# mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs # mypy: allow-untyped-calls, allow-untyped-defs, no-check-untyped-defs