Merge pull request #672 from balloob/some-cleanup

Make component dependencies optional
This commit is contained in:
Paulus Schoutsen 2015-11-27 15:08:22 -08:00
commit ad3f96fa25
38 changed files with 27 additions and 63 deletions

View File

@ -82,7 +82,7 @@ def _setup_component(hass, domain, config):
return True return True
component = loader.get_component(domain) component = loader.get_component(domain)
missing_deps = [dep for dep in component.DEPENDENCIES missing_deps = [dep for dep in getattr(component, 'DEPENDENCIES', [])
if dep not in hass.config.components] if dep not in hass.config.components]
if missing_deps: if missing_deps:
@ -106,7 +106,7 @@ def _setup_component(hass, domain, config):
# Assumption: if a component does not depend on groups # Assumption: if a component does not depend on groups
# it communicates with devices # it communicates with devices
if group.DOMAIN not in component.DEPENDENCIES: if group.DOMAIN not in getattr(component, 'DEPENDENCIES', []):
hass.pool.add_worker() hass.pool.add_worker()
hass.bus.fire( hass.bus.fire(
@ -133,8 +133,7 @@ def prepare_setup_platform(hass, config, domain, platform_name):
return platform return platform
# Load dependencies # Load dependencies
if hasattr(platform, 'DEPENDENCIES'): for component in getattr(platform, 'DEPENDENCIES', []):
for component in platform.DEPENDENCIES:
if not setup_component(hass, component, config): if not setup_component(hass, component, config):
_LOGGER.error( _LOGGER.error(
'Unable to prepare setup for platform %s because ' 'Unable to prepare setup for platform %s because '

View File

@ -15,7 +15,6 @@ from homeassistant.helpers.entity import Entity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
DOMAIN = 'alarm_control_panel' DOMAIN = 'alarm_control_panel'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -18,8 +18,6 @@ from homeassistant.const import (
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = []
DEFAULT_ALARM_NAME = 'HA Alarm' DEFAULT_ALARM_NAME = 'HA Alarm'
DEFAULT_PENDING_TIME = 60 DEFAULT_PENDING_TIME = 60
DEFAULT_TRIGGER_TIME = 120 DEFAULT_TRIGGER_TIME = 120

View File

@ -19,7 +19,6 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP) EVENT_HOMEASSISTANT_STOP)
DOMAIN = "arduino" DOMAIN = "arduino"
DEPENDENCIES = []
REQUIREMENTS = ['PyMata==2.07a'] REQUIREMENTS = ['PyMata==2.07a']
BOARD = None BOARD = None
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -14,7 +14,6 @@ from homeassistant.helpers.entity import Entity
from homeassistant.const import (STATE_ON, STATE_OFF) from homeassistant.const import (STATE_ON, STATE_OFF)
DOMAIN = 'binary_sensor' DOMAIN = 'binary_sensor'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -8,7 +8,6 @@ https://home-assistant.io/components/browser/
""" """
DOMAIN = "browser" DOMAIN = "browser"
DEPENDENCIES = []
SERVICE_BROWSE_URL = "browse_url" SERVICE_BROWSE_URL = "browse_url"

View File

@ -15,7 +15,6 @@ from homeassistant.helpers import generate_entity_id
from homeassistant.const import EVENT_TIME_CHANGED from homeassistant.const import EVENT_TIME_CHANGED
DOMAIN = "configurator" DOMAIN = "configurator"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"
SERVICE_CONFIGURE = "configure" SERVICE_CONFIGURE = "configure"

View File

@ -14,7 +14,6 @@ from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF) ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
DOMAIN = "conversation" DOMAIN = "conversation"
DEPENDENCIES = []
SERVICE_PROCESS = "process" SERVICE_PROCESS = "process"

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
ATTR_SERVICE, ATTR_DISCOVERED) ATTR_SERVICE, ATTR_DISCOVERED)
DOMAIN = "discovery" DOMAIN = "discovery"
DEPENDENCIES = []
REQUIREMENTS = ['netdisco==0.5.1'] REQUIREMENTS = ['netdisco==0.5.1']
SCAN_INTERVAL = 300 # seconds SCAN_INTERVAL = 300 # seconds

