mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Move imports in nest component (#27778)
This commit is contained in:
parent
8350e1246a
commit
ab598da4ba
@ -4,6 +4,8 @@ import socket
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
from nest import Nest
|
||||||
|
from nest.nest import AuthorizationError, APIError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -142,7 +144,6 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up Nest from a config entry."""
|
"""Set up Nest from a config entry."""
|
||||||
from nest import Nest
|
|
||||||
|
|
||||||
nest = Nest(access_token=entry.data["tokens"]["access_token"])
|
nest = Nest(access_token=entry.data["tokens"]["access_token"])
|
||||||
|
|
||||||
@ -286,8 +287,6 @@ class NestDevice:
|
|||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
"""Initialize Nest."""
|
"""Initialize Nest."""
|
||||||
from nest.nest import AuthorizationError, APIError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Do not optimize next statement, it is here for initialize
|
# Do not optimize next statement, it is here for initialize
|
||||||
# persistence Nest API connection.
|
# persistence Nest API connection.
|
||||||
@ -302,8 +301,6 @@ class NestDevice:
|
|||||||
|
|
||||||
def structures(self):
|
def structures(self):
|
||||||
"""Generate a list of structures."""
|
"""Generate a list of structures."""
|
||||||
from nest.nest import AuthorizationError, APIError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for structure in self.nest.structures:
|
for structure in self.nest.structures:
|
||||||
if structure.name not in self.local_structure:
|
if structure.name not in self.local_structure:
|
||||||
@ -332,8 +329,6 @@ class NestDevice:
|
|||||||
|
|
||||||
def _devices(self, device_type):
|
def _devices(self, device_type):
|
||||||
"""Generate a list of Nest devices."""
|
"""Generate a list of Nest devices."""
|
||||||
from nest.nest import AuthorizationError, APIError
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for structure in self.nest.structures:
|
for structure in self.nest.structures:
|
||||||
if structure.name not in self.local_structure:
|
if structure.name not in self.local_structure:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""Support for Nest thermostats."""
|
"""Support for Nest thermostats."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from nest.nest import APIError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
|
||||||
@ -232,7 +233,6 @@ class NestThermostat(ClimateDevice):
|
|||||||
|
|
||||||
def set_temperature(self, **kwargs):
|
def set_temperature(self, **kwargs):
|
||||||
"""Set new target temperature."""
|
"""Set new target temperature."""
|
||||||
import nest
|
|
||||||
|
|
||||||
temp = None
|
temp = None
|
||||||
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
target_temp_low = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||||
@ -247,7 +247,7 @@ class NestThermostat(ClimateDevice):
|
|||||||
try:
|
try:
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
self.device.target = temp
|
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)
|
_LOGGER.error("An error occurred while setting temperature: %s", api_error)
|
||||||
# restore target temperature
|
# restore target temperature
|
||||||
self.schedule_update_ha_state(True)
|
self.schedule_update_ha_state(True)
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from nest.nest import NestAuth, AUTHORIZE_URL, AuthorizationError
|
||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from . import config_flow
|
from . import config_flow
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@ -21,14 +23,11 @@ def initialize(hass, client_id, client_secret):
|
|||||||
|
|
||||||
async def generate_auth_url(client_id, flow_id):
|
async def generate_auth_url(client_id, flow_id):
|
||||||
"""Generate an authorize url."""
|
"""Generate an authorize url."""
|
||||||
from nest.nest import AUTHORIZE_URL
|
|
||||||
|
|
||||||
return AUTHORIZE_URL.format(client_id, flow_id)
|
return AUTHORIZE_URL.format(client_id, flow_id)
|
||||||
|
|
||||||
|
|
||||||
async def resolve_auth_code(hass, client_id, client_secret, code):
|
async def resolve_auth_code(hass, client_id, client_secret, code):
|
||||||
"""Resolve an authorization code."""
|
"""Resolve an authorization code."""
|
||||||
from nest.nest import NestAuth, AuthorizationError
|
|
||||||
|
|
||||||
result = asyncio.Future()
|
result = asyncio.Future()
|
||||||
auth = NestAuth(
|
auth = NestAuth(
|
||||||
|
Loading…
Reference in New Issue
Block a user