diff --git a/homeassistant/components/netatmo/__init__.py b/homeassistant/components/netatmo/__init__.py index 28d422557da3f..4b9f0690ac5a4 100644 --- a/homeassistant/components/netatmo/__init__.py +++ b/homeassistant/components/netatmo/__init__.py @@ -3,6 +3,7 @@ from datetime import timedelta from urllib.error import HTTPError +import pyatmo import voluptuous as vol from homeassistant.const import ( @@ -89,7 +90,6 @@ def setup(hass, config): """Set up the Netatmo devices.""" - import pyatmo hass.data[DATA_PERSONS] = {} try: @@ -254,8 +254,6 @@ def get_persons(self): @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Call the Netatmo API to update the data.""" - import pyatmo - self.camera_data = pyatmo.CameraData(self.auth, size=100) @Throttle(MIN_TIME_BETWEEN_EVENT_UPDATES) diff --git a/homeassistant/components/netatmo/binary_sensor.py b/homeassistant/components/netatmo/binary_sensor.py index 591cd790ecf5d..1a40d3952e945 100644 --- a/homeassistant/components/netatmo/binary_sensor.py +++ b/homeassistant/components/netatmo/binary_sensor.py @@ -1,6 +1,7 @@ """Support for the Netatmo binary sensors.""" import logging +from pyatmo import NoDevice import voluptuous as vol from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorDevice @@ -58,15 +59,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None): module_name = None - import pyatmo - auth = hass.data[DATA_NETATMO_AUTH] try: data = CameraData(hass, auth, home) if not data.get_camera_names(): return None - except pyatmo.NoDevice: + except NoDevice: return None welcome_sensors = config.get(CONF_WELCOME_SENSORS, WELCOME_SENSOR_TYPES) diff --git a/homeassistant/components/netatmo/camera.py b/homeassistant/components/netatmo/camera.py index 60428961cb95b..ecc38add3b41c 100644 --- a/homeassistant/components/netatmo/camera.py +++ b/homeassistant/components/netatmo/camera.py @@ -1,6 +1,7 @@ """Support for the Netatmo cameras.""" import logging +from pyatmo import NoDevice import requests import voluptuous as vol @@ -38,7 +39,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): home = config.get(CONF_HOME) verify_ssl = config.get(CONF_VERIFY_SSL, True) quality = config.get(CONF_QUALITY, DEFAULT_QUALITY) - import pyatmo auth = hass.data[DATA_NETATMO_AUTH] @@ -60,7 +60,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): ] ) data.get_persons() - except pyatmo.NoDevice: + except NoDevice: return None diff --git a/homeassistant/components/netatmo/climate.py b/homeassistant/components/netatmo/climate.py index 1465058652dea..8ba13a03889d2 100644 --- a/homeassistant/components/netatmo/climate.py +++ b/homeassistant/components/netatmo/climate.py @@ -3,6 +3,7 @@ import logging from typing import Optional, List +import pyatmo import requests import voluptuous as vol @@ -103,8 +104,6 @@ def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the NetAtmo Thermostat.""" - import pyatmo - homes_conf = config.get(CONF_HOMES) auth = hass.data[DATA_NETATMO_AUTH] @@ -365,8 +364,6 @@ def get_home_ids(self): def setup(self): """Retrieve HomeData by NetAtmo API.""" - import pyatmo - try: self.homedata = pyatmo.HomeData(self.auth) self.home_id = self.homedata.gethomeId(self.home) @@ -408,8 +405,6 @@ def get_room_ids(self): def setup(self): """Retrieve HomeData and HomeStatus by NetAtmo API.""" - import pyatmo - try: self.homedata = pyatmo.HomeData(self.auth) self.homestatus = pyatmo.HomeStatus(self.auth, home_id=self.home_id) @@ -423,8 +418,6 @@ def setup(self): @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Call the NetAtmo API to update the data.""" - import pyatmo - try: self.homestatus = pyatmo.HomeStatus(self.auth, home_id=self.home_id) except TypeError: diff --git a/homeassistant/components/netatmo/sensor.py b/homeassistant/components/netatmo/sensor.py index 9e68c078cdcb3..38e3753708e1b 100644 --- a/homeassistant/components/netatmo/sensor.py +++ b/homeassistant/components/netatmo/sensor.py @@ -4,6 +4,7 @@ from datetime import timedelta from time import time +import pyatmo import requests import voluptuous as vol @@ -174,8 +175,6 @@ def _retry(_data): if _dev: add_entities(_dev, True) - import pyatmo - for data_class in [pyatmo.WeatherStationData, pyatmo.HomeCoachData]: try: data = NetatmoData(auth, data_class, config.get(CONF_STATION)) @@ -512,8 +511,6 @@ def __init__(self, auth, lat_ne, lon_ne, lat_sw, lon_sw): @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): """Request an update from the Netatmo API.""" - import pyatmo - data = pyatmo.PublicData( self.auth, LAT_NE=self.lat_ne, @@ -559,12 +556,10 @@ def update(self): if time() < self._next_update or not self._update_in_progress.acquire(False): return try: - from pyatmo import NoDevice - try: self.station_data = self.data_class(self.auth) _LOGGER.debug("%s detected!", str(self.data_class.__name__)) - except NoDevice: + except pyatmo.NoDevice: _LOGGER.warning( "No Weather or HomeCoach devices found for %s", str(self.station) )