View File

@ -15,7 +15,6 @@ from homeassistant.helpers import validate_config
from homeassistant.util import sanitize_filename from homeassistant.util import sanitize_filename
DOMAIN = "downloader" DOMAIN = "downloader"
DEPENDENCIES = []
SERVICE_DOWNLOAD_FILE = "download_file" SERVICE_DOWNLOAD_FILE = "download_file"

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
STATE_UNKNOWN) STATE_UNKNOWN)
DOMAIN = "group" DOMAIN = "group"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"

View File

@ -34,7 +34,6 @@ import homeassistant.util.dt as date_util
import homeassistant.bootstrap as bootstrap import homeassistant.bootstrap as bootstrap
DOMAIN = "http" DOMAIN = "http"
DEPENDENCIES = []
CONF_API_PASSWORD = "api_password" CONF_API_PASSWORD = "api_password"
CONF_SERVER_HOST = "server_host" CONF_SERVER_HOST = "server_host"

View File

@ -22,8 +22,6 @@ ATTR_VALUE1 = 'value1'
ATTR_VALUE2 = 'value2' ATTR_VALUE2 = 'value2'
ATTR_VALUE3 = 'value3' ATTR_VALUE3 = 'value3'
DEPENDENCIES = []
REQUIREMENTS = ['pyfttt==0.3'] REQUIREMENTS = ['pyfttt==0.3']

View File

@ -9,7 +9,6 @@ https://home-assistant.io/components/introduction/
import logging import logging
DOMAIN = 'introduction' DOMAIN = 'introduction'
DEPENDENCIES = []
def setup(hass, config=None): def setup(hass, config=None):

View File

@ -20,7 +20,6 @@ from homeassistant.const import (
ATTR_FRIENDLY_NAME) ATTR_FRIENDLY_NAME)
DOMAIN = "isy994" DOMAIN = "isy994"
DEPENDENCIES = []
REQUIREMENTS = ['PyISY==1.0.5'] REQUIREMENTS = ['PyISY==1.0.5']
DISCOVER_LIGHTS = "isy994.lights" DISCOVER_LIGHTS = "isy994.lights"
DISCOVER_SWITCHES = "isy994.switches" DISCOVER_SWITCHES = "isy994.switches"

View File

