Fix imports

This commit is contained in:
Paulus Schoutsen 2016-01-28 21:37:08 -08:00
parent d6db00b55a
commit cbc6323438
20 changed files with 36 additions and 126 deletions

View file

@ -10,8 +10,8 @@ omit =
homeassistant/components/arduino.py homeassistant/components/arduino.py
homeassistant/components/*/arduino.py homeassistant/components/*/arduino.py
homeassistant/components/insteon.py homeassistant/components/insteon_hub.py
homeassistant/components/*/insteon.py homeassistant/components/*/insteon_hub.py
homeassistant/components/isy994.py homeassistant/components/isy994.py
homeassistant/components/*/isy994.py homeassistant/components/*/isy994.py

View file

@ -9,11 +9,6 @@ https://home-assistant.io/components/arduino/
""" """
import logging import logging
try:
from PyMata.pymata import PyMata
except ImportError:
PyMata = None
from homeassistant.helpers import validate_config from homeassistant.helpers import validate_config
from homeassistant.const import (EVENT_HOMEASSISTANT_START, from homeassistant.const import (EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP) EVENT_HOMEASSISTANT_STOP)
@ -27,18 +22,12 @@ _LOGGER = logging.getLogger(__name__)
def setup(hass, config): def setup(hass, config):
""" Setup the Arduino component. """ """ Setup the Arduino component. """
global PyMata # pylint: disable=invalid-name
if PyMata is None:
from PyMata.pymata import PyMata as PyMata_
PyMata = PyMata_
import serial
if not validate_config(config, if not validate_config(config,
{DOMAIN: ['port']}, {DOMAIN: ['port']},
_LOGGER): _LOGGER):
return False return False
import serial
global BOARD global BOARD
try: try:
BOARD = ArduinoBoard(config[DOMAIN]['port']) BOARD = ArduinoBoard(config[DOMAIN]['port'])
@ -67,6 +56,7 @@ class ArduinoBoard(object):
""" Represents an Arduino board. """ """ Represents an Arduino board. """
def __init__(self, port): def __init__(self, port):
from PyMata.pymata import PyMata
self._port = port self._port = port
self._board = PyMata(self._port, verbose=False) self._board = PyMata(self._port, verbose=False)

View file

@ -15,6 +15,8 @@ from homeassistant.helpers import validate_config
from homeassistant.util import Throttle from homeassistant.util import Throttle
from homeassistant.components.device_tracker import DOMAIN from homeassistant.components.device_tracker import DOMAIN
REQUIREMENTS = ['fritzconnection==0.4.6']
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5) MIN_TIME_BETWEEN_SCANS = timedelta(seconds=5)
@ -55,16 +57,8 @@ class FritzBoxScanner(object):
self.password = '' self.password = ''
self.success_init = True self.success_init = True
# Try to import the fritzconnection library # pylint: disable=import-error
try:
# noinspection PyPackageRequirements,PyUnresolvedReferences
import fritzconnection as fc import fritzconnection as fc
except ImportError:
_LOGGER.exception("""Failed to import Python library
fritzconnection. Please run
<home-assistant>/setup to install it.""")
self.success_init = False
return
# Check for user specific configuration # Check for user specific configuration
if CONF_HOST in config.keys(): if CONF_HOST in config.keys():

View file

@ -11,6 +11,8 @@ import logging
import re import re
import threading import threading
import requests
from homeassistant.helpers import validate_config from homeassistant.helpers import validate_config
from homeassistant.util import sanitize_filename from homeassistant.util import sanitize_filename
@ -30,14 +32,6 @@ def setup(hass, config):
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
try:
import requests
except ImportError:
logger.exception(("Failed to import requests. "
"Did you maybe not execute 'pip install requests'?"))
return False
if not validate_config(config, {DOMAIN: [CONF_DOWNLOAD_DIR]}, logger): if not validate_config(config, {DOMAIN: [CONF_DOWNLOAD_DIR]}, logger):
return False return False

View file

@ -15,10 +15,10 @@ from homeassistant.const import (
CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY, ATTR_DISCOVERED, CONF_USERNAME, CONF_PASSWORD, CONF_API_KEY, ATTR_DISCOVERED,
ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED) ATTR_SERVICE, EVENT_PLATFORM_DISCOVERED)
DOMAIN = "insteon" DOMAIN = "insteon_hub"
REQUIREMENTS = ['insteon_hub==0.4.5'] REQUIREMENTS = ['insteon_hub==0.4.5']
INSTEON = None INSTEON = None
DISCOVER_LIGHTS = "insteon.lights" DISCOVER_LIGHTS = "insteon_hub.lights"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View file

@ -37,11 +37,7 @@ def setup(hass, config):
Setup ISY994 component. Setup ISY994 component.
This will automatically import associated lights, switches, and sensors. This will automatically import associated lights, switches, and sensors.
""" """
try:
import PyISY import PyISY
except ImportError:
_LOGGER.error("Error while importing dependency PyISY.")
return False
# pylint: disable=global-statement # pylint: disable=global-statement
# check for required values in configuration file # check for required values in configuration file

