From 3e9d28f28a92900a44a682c85d645000bcec7c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diefferson=20Koderer=20M=C3=B4ro?= Date: Mon, 21 Oct 2019 05:05:41 -0300 Subject: [PATCH] Move imports in mobile_app component (#28027) --- homeassistant/components/mobile_app/__init__.py | 3 +-- homeassistant/components/mobile_app/binary_sensor.py | 3 +-- homeassistant/components/mobile_app/config_flow.py | 3 ++- homeassistant/components/mobile_app/const.py | 2 +- .../components/mobile_app/device_tracker.py | 9 +++++---- homeassistant/components/mobile_app/helpers.py | 12 +++++------- homeassistant/components/mobile_app/http_api.py | 12 +++++------- homeassistant/components/mobile_app/notify.py | 1 - homeassistant/components/mobile_app/sensor.py | 1 - homeassistant/components/mobile_app/webhook.py | 12 ++++-------- homeassistant/components/mobile_app/websocket_api.py | 1 - 11 files changed, 24 insertions(+), 35 deletions(-) diff --git a/homeassistant/components/mobile_app/__init__.py b/homeassistant/components/mobile_app/__init__.py index 01877099201..ca2a58d1f96 100644 --- a/homeassistant/components/mobile_app/__init__.py +++ b/homeassistant/components/mobile_app/__init__.py @@ -1,6 +1,6 @@ """Integrates Native Apps to Home Assistant.""" -from homeassistant.const import CONF_WEBHOOK_ID from homeassistant.components.webhook import async_register as webhook_register +from homeassistant.const import CONF_WEBHOOK_ID from homeassistant.helpers import device_registry as dr, discovery from homeassistant.helpers.typing import ConfigType, HomeAssistantType @@ -20,7 +20,6 @@ from .const import ( STORAGE_KEY, STORAGE_VERSION, ) - from .http_api import RegistrationsView from .webhook import handle_webhook from .websocket_api import register_websocket_handlers diff --git a/homeassistant/components/mobile_app/binary_sensor.py b/homeassistant/components/mobile_app/binary_sensor.py index 975c4c16c32..73bf925553e 100644 --- a/homeassistant/components/mobile_app/binary_sensor.py +++ b/homeassistant/components/mobile_app/binary_sensor.py @@ -1,9 +1,9 @@ """Binary sensor platform for mobile_app.""" from functools import partial +from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.const import CONF_WEBHOOK_ID from homeassistant.core import callback -from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import ( @@ -13,7 +13,6 @@ from .const import ( DATA_DEVICES, DOMAIN, ) - from .entity import MobileAppEntity, sensor_id diff --git a/homeassistant/components/mobile_app/config_flow.py b/homeassistant/components/mobile_app/config_flow.py index 96b0a35aae2..bc9c6167da8 100644 --- a/homeassistant/components/mobile_app/config_flow.py +++ b/homeassistant/components/mobile_app/config_flow.py @@ -1,6 +1,7 @@ """Config flow for Mobile App.""" from homeassistant import config_entries -from .const import DOMAIN, ATTR_DEVICE_NAME + +from .const import ATTR_DEVICE_NAME, DOMAIN @config_entries.HANDLERS.register(DOMAIN) diff --git a/homeassistant/components/mobile_app/const.py b/homeassistant/components/mobile_app/const.py index d01990b74b9..0b6a93a39ea 100644 --- a/homeassistant/components/mobile_app/const.py +++ b/homeassistant/components/mobile_app/const.py @@ -4,13 +4,13 @@ import voluptuous as vol from homeassistant.components.binary_sensor import ( DEVICE_CLASSES as BINARY_SENSOR_CLASSES, ) -from homeassistant.components.sensor import DEVICE_CLASSES as SENSOR_CLASSES from homeassistant.components.device_tracker import ( ATTR_BATTERY, ATTR_GPS, ATTR_GPS_ACCURACY, ATTR_LOCATION_NAME, ) +from homeassistant.components.sensor import DEVICE_CLASSES as SENSOR_CLASSES from homeassistant.const import ATTR_DOMAIN, ATTR_SERVICE, ATTR_SERVICE_DATA from homeassistant.helpers import config_validation as cv diff --git a/homeassistant/components/mobile_app/device_tracker.py b/homeassistant/components/mobile_app/device_tracker.py index 0e05c424609..f58f80aa5fc 100644 --- a/homeassistant/components/mobile_app/device_tracker.py +++ b/homeassistant/components/mobile_app/device_tracker.py @@ -1,19 +1,20 @@ """Device tracker platform that adds support for OwnTracks over MQTT.""" import logging -from homeassistant.core import callback -from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, ATTR_BATTERY_LEVEL -from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS from homeassistant.components.device_tracker.config_entry import TrackerEntity +from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS +from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_LATITUDE, ATTR_LONGITUDE +from homeassistant.core import callback from homeassistant.helpers.restore_state import RestoreEntity + from .const import ( ATTR_ALTITUDE, ATTR_BATTERY, ATTR_COURSE, ATTR_DEVICE_ID, ATTR_DEVICE_NAME, - ATTR_GPS_ACCURACY, ATTR_GPS, + ATTR_GPS_ACCURACY, ATTR_LOCATION_NAME, ATTR_SPEED, ATTR_VERTICAL_ACCURACY, diff --git a/homeassistant/components/mobile_app/helpers.py b/homeassistant/components/mobile_app/helpers.py index 3be082951c5..2fb949720d6 100644 --- a/homeassistant/components/mobile_app/helpers.py +++ b/homeassistant/components/mobile_app/helpers.py @@ -1,9 +1,11 @@ """Helpers for mobile_app.""" -import logging import json +import logging from typing import Callable, Dict, Tuple -from aiohttp.web import json_response, Response +from aiohttp.web import Response, json_response +from nacl.encoding import Base64Encoder +from nacl.secret import SecretBox from homeassistant.core import Context from homeassistant.helpers.json import JSONEncoder @@ -13,8 +15,8 @@ from .const import ( ATTR_APP_DATA, ATTR_APP_ID, ATTR_APP_NAME, - ATTR_DEVICE_ID, ATTR_APP_VERSION, + ATTR_DEVICE_ID, ATTR_DEVICE_NAME, ATTR_MANUFACTURER, ATTR_MODEL, @@ -36,8 +38,6 @@ def setup_decrypt() -> Tuple[int, Callable]: Async friendly. """ - from nacl.secret import SecretBox - from nacl.encoding import Base64Encoder def decrypt(ciphertext, key): """Decrypt ciphertext using key.""" @@ -51,8 +51,6 @@ def setup_encrypt() -> Tuple[int, Callable]: Async friendly. """ - from nacl.secret import SecretBox - from nacl.encoding import Base64Encoder def encrypt(ciphertext, key): """Encrypt ciphertext using key.""" diff --git a/homeassistant/components/mobile_app/http_api.py b/homeassistant/components/mobile_app/http_api.py index 67914ea7076..ee69f15fb11 100644 --- a/homeassistant/components/mobile_app/http_api.py +++ b/homeassistant/components/mobile_app/http_api.py @@ -1,18 +1,19 @@ """Provides an HTTP API for mobile_app.""" -import uuid from typing import Dict +import uuid -from aiohttp.web import Response, Request +from aiohttp.web import Request, Response +from nacl.secret import SecretBox from homeassistant.auth.util import generate_secret from homeassistant.components.cloud import ( + CloudNotAvailable, async_create_cloudhook, async_remote_ui_url, - CloudNotAvailable, ) from homeassistant.components.http import HomeAssistantView from homeassistant.components.http.data_validator import RequestDataValidator -from homeassistant.const import HTTP_CREATED, CONF_WEBHOOK_ID +from homeassistant.const import CONF_WEBHOOK_ID, HTTP_CREATED from .const import ( ATTR_DEVICE_ID, @@ -24,7 +25,6 @@ from .const import ( DOMAIN, REGISTRATION_SCHEMA, ) - from .helpers import supports_encryption @@ -49,8 +49,6 @@ class RegistrationsView(HomeAssistantView): data[CONF_WEBHOOK_ID] = webhook_id if data[ATTR_SUPPORTS_ENCRYPTION] and supports_encryption(): - from nacl.secret import SecretBox - data[CONF_SECRET] = generate_secret(SecretBox.KEY_SIZE) data[CONF_USER_ID] = request["hass_user"].id diff --git a/homeassistant/components/mobile_app/notify.py b/homeassistant/components/mobile_app/notify.py index 1e6a0517026..8ac34c9af1d 100644 --- a/homeassistant/components/mobile_app/notify.py +++ b/homeassistant/components/mobile_app/notify.py @@ -12,7 +12,6 @@ from homeassistant.components.notify import ( ATTR_TITLE_DEFAULT, BaseNotificationService, ) - from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.util.dt as dt_util diff --git a/homeassistant/components/mobile_app/sensor.py b/homeassistant/components/mobile_app/sensor.py index b96a6f1e2f0..199ba968dd2 100644 --- a/homeassistant/components/mobile_app/sensor.py +++ b/homeassistant/components/mobile_app/sensor.py @@ -13,7 +13,6 @@ from .const import ( DATA_DEVICES, DOMAIN, ) - from .entity import MobileAppEntity, sensor_id diff --git a/homeassistant/components/mobile_app/webhook.py b/homeassistant/components/mobile_app/webhook.py index f95d5b993f0..66188500fd6 100644 --- a/homeassistant/components/mobile_app/webhook.py +++ b/homeassistant/components/mobile_app/webhook.py @@ -1,13 +1,12 @@ """Webhook handlers for mobile_app.""" import logging -from aiohttp.web import HTTPBadRequest, Response, Request +from aiohttp.web import HTTPBadRequest, Request, Response import voluptuous as vol -from homeassistant.components.cloud import async_remote_ui_url, CloudNotAvailable +from homeassistant.components.cloud import CloudNotAvailable, async_remote_ui_url from homeassistant.components.frontend import MANIFEST_JSON from homeassistant.components.zone.const import DOMAIN as ZONE_DOMAIN - from homeassistant.const import ( ATTR_DOMAIN, ATTR_SERVICE, @@ -50,10 +49,10 @@ from .const import ( ERR_ENCRYPTION_REQUIRED, ERR_SENSOR_DUPLICATE_UNIQUE_ID, ERR_SENSOR_NOT_REGISTERED, + SIGNAL_LOCATION_UPDATE, SIGNAL_SENSOR_UPDATE, WEBHOOK_PAYLOAD_SCHEMA, WEBHOOK_SCHEMAS, - WEBHOOK_TYPES, WEBHOOK_TYPE_CALL_SERVICE, WEBHOOK_TYPE_FIRE_EVENT, WEBHOOK_TYPE_GET_CONFIG, @@ -63,10 +62,8 @@ from .const import ( WEBHOOK_TYPE_UPDATE_LOCATION, WEBHOOK_TYPE_UPDATE_REGISTRATION, WEBHOOK_TYPE_UPDATE_SENSOR_STATES, - SIGNAL_LOCATION_UPDATE, + WEBHOOK_TYPES, ) - - from .helpers import ( _decrypt_payload, empty_okay_response, @@ -77,7 +74,6 @@ from .helpers import ( webhook_response, ) - _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/mobile_app/websocket_api.py b/homeassistant/components/mobile_app/websocket_api.py index d0d13415b4d..813d0a9cf89 100644 --- a/homeassistant/components/mobile_app/websocket_api.py +++ b/homeassistant/components/mobile_app/websocket_api.py @@ -29,7 +29,6 @@ from .const import ( DATA_STORE, DOMAIN, ) - from .helpers import safe_registration, savable_state