@ -15,7 +15,6 @@ from homeassistant.const import (
DOMAIN = "keyboard" DOMAIN = "keyboard"
DEPENDENCIES = []
REQUIREMENTS = ['pyuserinput==0.1.9'] REQUIREMENTS = ['pyuserinput==0.1.9']

View File

@ -21,7 +21,6 @@ import homeassistant.util.color as color_util
DOMAIN = "light" DOMAIN = "light"
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
GROUP_NAME_ALL_LIGHTS = 'all lights' GROUP_NAME_ALL_LIGHTS = 'all lights'

View File

@ -14,7 +14,6 @@ _LOGGER = logging.getLogger(__name__)
REQUIREMENTS = ["blinkstick==1.1.7"] REQUIREMENTS = ["blinkstick==1.1.7"]
DEPENDENCIES = []
# pylint: disable=unused-argument # pylint: disable=unused-argument

View File

@ -20,7 +20,6 @@ from homeassistant.const import (
from homeassistant.components import (group, wink) from homeassistant.components import (group, wink)
DOMAIN = 'lock' DOMAIN = 'lock'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
GROUP_NAME_ALL_LOCKS = 'all locks' GROUP_NAME_ALL_LOCKS = 'all locks'

View File

@ -10,7 +10,6 @@ import logging
from collections import OrderedDict from collections import OrderedDict
DOMAIN = 'logger' DOMAIN = 'logger'
DEPENDENCIES = []
LOGSEVERITY = { LOGSEVERITY = {
'CRITICAL': 50, 'CRITICAL': 50,

View File

@ -22,7 +22,6 @@ from homeassistant.const import (
SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK) SERVICE_MEDIA_NEXT_TRACK, SERVICE_MEDIA_PREVIOUS_TRACK, SERVICE_MEDIA_SEEK)
DOMAIN = 'media_player' DOMAIN = 'media_player'
DEPENDENCIES = []
SCAN_INTERVAL = 10 SCAN_INTERVAL = 10
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -13,7 +13,6 @@ from homeassistant.const import (EVENT_HOMEASSISTANT_START,
DOMAIN = "modbus" DOMAIN = "modbus"
DEPENDENCIES = []
REQUIREMENTS = ['https://github.com/bashwork/pymodbus/archive/' REQUIREMENTS = ['https://github.com/bashwork/pymodbus/archive/'
'd7fc4f1cc975631e0a9011390e8017f64b612661.zip#pymodbus==1.2.0'] 'd7fc4f1cc975631e0a9011390e8017f64b612661.zip#pymodbus==1.2.0']

View File

@ -33,7 +33,6 @@ DEFAULT_RETAIN = False
SERVICE_PUBLISH = 'publish' SERVICE_PUBLISH = 'publish'
EVENT_MQTT_MESSAGE_RECEIVED = 'MQTT_MESSAGE_RECEIVED' EVENT_MQTT_MESSAGE_RECEIVED = 'MQTT_MESSAGE_RECEIVED'
DEPENDENCIES = []
REQUIREMENTS = ['paho-mqtt==1.1', 'jsonpath-rw==1.4.0'] REQUIREMENTS = ['paho-mqtt==1.1', 'jsonpath-rw==1.4.0']
CONF_BROKER = 'broker' CONF_BROKER = 'broker'

View File

@ -17,7 +17,6 @@ from homeassistant.helpers import config_per_platform
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
DOMAIN = "notify" DOMAIN = "notify"
DEPENDENCIES = []
# Title of notification # Title of notification
ATTR_TITLE = "title" ATTR_TITLE = "title"

View File

@ -23,7 +23,6 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP) EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_STOP)
DOMAIN = "recorder" DOMAIN = "recorder"
DEPENDENCIES = []
DB_FILE = 'home-assistant.db' DB_FILE = 'home-assistant.db'

View File

@ -9,7 +9,6 @@ https://home-assistant.io/components/rfxtrx/
import logging import logging
from homeassistant.util import slugify from homeassistant.util import slugify
DEPENDENCIES = []
REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip' + REQUIREMENTS = ['https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip' +
'#RFXtrx==0.2'] '#RFXtrx==0.2']

View File

@ -76,8 +76,9 @@ def setup(hass, config):
_LOGGER.warn("Found invalid key for script: %s. Use %s instead.", _LOGGER.warn("Found invalid key for script: %s. Use %s instead.",
object_id, slugify(object_id)) object_id, slugify(object_id))
continue continue
if not cfg.get(CONF_SEQUENCE): if not isinstance(cfg.get(CONF_SEQUENCE), list):
_LOGGER.warn("Missing key 'sequence' for script %s", object_id) _LOGGER.warn("Key 'sequence' for script %s should be a list",
object_id)
continue continue
alias = cfg.get(CONF_ALIAS, object_id) alias = cfg.get(CONF_ALIAS, object_id)
script = Script(hass, object_id, alias, cfg[CONF_SEQUENCE]) script = Script(hass, object_id, alias, cfg[CONF_SEQUENCE])

View File

@ -12,7 +12,6 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.components import wink, zwave, isy994, verisure from homeassistant.components import wink, zwave, isy994, verisure
DOMAIN = 'sensor' DOMAIN = 'sensor'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}' ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -12,7 +12,6 @@ import subprocess
from homeassistant.util import slugify from homeassistant.util import slugify
DOMAIN = 'shell_command' DOMAIN = 'shell_command'
DEPENDENCIES = []
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)

View File

@ -15,7 +15,6 @@ import homeassistant.util.dt as dt_util
from homeassistant.helpers.event import track_point_in_utc_time from homeassistant.helpers.event import track_point_in_utc_time
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
DEPENDENCIES = []
REQUIREMENTS = ['astral==0.8.1'] REQUIREMENTS = ['astral==0.8.1']
DOMAIN = "sun" DOMAIN = "sun"
ENTITY_ID = "sun.sun" ENTITY_ID = "sun.sun"

View File