View file

@ -6,8 +6,6 @@ Provides functionality to emulate keyboard presses on host machine.
For more details about this component, please refer to the documentation at For more details about this component, please refer to the documentation at
https://home-assistant.io/components/keyboard/ https://home-assistant.io/components/keyboard/
""" """
import logging
from homeassistant.const import ( from homeassistant.const import (
SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE, SERVICE_VOLUME_UP, SERVICE_VOLUME_DOWN, SERVICE_VOLUME_MUTE,
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK,
@ -50,13 +48,7 @@ def media_prev_track(hass):
def setup(hass, config): def setup(hass, config):
""" Listen for keyboard events. """ """ Listen for keyboard events. """
try:
import pykeyboard import pykeyboard
except ImportError:
logging.getLogger(__name__).exception(
"Error while importing dependency PyUserInput.")
return False
keyboard = pykeyboard.PyKeyboard() keyboard = pykeyboard.PyKeyboard()
keyboard.special_key_assignment() keyboard.special_key_assignment()

View file

@ -11,7 +11,7 @@ import os
import csv import csv
from homeassistant.components import ( from homeassistant.components import (
group, discovery, wink, isy994, zwave, insteon) group, discovery, wink, isy994, zwave, insteon_hub)
from homeassistant.config import load_yaml_config_file from homeassistant.config import load_yaml_config_file
from homeassistant.const import ( from homeassistant.const import (
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE,
@ -60,7 +60,7 @@ LIGHT_PROFILES_FILE = "light_profiles.csv"
# Maps discovered services to their platforms # Maps discovered services to their platforms
DISCOVERY_PLATFORMS = { DISCOVERY_PLATFORMS = {
wink.DISCOVER_LIGHTS: 'wink', wink.DISCOVER_LIGHTS: 'wink',
insteon.DISCOVER_LIGHTS: 'insteon', insteon_hub.DISCOVER_LIGHTS: 'insteon',
isy994.DISCOVER_LIGHTS: 'isy994', isy994.DISCOVER_LIGHTS: 'isy994',
discovery.SERVICE_HUE: 'hue', discovery.SERVICE_HUE: 'hue',
zwave.DISCOVER_LIGHTS: 'zwave', zwave.DISCOVER_LIGHTS: 'zwave',

View file

@ -4,7 +4,7 @@ homeassistant.components.light.insteon
Support for Insteon Hub lights. Support for Insteon Hub lights.
""" """
from homeassistant.components.insteon import (INSTEON, InsteonToggleDevice) from homeassistant.components.insteon_hub import (INSTEON, InsteonToggleDevice)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):

View file

@ -9,11 +9,6 @@ https://home-assistant.io/components/media_player.mpd/
import logging import logging
import socket import socket
try:
import mpd
except ImportError:
mpd = None
from homeassistant.const import ( from homeassistant.const import (
STATE_PLAYING, STATE_PAUSED, STATE_OFF) STATE_PLAYING, STATE_PAUSED, STATE_OFF)
@ -40,10 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
location = config.get('location', 'MPD') location = config.get('location', 'MPD')
password = config.get('password', None) password = config.get('password', None)
global mpd # pylint: disable=invalid-name import mpd
if mpd is None:
import mpd as mpd_
mpd = mpd_
# pylint: disable=no-member # pylint: disable=no-member
try: try:
@ -82,6 +74,8 @@ class MpdDevice(MediaPlayerDevice):
# pylint: disable=no-member, abstract-method # pylint: disable=no-member, abstract-method
def __init__(self, server, port, location, password): def __init__(self, server, port, location, password):
import mpd
self.server = server self.server = server
self.port = port self.port = port
self._name = location self._name = location
@ -95,6 +89,7 @@ class MpdDevice(MediaPlayerDevice):
self.update() self.update()
def update(self): def update(self):
import mpd
try: try:
self.status = self.client.status() self.status = self.client.status()
self.currentsong = self.client.currentsong() self.currentsong = self.client.currentsong()

View file

@ -48,11 +48,7 @@ def setup(hass, config):
subscriber(event) subscriber(event)
# Try to load the RFXtrx module # Try to load the RFXtrx module
try:
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
except ImportError:
_LOGGER.exception("Failed to import rfxtrx")
return False
# Init the rfxtrx module # Init the rfxtrx module
global RFXOBJECT global RFXOBJECT
@ -74,11 +70,7 @@ def setup(hass, config):
def get_rfx_object(packetid): def get_rfx_object(packetid):
""" Return the RFXObject with the packetid. """ """ Return the RFXObject with the packetid. """
try:
import RFXtrx as rfxtrxmod import RFXtrx as rfxtrxmod
except ImportError:
_LOGGER.exception("Failed to import rfxtrx")
return False
binarypacket = bytearray.fromhex(packetid) binarypacket = bytearray.fromhex(packetid)

View file

@ -47,17 +47,9 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the Bitcoin sensor. """ """ Get the Bitcoin sensor. """
try:
from blockchain.wallet import Wallet from blockchain.wallet import Wallet
from blockchain import exchangerates, exceptions from blockchain import exchangerates, exceptions
except ImportError:
_LOGGER.exception(
"Unable to import blockchain. "
"Did you maybe not install the 'blockchain' package?")
return False
wallet_id = config.get('wallet', None) wallet_id = config.get('wallet', None)
password = config.get('password', None) password = config.get('password', None)
currency = config.get('currency', 'USD') currency = config.get('currency', 'USD')

View file

@ -25,14 +25,6 @@ ATTR_HZ = 'GHz Advertised'
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the CPU speed sensor. """ """ Sets up the CPU speed sensor. """
try:
import cpuinfo # noqa
except ImportError:
_LOGGER.exception(
"Unable to import cpuinfo. "
"Did you maybe not install the 'py-cpuinfo' package?")
return False
add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))]) add_devices([CpuSpeedSensor(config.get('name', DEFAULT_NAME))])

View file

@ -31,16 +31,9 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Get the DHT sensor. """ """ Get the DHT sensor. """
try: # pylint: disable=import-error
import Adafruit_DHT import Adafruit_DHT
except ImportError:
_LOGGER.exception(
"Unable to import Adafruit_DHT. "
"Did you maybe not install the 'Adafruit_DHT' package?")
return False
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
unit = hass.config.temperature_unit unit = hass.config.temperature_unit
available_sensors = { available_sensors = {

View file

@ -37,16 +37,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
_LOGGER.error("Latitude or longitude not set in Home Assistant config") _LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False return False
try:
from pyowm import OWM from pyowm import OWM
except ImportError:
_LOGGER.exception(
"Unable to import pyowm. "
"Did you maybe not install the 'PyOWM' package?")
return False
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
unit = hass.config.temperature_unit unit = hass.config.temperature_unit
forecast = config.get('forecast', 0) forecast = config.get('forecast', 0)

View file

@ -20,12 +20,7 @@ REQUIREMENTS = ['https://github.com/rkabadi/temper-python/archive/'
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Temper sensors. """ """ Find and return Temper sensors. """
try:
# pylint: disable=no-name-in-module, import-error
from temperusb.temper import TemperHandler from temperusb.temper import TemperHandler
except ImportError:
_LOGGER.error('Failed to import temperusb')
return False
temp_unit = hass.config.temperature_unit temp_unit = hass.config.temperature_unit
name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME) name = config.get(CONF_NAME, DEVICE_DEFAULT_NAME)

