def setup_hass_instance(emulated_hue_config):
    hass = get_test_home_assistant()

    # We need to do this to get access to homeassistant/turn_(on,off)
    core_components.setup(hass, {core.DOMAIN: {}})

    bootstrap.setup_component(
        hass, http.DOMAIN,
        {http.DOMAIN: {http.CONF_SERVER_PORT: HTTP_SERVER_PORT}})

    bootstrap.setup_component(hass, emulated_hue.DOMAIN, emulated_hue_config)

    return hass
Пример #2
0
    def setUp(self):  # pylint: disable=invalid-name
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.assertTrue(comps.setup(self.hass, {}))

        self.hass.states.set('light.Bowl', STATE_ON)
        self.hass.states.set('light.Ceiling', STATE_OFF)
Пример #3
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = homeassistant.HomeAssistant()

    enable_logging(hass)

    loader.prepare(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    config = defaultdict(dict, config)

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != homeassistant.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error("Home Assistant core failed to initialize. "
                      "Further initialization aborted.")

        return hass

    _LOGGER.info("Home Assistant core initialized")

    # Setup the components
    for domain in loader.load_order_components(components):
        setup_component(hass, domain, config)

    return hass
Пример #4
0
    def setUp(self):  # pylint: disable=invalid-name
        """ Init needed objects. """
        self.hass = ha.HomeAssistant()
        self.assertTrue(comps.setup(self.hass, {}))

        self.hass.states.set('light.Bowl', STATE_ON)
        self.hass.states.set('light.Ceiling', STATE_OFF)
Пример #5
0
    def setUp(self):  # pylint: disable=invalid-name
        """ Init needed objects. """
        self.hass = get_test_home_assistant()
        self.assertTrue(comps.setup(self.hass, {}))

        self.hass.states.set("light.Bowl", STATE_ON)
        self.hass.states.set("light.Ceiling", STATE_OFF)
Пример #6
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = homeassistant.HomeAssistant()

    process_ha_core_config(hass, config.get(homeassistant.DOMAIN, {}))

    enable_logging(hass)

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(dict, {key: value or {} for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys() if " " not in key and key != homeassistant.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error("Home Assistant core failed to initialize. " "Further initialization aborted.")

        return hass

    _LOGGER.info("Home Assistant core initialized")

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #7
0
    def setUp(self):  # pylint: disable=invalid-name
        """ Init needed objects. """
        self.hass = ha.HomeAssistant()
        self.assertTrue(comps.setup(self.hass, {}))

        self.hass.states.set('light.Bowl', STATE_ON)
        self.hass.states.set('light.Ceiling', STATE_OFF)
Пример #8
0
def from_config_dict(config,
                     hass=None,
                     config_dir=None,
                     enable_log=True,
                     verbose=False,
                     daemon=False,
                     skip_pip=False,
                     log_rotate_days=None):
    """Try to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = core.HomeAssistant()
        if config_dir is not None:
            config_dir = os.path.abspath(config_dir)
            hass.config.config_dir = config_dir
            mount_local_lib_path(config_dir)

    process_ha_config_upgrade(hass)
    process_ha_core_config(hass, config.get(core.DOMAIN, {}))

    if enable_log:
        enable_logging(hass, verbose, daemon, log_rotate_days)

    hass.config.skip_pip = skip_pip
    if skip_pip:
        _LOGGER.warning('Skipping pip installation of required modules. '
                        'This may cause issues.')

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(dict,
                         {key: value or {}
                          for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = set(
        key.split(' ')[0] for key in config.keys() if key != core.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error('Home Assistant core failed to initialize. '
                      'Further initialization aborted.')

        return hass

    _LOGGER.info('Home Assistant core initialized')

    # Give event decorators access to HASS
    event_decorators.HASS = hass
    service.HASS = hass

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #9
0
    def setUp(self):  # pylint: disable=invalid-name
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()
        self.assertTrue(comps.setup(self.hass, {}))

        self.hass.states.set('light.Bowl', STATE_ON)
        self.hass.states.set('light.Ceiling', STATE_OFF)
Пример #10
0
def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
                     verbose=False, daemon=False, skip_pip=False,
                     log_rotate_days=None):
    """Try to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = core.HomeAssistant()
        if config_dir is not None:
            config_dir = os.path.abspath(config_dir)
            hass.config.config_dir = config_dir
            mount_local_lib_path(config_dir)

    try:
        process_ha_core_config(hass, config_util.CORE_CONFIG_SCHEMA(
            config.get(core.DOMAIN, {})))
    except vol.MultipleInvalid as ex:
        _LOGGER.error('Invalid config for [homeassistant]: %s', ex)
        return None

    process_ha_config_upgrade(hass)

    if enable_log:
        enable_logging(hass, verbose, daemon, log_rotate_days)

    hass.config.skip_pip = skip_pip
    if skip_pip:
        _LOGGER.warning('Skipping pip installation of required modules. '
                        'This may cause issues.')

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(
        dict, {key: value or {} for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = set(key.split(' ')[0] for key in config.keys()
                     if key != core.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error('Home Assistant core failed to initialize. '
                      'Further initialization aborted.')

        return hass

    _LOGGER.info('Home Assistant core initialized')

    # Give event decorators access to HASS
    event_decorators.HASS = hass
    service.HASS = hass

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #11
0
 def setUp(self):  # pylint: disable=invalid-name
     """ Start up ha for testing """
     self.ent_id = 'light.kitchen_lights'
     self.hass = get_test_home_assistant(3)
     self.hass.states.set(self.ent_id, 'on')
     self.assertTrue(core_components.setup(self.hass, {}))
     self.assertTrue(
         conversation.setup(self.hass, {conversation.DOMAIN: {}}))
Пример #12
0
 def setUp(self):  # pylint: disable=invalid-name
     """Setup things to be run when tests are started."""
     self.ent_id = 'light.kitchen_lights'
     self.hass = get_test_home_assistant(3)
     self.hass.states.set(self.ent_id, 'on')
     self.assertTrue(core_components.setup(self.hass, {}))
     self.assertTrue(setup_component(self.hass, conversation.DOMAIN, {
         conversation.DOMAIN: {}}))
Пример #13
0
 def setUp(self):  # pylint: disable=invalid-name
     """ Start up ha for testing """
     self.ent_id = 'light.kitchen_lights'
     self.hass = get_test_home_assistant(3)
     self.hass.states.set(self.ent_id, 'on')
     self.assertTrue(core_components.setup(self.hass, {}))
     self.assertTrue(
         conversation.setup(self.hass, {conversation.DOMAIN: {}}))
 def setUp(self):  # pylint: disable=invalid-name
     """Setup things to be run when tests are started."""
     self.ent_id = 'light.kitchen_lights'
     self.hass = get_test_home_assistant(3)
     self.hass.states.set(self.ent_id, 'on')
     self.assertTrue(core_components.setup(self.hass, {}))
     self.assertTrue(
         setup_component(self.hass, conversation.DOMAIN,
                         {conversation.DOMAIN: {}}))
Пример #15
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = homeassistant.HomeAssistant()

    logger = logging.getLogger(__name__)

    loader.prepare(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    config = defaultdict(dict, config)

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != homeassistant.DOMAIN)

    if not core_components.setup(hass, config):
        logger.error(("Home Assistant core failed to initialize. "
                      "Further initialization aborted."))

        return hass

    logger.info("Home Assistant core initialized")

    # Setup the components

    # We assume that all components that load before the group component loads
    # are components that poll devices. As their tasks are IO based, we will
    # add an extra worker for each of them.
    add_worker = True

    for domain in loader.load_order_components(components):
        component = loader.get_component(domain)

        try:
            if component.setup(hass, config):
                logger.info("component %s initialized", domain)

                add_worker = add_worker and domain != "group"

                if add_worker:
                    hass.pool.add_worker()

            else:
                logger.error("component %s failed to initialize", domain)

        except Exception:  # pylint: disable=broad-except
            logger.exception("Error during setup of component %s", domain)

    return hass
Пример #16
0
def from_config_dict(
    config,
    hass=None,
    config_dir=None,
    enable_log=True,
    verbose=False,
    daemon=False,
    skip_pip=False,
    log_rotate_days=None,
):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = core.HomeAssistant()
        if config_dir is not None:
            config_dir = os.path.abspath(config_dir)
            hass.config.config_dir = config_dir
            mount_local_lib_path(config_dir)

    process_ha_config_upgrade(hass)
    process_ha_core_config(hass, config.get(core.DOMAIN, {}))

    if enable_log:
        enable_logging(hass, verbose, daemon, log_rotate_days)

    hass.config.skip_pip = skip_pip
    if skip_pip:
        _LOGGER.warning("Skipping pip installation of required modules. " "This may cause issues.")

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(dict, {key: value or {} for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = set(key.split(" ")[0] for key in config.keys() if key != core.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error("Home Assistant core failed to initialize. " "Further initialization aborted.")

        return hass

    _LOGGER.info("Home Assistant core initialized")

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #17
0
    def component_setup():
        """Set up a component."""
        if not core_components.setup(hass, config):
            _LOGGER.error("Home Assistant core failed to initialize. " "Further initialization aborted.")
            return hass

        persistent_notification.setup(hass, config)

        _LOGGER.info("Home Assistant core initialized")

        # Give event decorators access to HASS
        event_decorators.HASS = hass
        service.HASS = hass

        # Setup the components
        for domain in loader.load_order_components(components):
            _setup_component(hass, domain, config)
Пример #18
0
    def component_setup():
        """Set up a component."""
        if not core_components.setup(hass, config):
            _LOGGER.error('Home Assistant core failed to initialize. '
                          'Further initialization aborted.')
            return hass

        persistent_notification.setup(hass, config)

        _LOGGER.info('Home Assistant core initialized')

        # Give event decorators access to HASS
        event_decorators.HASS = hass
        service.HASS = hass

        # Setup the components
        for domain in loader.load_order_components(components):
            _setup_component(hass, domain, config)
Пример #19
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.


    Dynamically loads required components and its dependencies.
    """

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    config = defaultdict(dict, config)

    if hass is None:
        hass = homeassistant.HomeAssistant(config)

    logger = logging.getLogger(__name__)

    loader.prepare(hass)


    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != homeassistant.DOMAIN)

    # Setup the components
    if core_components.setup(hass, config):
        logger.info("Home Assistant core initialized")

        for domain in loader.load_order_components(components):
            if domain is not "pushbullet":
                try:
                    if loader.get_component(domain).setup(hass, config):
                        logger.info("component %s initialized", domain)
                    else:
                        logger.error("component %s failed to initialize", domain)

                except Exception:  # pylint: disable=broad-except
                    logger.exception("Error during setup of component %s", domain)

    else:
        logger.error(("Home Assistant core failed to initialize. "
                      "Further initialization aborted."))

    return hass
Пример #20
0
def from_config_dict(config, hass=None, config_dir=None, enable_log=True,
                     verbose=False, daemon=False):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = core.HomeAssistant()
        if config_dir is not None:
            config_dir = os.path.abspath(config_dir)
            hass.config.config_dir = config_dir
            mount_local_lib_path(config_dir)

    process_ha_core_config(hass, config.get(core.DOMAIN, {}))

    if enable_log:
        enable_logging(hass, verbose, daemon)

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(
        dict, {key: value or {} for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != core.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error('Home Assistant core failed to initialize. '
                      'Further initialization aborted.')

        return hass

    _LOGGER.info('Home Assistant core initialized')

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #21
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = homeassistant.HomeAssistant()

    logger = logging.getLogger(__name__)

    loader.prepare(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    config = defaultdict(dict, config)

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != homeassistant.DOMAIN)

    # Setup the components
    if core_components.setup(hass, config):
        logger.info("Home Assistant core initialized")

        for domain in loader.load_order_components(components):
            try:
                if loader.get_component(domain).setup(hass, config):
                    logger.info("component %s initialized", domain)
                else:
                    logger.error("component %s failed to initialize", domain)

            except Exception:  # pylint: disable=broad-except
                logger.exception("Error during setup of component %s", domain)

    else:
        logger.error(("Home Assistant core failed to initialize. "
                      "Further initialization aborted."))

    return hass
Пример #22
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = core.HomeAssistant()

    process_ha_core_config(hass, config.get(core.DOMAIN, {}))

    enable_logging(hass)

    _ensure_loader_prepared(hass)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    # Convert values to dictionaries if they are None
    config = defaultdict(dict,
                         {key: value or {}
                          for key, value in config.items()})

    # Filter out the repeating and common config section [homeassistant]
    components = (key for key in config.keys()
                  if ' ' not in key and key != core.DOMAIN)

    if not core_components.setup(hass, config):
        _LOGGER.error('Home Assistant core failed to initialize. '
                      'Further initialization aborted.')

        return hass

    _LOGGER.info('Home Assistant core initialized')

    # Setup the components
    for domain in loader.load_order_components(components):
        _setup_component(hass, domain, config)

    return hass
Пример #23
0
 def setUp(self):     # pylint: disable=invalid-name
     """Run when tests are started."""
     self.hass = get_test_home_assistant()
     core_components.setup(self.hass, {})
Пример #24
0
def from_config_dict(config, hass=None):
    """
    Tries to configure Home Assistant from a config dict.

    Dynamically loads required components and its dependencies.
    """
    if hass is None:
        hass = homeassistant.HomeAssistant()

    logger = logging.getLogger(__name__)

    # Make a copy because we are mutating it.
    # Convert it to defaultdict so components can always have config dict
    config = defaultdict(dict, config)

    # List of loaded components
    components = {}

    # List of components to validate
    to_validate = []

    # List of validated components
    validated = []

    # List of components we are going to load
    to_load = [key for key in config.keys() if key != homeassistant.DOMAIN]

    # Load required components
    while to_load:
        domain = to_load.pop()

        component = core_components.get_component(domain, logger)

        # if None it does not exist, error already thrown by get_component
        if component is not None:
            components[domain] = component

            # Special treatment for GROUP, we want to load it as late as
            # possible. We do this by loading it if all other to be loaded
            # modules depend on it.
            if component.DOMAIN == group.DOMAIN:
                pass

            # Components with no dependencies are valid
            elif not component.DEPENDENCIES:
                validated.append(domain)

            # If dependencies we'll validate it later
            else:
                to_validate.append(domain)

                # Make sure to load all dependencies that are not being loaded
                for dependency in component.DEPENDENCIES:
                    if dependency not in chain(components.keys(), to_load):
                        to_load.append(dependency)

    # Validate dependencies
    group_added = False

    while to_validate:
        newly_validated = []

        for domain in to_validate:
            if all(domain in validated for domain
                   in components[domain].DEPENDENCIES):

                newly_validated.append(domain)

        # We validated new domains this iteration, add them to validated
        if newly_validated:

            # Add newly validated domains to validated
            validated.extend(newly_validated)

            # remove domains from to_validate
            for domain in newly_validated:
                to_validate.remove(domain)

            newly_validated.clear()

        # Nothing validated this iteration. Add group dependency and try again.
        elif not group_added:
            group_added = True
            validated.append(group.DOMAIN)

        # Group has already been added and we still can't validate all.
        # Report missing deps as error and skip loading of these domains
        else:
            for domain in to_validate:
                missing_deps = [dep for dep in components[domain].DEPENDENCIES
                                if dep not in validated]

                logger.error(
                    "Could not validate all dependencies for {}: {}".format(
                        domain, ", ".join(missing_deps)))

            break

    # Make sure we load groups if not in list yet.
    if not group_added:
        validated.append(group.DOMAIN)

        if group.DOMAIN not in components:
            components[group.DOMAIN] = \
                core_components.get_component(group.DOMAIN, logger)

    # Setup the components
    if core_components.setup(hass, config):
        logger.info("Home Assistant core initialized")

        for domain in validated:
            component = components[domain]

            try:
                if component.setup(hass, config):
                    logger.info("component {} initialized".format(domain))
                else:
                    logger.error(
                        "component {} failed to initialize".format(domain))

            except Exception:  # pylint: disable=broad-except
                logger.exception(
                    "Error during setup of component {}".format(domain))

    else:
        logger.error(("Home Assistant core failed to initialize. "
                      "Further initialization aborted."))

    return hass
Пример #25
0
 def setUp(self):  # pylint: disable=invalid-name
     """ Things to be run when tests are started. """
     self.hass = get_test_home_assistant()
     core_components.setup(self.hass, {})