@ -20,7 +20,6 @@ from homeassistant.components import (
group, discovery, wink, isy994, verisure, zwave) group, discovery, wink, isy994, verisure, zwave)
DOMAIN = 'switch' DOMAIN = 'switch'
DEPENDENCIES = []
SCAN_INTERVAL = 30 SCAN_INTERVAL = 30
GROUP_NAME_ALL_SWITCHES = 'all switches' GROUP_NAME_ALL_SWITCHES = 'all switches'

View File

@ -20,7 +20,6 @@ from homeassistant.const import (
TEMP_CELCIUS) TEMP_CELCIUS)
DOMAIN = "thermostat" DOMAIN = "thermostat"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}" ENTITY_ID_FORMAT = DOMAIN + ".{}"
SCAN_INTERVAL = 60 SCAN_INTERVAL = 60

View File

@ -16,7 +16,6 @@ from homeassistant.helpers import event
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
PYPI_URL = 'https://pypi.python.org/pypi/homeassistant/json' PYPI_URL = 'https://pypi.python.org/pypi/homeassistant/json'
DEPENDENCIES = []
DOMAIN = 'updater' DOMAIN = 'updater'
ENTITY_ID = 'updater.updater' ENTITY_ID = 'updater.updater'

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME) ATTR_SERVICE, ATTR_DISCOVERED, ATTR_FRIENDLY_NAME)
DOMAIN = "wink" DOMAIN = "wink"
DEPENDENCIES = []
REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/' REQUIREMENTS = ['https://github.com/balloob/python-wink/archive/'
'42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip' '42fdcfa721b1bc583688e3592d8427f4c13ba6d9.zip'
'#python-wink==0.2'] '#python-wink==0.2']

View File

@ -15,7 +15,6 @@ from homeassistant.helpers.entity import Entity
from homeassistant.util.location import distance from homeassistant.util.location import distance
DOMAIN = "zone" DOMAIN = "zone"
DEPENDENCIES = []
ENTITY_ID_FORMAT = 'zone.{}' ENTITY_ID_FORMAT = 'zone.{}'
ENTITY_ID_HOME = ENTITY_ID_FORMAT.format('home') ENTITY_ID_HOME = ENTITY_ID_FORMAT.format('home')
STATE = 'zoning' STATE = 'zoning'

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED) EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED)
DOMAIN = "zwave" DOMAIN = "zwave"
DEPENDENCIES = []
REQUIREMENTS = ['pydispatcher==2.0.5'] REQUIREMENTS = ['pydispatcher==2.0.5']
CONF_USB_STICK_PATH = "usb_path" CONF_USB_STICK_PATH = "usb_path"

View File

@ -193,7 +193,7 @@ def _load_order_component(comp_name, load_order, loading):
loading.add(comp_name) loading.add(comp_name)
for dependency in component.DEPENDENCIES: for dependency in getattr(component, 'DEPENDENCIES', []):
# Check not already loaded # Check not already loaded
if dependency in load_order: if dependency in load_order:
continue continue

View File

@ -27,23 +27,10 @@ class TestScript(unittest.TestCase):
""" Stop down stuff we started. """ """ Stop down stuff we started. """
self.hass.stop() self.hass.stop()
def test_setup_with_empty_sequence(self):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': []
}
}
}))
self.assertIsNone(self.hass.states.get(ENTITY_ID))
def test_setup_with_missing_sequence(self): def test_setup_with_missing_sequence(self):
self.assertTrue(script.setup(self.hass, { self.assertTrue(script.setup(self.hass, {
'script': { 'script': {
'test': { 'test': {}
'sequence': []
}
} }
})) }))
@ -60,6 +47,19 @@ class TestScript(unittest.TestCase):
self.assertEqual(0, len(self.hass.states.entity_ids('script'))) self.assertEqual(0, len(self.hass.states.entity_ids('script')))
def test_setup_with_dict_as_sequence(self):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': {
'event': 'test_event'
}
}
}
}))
self.assertEqual(0, len(self.hass.states.entity_ids('script')))
def test_firing_event(self): def test_firing_event(self):
event = 'test_event' event = 'test_event'
calls = [] calls = []