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
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 missing_deps:
@ -106,7 +106,7 @@ def _setup_component(hass, domain, config):
# Assumption: if a component does not depend on groups
# it communicates with devices
if group.DOMAIN not in component.DEPENDENCIES:
if group.DOMAIN not in getattr(component, 'DEPENDENCIES', []):
hass.pool.add_worker()
hass.bus.fire(
@ -133,14 +133,13 @@ def prepare_setup_platform(hass, config, domain, platform_name):
return platform
# Load dependencies
if hasattr(platform, 'DEPENDENCIES'):
for component in platform.DEPENDENCIES:
if not setup_component(hass, component, config):
_LOGGER.error(
'Unable to prepare setup for platform %s because '
'dependency %s could not be initialized', platform_path,
component)
return None
for component in getattr(platform, 'DEPENDENCIES', []):
if not setup_component(hass, component, config):
_LOGGER.error(
'Unable to prepare setup for platform %s because '
'dependency %s could not be initialized', platform_path,
component)
return None
if not _handle_requirements(hass, platform, platform_path):
return None

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ https://home-assistant.io/components/browser/
"""
DOMAIN = "browser"
DEPENDENCIES = []
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
DOMAIN = "configurator"
DEPENDENCIES = []
ENTITY_ID_FORMAT = DOMAIN + ".{}"
SERVICE_CONFIGURE = "configure"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -76,8 +76,9 @@ def setup(hass, config):
_LOGGER.warn("Found invalid key for script: %s. Use %s instead.",
object_id, slugify(object_id))
continue
if not cfg.get(CONF_SEQUENCE):
_LOGGER.warn("Missing key 'sequence' for script %s", object_id)
if not isinstance(cfg.get(CONF_SEQUENCE), list):
_LOGGER.warn("Key 'sequence' for script %s should be a list",
object_id)
continue
alias = cfg.get(CONF_ALIAS, object_id)
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
DOMAIN = 'sensor'
DEPENDENCIES = []
SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}'

View File

@ -12,7 +12,6 @@ import subprocess
from homeassistant.util import slugify
DOMAIN = 'shell_command'
DEPENDENCIES = []
_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.entity import Entity
DEPENDENCIES = []
REQUIREMENTS = ['astral==0.8.1']
DOMAIN = "sun"
ENTITY_ID = "sun.sun"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,7 +17,6 @@ from homeassistant.const import (
EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE, ATTR_DISCOVERED)
DOMAIN = "zwave"
DEPENDENCIES = []
REQUIREMENTS = ['pydispatcher==2.0.5']
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)
for dependency in component.DEPENDENCIES:
for dependency in getattr(component, 'DEPENDENCIES', []):
# Check not already loaded
if dependency in load_order:
continue

View File

@ -27,23 +27,10 @@ class TestScript(unittest.TestCase):
""" Stop down stuff we started. """
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):
self.assertTrue(script.setup(self.hass, {
'script': {
'test': {
'sequence': []
}
'test': {}
}
}))
@ -60,6 +47,19 @@ class TestScript(unittest.TestCase):
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):
event = 'test_event'
calls = []