Always load Hass.io component on Hass.io (#22185)

* Always load Hass.io component on Hass.io

* Lint

* Lint
This commit is contained in:
Paulus Schoutsen 2019-03-19 11:33:50 -07:00 committed by GitHub
parent 88669c6543
commit 92dc26bab3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 26 deletions

View file

@ -127,10 +127,7 @@ async def async_from_config_dict(config: Dict[str, Any],
hass.config_entries = config_entries.ConfigEntries(hass, config)
await hass.config_entries.async_initialize()
# Filter out the repeating and common config section [homeassistant]
components = set(key.split(' ')[0] for key in config.keys()
if key != core.DOMAIN)
components.update(hass.config_entries.async_domains())
components = _get_components(hass, config)
# Resolve all dependencies of all components.
for component in list(components):
@ -391,3 +388,20 @@ async def async_mount_local_lib_path(config_dir: str) -> str:
if lib_dir not in sys.path:
sys.path.insert(0, lib_dir)
return deps_dir
@core.callback
def _get_components(hass: core.HomeAssistant, config: Dict[str, Any]):
"""Get components to set up."""
# Filter out the repeating and common config section [homeassistant]
components = set(key.split(' ')[0] for key in config.keys()
if key != core.DOMAIN)
# Add config entry domains
components.update(hass.config_entries.async_domains())
# Make sure the Hass.io component is loaded
if 'HASSIO' in os.environ:
components.add('hassio')
return components

View file

@ -9,7 +9,6 @@ loaded before the EVENT_PLATFORM_DISCOVERED is fired.
import json
from datetime import timedelta
import logging
import os
import voluptuous as vol
@ -199,10 +198,6 @@ async def async_setup(hass, config):
"""Schedule the first discovery when Home Assistant starts up."""
async_track_point_in_utc_time(hass, scan_devices, dt_util.utcnow())
# Discovery for local services
if 'HASSIO' in os.environ:
hass.async_create_task(new_service_found(SERVICE_HASSIO, {}))
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, schedule_first)
return True

View file

@ -1,6 +1,5 @@
"""The tests for the discovery component."""
import asyncio
import os
from unittest.mock import patch, MagicMock
import pytest
@ -142,21 +141,6 @@ def test_discover_duplicates(hass):
SERVICE_NO_PLATFORM_COMPONENT, BASE_CONFIG)
@asyncio.coroutine
def test_load_component_hassio(hass):
"""Test load hassio component."""
def discover(netdisco):
"""Fake discovery."""
return []
with patch.dict(os.environ, {'HASSIO': "FAKE_HASSIO"}), \
patch('homeassistant.components.hassio.async_setup',
return_value=mock_coro(return_value=True)) as mock_hassio:
yield from mock_discovery(hass, discover)
assert mock_hassio.called
async def test_discover_config_flow(hass):
"""Test discovery triggering a config flow."""
discovery_info = {

View file

@ -34,7 +34,7 @@ def test_from_config_file(hass):
}
with patch_yaml_files(files, True):
yield from bootstrap.async_from_config_file('config.yaml')
yield from bootstrap.async_from_config_file('config.yaml', hass)
assert components == hass.config.components
@ -103,3 +103,12 @@ async def test_async_from_config_file_not_mount_deps_folder(loop):
await bootstrap.async_from_config_file('mock-path', hass)
assert len(mock_mount.mock_calls) == 0
async def test_load_hassio(hass):
"""Test that we load Hass.io component."""
with patch.dict(os.environ, {}, clear=True):
assert bootstrap._get_components(hass, {}) == set()
with patch.dict(os.environ, {'HASSIO': '1'}):
assert bootstrap._get_components(hass, {}) == {'hassio'}