Move imports in nest component (#27778)
parent
8350e1246a
commit
ab598da4ba
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue