Skip to content

Commit

Permalink
Move imports in netatmo component (#27360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame authored and balloob committed Oct 10, 2019
1 parent 6c739f4 commit 7718d61
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 23 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/netatmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import timedelta
from urllib.error import HTTPError

import pyatmo
import voluptuous as vol

from homeassistant.const import (
Expand Down Expand Up @@ -89,7 +90,6 @@

def setup(hass, config):
"""Set up the Netatmo devices."""
import pyatmo

hass.data[DATA_PERSONS] = {}
try:
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/netatmo/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/netatmo/camera.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Support for the Netatmo cameras."""
import logging

from pyatmo import NoDevice
import requests
import voluptuous as vol

Expand Down Expand Up @@ -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]

Expand All @@ -60,7 +60,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
]
)
data.get_persons()
except pyatmo.NoDevice:
except NoDevice:
return None


Expand Down
9 changes: 1 addition & 8 deletions homeassistant/components/netatmo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from typing import Optional, List

import pyatmo
import requests
import voluptuous as vol

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions homeassistant/components/netatmo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datetime import timedelta
from time import time

import pyatmo
import requests
import voluptuous as vol

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
)
Expand Down

0 comments on commit 7718d61

Please sign in to comment.