View file

@ -27,12 +27,7 @@ _LOGGER = logging.getLogger(__name__)
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None): def setup_platform(hass, config, add_devices_callback, discovery_info=None):
""" Find and return Edimax Smart Plugs. """ """ Find and return Edimax Smart Plugs. """
try:
# pylint: disable=no-name-in-module, import-error
from pyedimax.smartplug import SmartPlug from pyedimax.smartplug import SmartPlug
except ImportError:
_LOGGER.error('Failed to import pyedimax')
return False
# pylint: disable=global-statement # pylint: disable=global-statement
# check for required values in configuration file # check for required values in configuration file

View file

@ -21,13 +21,7 @@ _LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Radio Thermostat. """ """ Sets up the Radio Thermostat. """
try:
import radiotherm import radiotherm
except ImportError:
_LOGGER.exception(
"Unable to import radiotherm. "
"Did you maybe not install the 'radiotherm' package?")
return False
hosts = [] hosts = []
if CONF_HOST in config: if CONF_HOST in config:

View file

@ -15,6 +15,9 @@ PyMata==2.07a
# homeassistant.components.conversation # homeassistant.components.conversation
fuzzywuzzy==0.8.0 fuzzywuzzy==0.8.0
# homeassistant.components.device_tracker.fritz
# fritzconnection==0.4.6
# homeassistant.components.device_tracker.icloud # homeassistant.components.device_tracker.icloud
pyicloud==0.7.2 pyicloud==0.7.2
@ -39,7 +42,7 @@ pyfttt==0.3
# homeassistant.components.influxdb # homeassistant.components.influxdb
influxdb==2.11.0 influxdb==2.11.0
# homeassistant.components.insteon # homeassistant.components.insteon_hub
insteon_hub==0.4.5 insteon_hub==0.4.5
# homeassistant.components.isy994 # homeassistant.components.isy994

View file

@ -13,6 +13,7 @@ import sys
COMMENT_REQUIREMENTS = [ COMMENT_REQUIREMENTS = [
'RPi.GPIO', 'RPi.GPIO',
'Adafruit_Python_DHT', 'Adafruit_Python_DHT',
'fritzconnection',
] ]