From 940b2998ea219b42d805306af98f9df6791dc581 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 7 Jul 2015 00:01:46 -0700 Subject: [PATCH] Add REQUIREMENTS list to components --- homeassistant/components/arduino.py | 15 ++++++++++++--- homeassistant/components/discovery.py | 1 + homeassistant/components/isy994.py | 1 + homeassistant/components/keyboard.py | 1 + homeassistant/components/light/hue.py | 1 + homeassistant/components/light/limitlessled.py | 7 ++----- homeassistant/components/media_player/cast.py | 15 +++++---------- homeassistant/components/media_player/kodi.py | 9 ++++----- homeassistant/components/media_player/mpd.py | 10 ++++------ homeassistant/components/notify/pushbullet.py | 1 + homeassistant/components/notify/pushover.py | 1 + homeassistant/components/notify/xmpp.py | 2 ++ homeassistant/components/sensor/bitcoin.py | 1 + homeassistant/components/sensor/forecast.py | 10 +++++++++- homeassistant/components/sensor/mysensors.py | 1 + homeassistant/components/sensor/openweathermap.py | 1 + homeassistant/components/sensor/systemmonitor.py | 1 + homeassistant/components/sensor/transmission.py | 1 + homeassistant/components/sun.py | 8 +++++--- homeassistant/components/switch/hikvisioncam.py | 2 +- homeassistant/components/switch/transmission.py | 1 + homeassistant/components/thermostat/nest.py | 2 ++ homeassistant/components/zwave.py | 1 + pylintrc | 4 +++- requirements.txt | 2 +- 25 files changed, 63 insertions(+), 36 deletions(-) diff --git a/homeassistant/components/arduino.py b/homeassistant/components/arduino.py index e7131f9c9e0..db91c5e0d9c 100644 --- a/homeassistant/components/arduino.py +++ b/homeassistant/components/arduino.py @@ -27,8 +27,10 @@ every initialization the pins are set to off/low. """ import logging -from PyMata.pymata import PyMata -import serial +try: + from PyMata.pymata import PyMata +except ImportError: + PyMata = None from homeassistant.helpers import validate_config from homeassistant.const import (EVENT_HOMEASSISTANT_START, @@ -36,6 +38,7 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START, DOMAIN = "arduino" DEPENDENCIES = [] +REQUIREMENTS = ['PyMata==2.07a'] BOARD = None _LOGGER = logging.getLogger(__name__) @@ -43,12 +46,18 @@ _LOGGER = logging.getLogger(__name__) def setup(hass, config): """ 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, {DOMAIN: ['port']}, _LOGGER): return False - # pylint: disable=global-statement global BOARD try: BOARD = ArduinoBoard(config[DOMAIN]['port']) diff --git a/homeassistant/components/discovery.py b/homeassistant/components/discovery.py index 819d45b5b68..63c9a0af74f 100644 --- a/homeassistant/components/discovery.py +++ b/homeassistant/components/discovery.py @@ -22,6 +22,7 @@ from homeassistant.const import ( DOMAIN = "discovery" DEPENDENCIES = [] +REQUIREMENTS = ['zeroconf>=0.16.0'] SCAN_INTERVAL = 300 # seconds diff --git a/homeassistant/components/isy994.py b/homeassistant/components/isy994.py index 2ff9b5caeaf..08235714d68 100644 --- a/homeassistant/components/isy994.py +++ b/homeassistant/components/isy994.py @@ -22,6 +22,7 @@ from homeassistant.const import ( # homeassistant constants DOMAIN = "isy994" DEPENDENCIES = [] +REQUIREMENTS = ['PyISY>=1.0.2'] DISCOVER_LIGHTS = "isy994.lights" DISCOVER_SWITCHES = "isy994.switches" DISCOVER_SENSORS = "isy994.sensors" diff --git a/homeassistant/components/keyboard.py b/homeassistant/components/keyboard.py index b59fe8d39dc..5359791087e 100644 --- a/homeassistant/components/keyboard.py +++ b/homeassistant/components/keyboard.py @@ -14,6 +14,7 @@ from homeassistant.const import ( DOMAIN = "keyboard" DEPENDENCIES = [] +REQUIREMENTS = ['pyuserinput>=0.1.9'] def volume_up(hass): diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 65a288f82d5..b4f9416b144 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -11,6 +11,7 @@ from homeassistant.components.light import ( Light, ATTR_BRIGHTNESS, ATTR_XY_COLOR, ATTR_TRANSITION, ATTR_FLASH, FLASH_LONG, FLASH_SHORT) +REQUIREMENTS = ['phue>=0.8'] MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10) MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100) diff --git a/homeassistant/components/light/limitlessled.py b/homeassistant/components/light/limitlessled.py index 649f642e077..b515bb1cbac 100644 --- a/homeassistant/components/light/limitlessled.py +++ b/homeassistant/components/light/limitlessled.py @@ -27,15 +27,12 @@ from homeassistant.const import DEVICE_DEFAULT_NAME from homeassistant.components.light import Light, ATTR_BRIGHTNESS _LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['ledcontroller>=1.0.7'] def setup_platform(hass, config, add_devices_callback, discovery_info=None): """ Gets the LimitlessLED lights. """ - try: - import ledcontroller - except ImportError: - _LOGGER.exception("Error while importing dependency ledcontroller.") - return + import ledcontroller led = ledcontroller.LedController(config['host']) diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index 77cdf79a112..2c9b3c3a15c 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -6,11 +6,8 @@ Provides functionality to interact with Cast devices on the network. WARNING: This platform is currently not working due to a changed Cast API """ -import logging - try: import pychromecast - import pychromecast.controllers.youtube as youtube except ImportError: pychromecast = None @@ -25,6 +22,7 @@ from homeassistant.components.media_player import ( SUPPORT_PREVIOUS_TRACK, SUPPORT_NEXT_TRACK, MEDIA_TYPE_MUSIC, MEDIA_TYPE_TVSHOW, MEDIA_TYPE_VIDEO) +REQUIREMENTS = ['pychromecast>=0.6.8.2'] CAST_SPLASH = 'https://home-assistant.io/images/cast/splash.png' SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_PREVIOUS_TRACK | \ @@ -34,14 +32,10 @@ SUPPORT_CAST = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the cast platform. """ - logger = logging.getLogger(__name__) - + global pychromecast # pylint: disable=invalid-name if pychromecast is None: - logger.error(( - "Failed to import pychromecast. Did you maybe not install the " - "'pychromecast' dependency?")) - - return False + import pychromecast as pychromecast_ + pychromecast = pychromecast_ if discovery_info: hosts = [discovery_info[0]] @@ -67,6 +61,7 @@ class CastDevice(MediaPlayerDevice): # pylint: disable=too-many-public-methods def __init__(self, host): + import pychromecast.controllers.youtube as youtube self.cast = pychromecast.Chromecast(host) self.youtube = youtube.YouTubeController() self.cast.register_handler(self.youtube) diff --git a/homeassistant/components/media_player/kodi.py b/homeassistant/components/media_player/kodi.py index d31e71251dc..e134c1c2f7e 100644 --- a/homeassistant/components/media_player/kodi.py +++ b/homeassistant/components/media_player/kodi.py @@ -49,6 +49,7 @@ except ImportError: jsonrpc_requests = None _LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['jsonrpc-requests>=0.1'] SUPPORT_KODI = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK @@ -58,12 +59,10 @@ SUPPORT_KODI = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the kodi platform. """ + global jsonrpc_requests # pylint: disable=invalid-name if jsonrpc_requests is None: - _LOGGER.exception( - "Unable to import jsonrpc_requests. " - "Did you maybe not install the 'jsonrpc-requests' pip module?") - - return False + import jsonrpc_requests as jsonrpc_requests_ + jsonrpc_requests = jsonrpc_requests_ add_devices([ KodiDevice( diff --git a/homeassistant/components/media_player/mpd.py b/homeassistant/components/media_player/mpd.py index f8b455ae6fe..0239173f7cc 100644 --- a/homeassistant/components/media_player/mpd.py +++ b/homeassistant/components/media_player/mpd.py @@ -48,7 +48,7 @@ from homeassistant.components.media_player import ( MEDIA_TYPE_MUSIC) _LOGGER = logging.getLogger(__name__) - +REQUIREMENTS = ['python-mpd2>=0.5.4'] SUPPORT_MPD = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_TURN_OFF | \ SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK @@ -62,12 +62,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None): port = config.get('port', 6600) location = config.get('location', 'MPD') + global mpd # pylint: disable=invalid-name if mpd is None: - _LOGGER.exception( - "Unable to import mpd2. " - "Did you maybe not install the 'python-mpd2' package?") - - return False + import mpd as mpd_ + mpd = mpd_ # pylint: disable=no-member try: diff --git a/homeassistant/components/notify/pushbullet.py b/homeassistant/components/notify/pushbullet.py index 09bfd3244c8..5e322cfc3b5 100644 --- a/homeassistant/components/notify/pushbullet.py +++ b/homeassistant/components/notify/pushbullet.py @@ -28,6 +28,7 @@ from homeassistant.components.notify import ( from homeassistant.const import CONF_API_KEY _LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['pushbullet.py>=0.7.1'] def get_service(hass, config): diff --git a/homeassistant/components/notify/pushover.py b/homeassistant/components/notify/pushover.py index f8ec652a39c..1bc5e9ac9a3 100644 --- a/homeassistant/components/notify/pushover.py +++ b/homeassistant/components/notify/pushover.py @@ -42,6 +42,7 @@ from homeassistant.components.notify import ( DOMAIN, ATTR_TITLE, BaseNotificationService) from homeassistant.const import CONF_API_KEY +REQUIREMENTS = ['python-pushover>=0.2'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/notify/xmpp.py b/homeassistant/components/notify/xmpp.py index 43bb5799458..25099921f45 100644 --- a/homeassistant/components/notify/xmpp.py +++ b/homeassistant/components/notify/xmpp.py @@ -47,6 +47,8 @@ from homeassistant.helpers import validate_config from homeassistant.components.notify import ( DOMAIN, ATTR_TITLE, BaseNotificationService) +REQUIREMENTS = ['sleekxmpp>=1.3.1'] + def get_service(hass, config): """ Get the Jabber (XMPP) notification service. """ diff --git a/homeassistant/components/sensor/bitcoin.py b/homeassistant/components/sensor/bitcoin.py index bc29198e6a0..e0ecbab6db5 100644 --- a/homeassistant/components/sensor/bitcoin.py +++ b/homeassistant/components/sensor/bitcoin.py @@ -71,6 +71,7 @@ from homeassistant.util import Throttle from homeassistant.helpers.entity import Entity +REQUIREMENTS = ['blockchain>=1.1.2'] _LOGGER = logging.getLogger(__name__) OPTION_TYPES = { 'wallet': ['Wallet balance', 'BTC'], diff --git a/homeassistant/components/sensor/forecast.py b/homeassistant/components/sensor/forecast.py index 98e088d5139..abd3cdadb73 100644 --- a/homeassistant/components/sensor/forecast.py +++ b/homeassistant/components/sensor/forecast.py @@ -50,7 +50,10 @@ Details for the API : https://developer.forecast.io/docs/v2 import logging from datetime import timedelta -import forecastio +try: + import forecastio +except ImportError: + forecastio = None from homeassistant.util import Throttle from homeassistant.const import (CONF_API_KEY, TEMP_CELCIUS, TEMP_FAHRENHEIT) @@ -79,6 +82,11 @@ MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=120) def setup_platform(hass, config, add_devices, discovery_info=None): """ Get the Forecast.io sensor. """ + global forecastio # pylint: disable=invalid-name + if forecastio is None: + import forecastio as forecastio_ + forecastio = forecastio_ + if None in (hass.config.latitude, hass.config.longitude): _LOGGER.error("Latitude or longitude not set in Home Assistant config") return False diff --git a/homeassistant/components/sensor/mysensors.py b/homeassistant/components/sensor/mysensors.py index 7fbcf65328d..4f3c2610c5a 100644 --- a/homeassistant/components/sensor/mysensors.py +++ b/homeassistant/components/sensor/mysensors.py @@ -39,6 +39,7 @@ ATTR_NODE_ID = "node_id" ATTR_CHILD_ID = "child_id" _LOGGER = logging.getLogger(__name__) +REQUIREMENTS = ['pyserial>=2.7'] def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/sensor/openweathermap.py b/homeassistant/components/sensor/openweathermap.py index 07413e7b1ea..22720748034 100644 --- a/homeassistant/components/sensor/openweathermap.py +++ b/homeassistant/components/sensor/openweathermap.py @@ -48,6 +48,7 @@ from homeassistant.util import Throttle from homeassistant.const import (CONF_API_KEY, TEMP_CELCIUS, TEMP_FAHRENHEIT) from homeassistant.helpers.entity import Entity +REQUIREMENTS = ['pywm>=2.2.1'] _LOGGER = logging.getLogger(__name__) SENSOR_TYPES = { 'weather': ['Condition', ''], diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 2615ab1a77b..1d1bdb1f3b5 100644 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -66,6 +66,7 @@ import homeassistant.util.dt as dt_util from homeassistant.helpers.entity import Entity from homeassistant.const import STATE_ON, STATE_OFF +REQUIREMENTS = ['psutil>=3.0.0'] SENSOR_TYPES = { 'disk_use_percent': ['Disk Use', '%'], 'disk_use': ['Disk Use', 'GiB'], diff --git a/homeassistant/components/sensor/transmission.py b/homeassistant/components/sensor/transmission.py index 8ce2b6951ca..b9ed3ea4e9f 100644 --- a/homeassistant/components/sensor/transmission.py +++ b/homeassistant/components/sensor/transmission.py @@ -67,6 +67,7 @@ from transmissionrpc.error import TransmissionError import logging +REQUIREMENTS = ['transmissionrpc>=0.11'] SENSOR_TYPES = { 'current_status': ['Status', ''], 'download_speed': ['Down Speed', 'MB/s'], diff --git a/homeassistant/components/sun.py b/homeassistant/components/sun.py index 24ef6e24e05..b1d1d755348 100644 --- a/homeassistant/components/sun.py +++ b/homeassistant/components/sun.py @@ -25,7 +25,7 @@ from datetime import timedelta try: import ephem except ImportError: - # Error will be raised during setup + # Will be fixed during setup ephem = None import homeassistant.util.dt as dt_util @@ -33,6 +33,7 @@ from homeassistant.helpers.entity import Entity from homeassistant.components.scheduler import ServiceEventListener DEPENDENCIES = [] +REQUIREMENTS = ['pyephem>=3.7'] DOMAIN = "sun" ENTITY_ID = "sun.sun" @@ -100,9 +101,10 @@ def setup(hass, config): """ Tracks the state of the sun. """ logger = logging.getLogger(__name__) + global ephem # pylint: disable=invalid-name if ephem is None: - logger.exception("Error while importing dependency ephem.") - return False + import ephem as ephem_ + ephem = ephem_ if None in (hass.config.latitude, hass.config.longitude): logger.error("Latitude or longitude not set in Home Assistant config") diff --git a/homeassistant/components/switch/hikvisioncam.py b/homeassistant/components/switch/hikvisioncam.py index af9c4c6ad40..388152361d2 100644 --- a/homeassistant/components/switch/hikvisioncam.py +++ b/homeassistant/components/switch/hikvisioncam.py @@ -53,7 +53,7 @@ except ImportError: hikvision.api = None _LOGGING = logging.getLogger(__name__) - +REQUIREMENTS = ['hikvision>=0.4'] # pylint: disable=too-many-arguments # pylint: disable=too-many-instance-attributes diff --git a/homeassistant/components/switch/transmission.py b/homeassistant/components/switch/transmission.py index b3fb04dbd82..8638f11a2e9 100644 --- a/homeassistant/components/switch/transmission.py +++ b/homeassistant/components/switch/transmission.py @@ -54,6 +54,7 @@ from transmissionrpc.error import TransmissionError import logging _LOGGING = logging.getLogger(__name__) +REQUIREMENTS = ['transmissionrpc>=0.11'] # pylint: disable=unused-argument diff --git a/homeassistant/components/thermostat/nest.py b/homeassistant/components/thermostat/nest.py index b9d13b123fb..b2e48b96bcd 100644 --- a/homeassistant/components/thermostat/nest.py +++ b/homeassistant/components/thermostat/nest.py @@ -6,6 +6,8 @@ import logging from homeassistant.components.thermostat import ThermostatDevice from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS) +REQUIREMENTS = ['python-nest>=2.3.1'] + # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): diff --git a/homeassistant/components/zwave.py b/homeassistant/components/zwave.py index 1d798746a63..c5967ae0f34 100644 --- a/homeassistant/components/zwave.py +++ b/homeassistant/components/zwave.py @@ -13,6 +13,7 @@ from homeassistant.const import ( DOMAIN = "zwave" DEPENDENCIES = [] +REQUIREMENTS = ['pydispatcher>=2.0.5'] CONF_USB_STICK_PATH = "usb_path" DEFAULT_CONF_USB_STICK_PATH = "/zwaveusbstick" diff --git a/pylintrc b/pylintrc index a9994eb70f5..54b1f80cdc5 100644 --- a/pylintrc +++ b/pylintrc @@ -9,13 +9,15 @@ reports=no # abstract-class-little-used - Prevents from setting right foundation # abstract-class-not-used - is flaky, should not show up but does # unused-argument - generic callbacks and setup methods create a lot of warnings +# global-statement - used for the on-demand requirement installation disable= locally-disabled, duplicate-code, cyclic-import, abstract-class-little-used, abstract-class-not-used, - unused-argument + unused-argument, + global-statement [EXCEPTIONS] overgeneral-exceptions=Exception,HomeAssistantError diff --git a/requirements.txt b/requirements.txt index 341fcd3cf81..0ee24587cf2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -68,7 +68,7 @@ hikvision>=0.4 # console log coloring colorlog>=2.6.0 -# JSON-RPC interface +# JSON-RPC interface (media_player.kodi) jsonrpc-requests>=0.1 # Forecast.io Bindings (sensor.forecast)