From ab598da4bae5010618def19176fb14c6b80bc8c3 Mon Sep 17 00:00:00 2001 From: Quentame Date: Thu, 17 Oct 2019 15:03:50 +0200 Subject: [PATCH] Move imports in nest component (#27778) --- homeassistant/components/nest/__init__.py | 9 ++------- homeassistant/components/nest/climate.py | 4 ++-- homeassistant/components/nest/local_auth.py | 5 ++--- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/nest/__init__.py b/homeassistant/components/nest/__init__.py index cf1ba36aa893..32bbd009417f 100644 --- a/homeassistant/components/nest/__init__.py +++ b/homeassistant/components/nest/__init__.py @@ -4,6 +4,8 @@ import socket from datetime import datetime, timedelta import threading +from nest import Nest +from nest.nest import AuthorizationError, APIError import voluptuous as vol from homeassistant import config_entries @@ -142,7 +144,6 @@ async def async_setup(hass, config): async def async_setup_entry(hass, entry): """Set up Nest from a config entry.""" - from nest import Nest nest = Nest(access_token=entry.data["tokens"]["access_token"]) @@ -286,8 +287,6 @@ class NestDevice: def initialize(self): """Initialize Nest.""" - from nest.nest import AuthorizationError, APIError - try: # Do not optimize next statement, it is here for initialize # persistence Nest API connection. @@ -302,8 +301,6 @@ class NestDevice: def structures(self): """Generate a list of structures.""" - from nest.nest import AuthorizationError, APIError - try: for structure in self.nest.structures: if structure.name not in self.local_structure: @@ -332,8 +329,6 @@ class NestDevice: def _devices(self, device_type): """Generate a list of Nest devices.""" - from nest.nest import AuthorizationError, APIError - try: for structure in self.nest.structures: if structure.name not in self.local_structure: diff --git a/homeassistant/components/nest/climate.py b/homeassistant/components/nest/climate.py index eec7108cdeab..795ce5c80e97 100644 --- a/homeassistant/components/nest/climate.py +++ b/homeassistant/components/nest/climate.py @@ -1,6 +1,7 @@ """Support for Nest thermostats.""" import logging +from nest.nest import APIError import voluptuous as vol from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice @@ -232,7 +233,6 @@ class NestThermostat(ClimateDevice): def set_temperature(self, **kwargs): """Set new target temperature.""" - import nest temp = None target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW) @@ -247,7 +247,7 @@ class NestThermostat(ClimateDevice): try: if temp is not None: self.device.target = temp - except nest.nest.APIError as api_error: + except APIError as api_error: _LOGGER.error("An error occurred while setting temperature: %s", api_error) # restore target temperature self.schedule_update_ha_state(True) diff --git a/homeassistant/components/nest/local_auth.py b/homeassistant/components/nest/local_auth.py index 51d826c242fb..38d1827326da 100644 --- a/homeassistant/components/nest/local_auth.py +++ b/homeassistant/components/nest/local_auth.py @@ -2,6 +2,8 @@ import asyncio from functools import partial +from nest.nest import NestAuth, AUTHORIZE_URL, AuthorizationError + from homeassistant.core import callback from . import config_flow from .const import DOMAIN @@ -21,14 +23,11 @@ def initialize(hass, client_id, client_secret): async def generate_auth_url(client_id, flow_id): """Generate an authorize url.""" - from nest.nest import AUTHORIZE_URL - return AUTHORIZE_URL.format(client_id, flow_id) async def resolve_auth_code(hass, client_id, client_secret, code): """Resolve an authorization code.""" - from nest.nest import NestAuth, AuthorizationError result = asyncio.Future() auth = NestAuth(