mirror of https://github.com/home-assistant/core
Add default_config component (#20799)
* Add default config component * Add default_config to default config * Fix comments
This commit is contained in:
parent
222c4ea6f3
commit
e59240fa00
|
@ -0,0 +1,23 @@
|
|||
"""Component providing default configuration for new users."""
|
||||
|
||||
DOMAIN = 'default_config'
|
||||
DEPENDENCIES = (
|
||||
'automation',
|
||||
'cloud',
|
||||
'config',
|
||||
'conversation',
|
||||
'discovery',
|
||||
'frontend',
|
||||
'history',
|
||||
'logbook',
|
||||
'map',
|
||||
'script',
|
||||
'sun',
|
||||
'system_health',
|
||||
'updater',
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Initialize default configuration."""
|
||||
return True
|
|
@ -105,7 +105,7 @@ CONF_IGNORE = 'ignore'
|
|||
CONF_ENABLE = 'enable'
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(DOMAIN): vol.Schema({
|
||||
vol.Optional(DOMAIN): vol.Schema({
|
||||
vol.Optional(CONF_IGNORE, default=[]):
|
||||
vol.All(cv.ensure_list, [
|
||||
vol.In(list(CONFIG_ENTRY_HANDLERS) + list(SERVICE_HANDLERS))]),
|
||||
|
@ -126,11 +126,15 @@ async def async_setup(hass, config):
|
|||
# Disable zeroconf logging, it spams
|
||||
logging.getLogger('zeroconf').setLevel(logging.CRITICAL)
|
||||
|
||||
# Platforms ignore by config
|
||||
ignored_platforms = config[DOMAIN][CONF_IGNORE]
|
||||
if DOMAIN in config:
|
||||
# Platforms ignore by config
|
||||
ignored_platforms = config[DOMAIN][CONF_IGNORE]
|
||||
|
||||
# Optional platforms enabled by config
|
||||
enabled_platforms = config[DOMAIN][CONF_ENABLE]
|
||||
# Optional platforms enabled by config
|
||||
enabled_platforms = config[DOMAIN][CONF_ENABLE]
|
||||
else:
|
||||
ignored_platforms = []
|
||||
enabled_platforms = []
|
||||
|
||||
async def new_service_found(service, info):
|
||||
"""Handle a new service if one is found."""
|
||||
|
|
|
@ -124,7 +124,7 @@ async def _async_process_config(hass, config, component):
|
|||
|
||||
scripts = []
|
||||
|
||||
for object_id, cfg in config[DOMAIN].items():
|
||||
for object_id, cfg in config.get(DOMAIN, {}).items():
|
||||
alias = cfg.get(CONF_ALIAS, object_id)
|
||||
script = ScriptEntity(hass, object_id, alias, cfg[CONF_SEQUENCE])
|
||||
scripts.append(script)
|
||||
|
|
|
@ -65,49 +65,16 @@ DEFAULT_CORE_CONFIG = (
|
|||
(CONF_CUSTOMIZE, '!include customize.yaml', None, 'Customization file'),
|
||||
) # type: Tuple[Tuple[str, Any, Any, Optional[str]], ...]
|
||||
DEFAULT_CONFIG = """
|
||||
# Show links to resources in log and frontend
|
||||
# Configure a default setup of Home Assistant (frontend, api, etc)
|
||||
default_config:
|
||||
|
||||
# Show the introduction message on startup.
|
||||
introduction:
|
||||
|
||||
# Enables the frontend
|
||||
frontend:
|
||||
|
||||
# Enables configuration UI
|
||||
config:
|
||||
|
||||
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
|
||||
# http:
|
||||
# base_url: example.duckdns.org:8123
|
||||
|
||||
# Checks for available updates
|
||||
# Note: This component will send some information about your system to
|
||||
# the developers to assist with development of Home Assistant.
|
||||
# For more information, please see:
|
||||
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
|
||||
updater:
|
||||
# Optional, allows Home Assistant developers to focus on popular components.
|
||||
# include_used_components: true
|
||||
|
||||
# Discover some devices automatically
|
||||
discovery:
|
||||
|
||||
# Allows you to issue voice commands from the frontend in enabled browsers
|
||||
conversation:
|
||||
|
||||
# Enables support for tracking state changes over time
|
||||
history:
|
||||
|
||||
# View all events in a logbook
|
||||
logbook:
|
||||
|
||||
# Enables a map showing the location of tracked devices
|
||||
map:
|
||||
|
||||
# Track the sun
|
||||
sun:
|
||||
|
||||
# Allow diagnosing system problems
|
||||
system_health:
|
||||
|
||||
# Sensors
|
||||
sensor:
|
||||
# Weather prediction
|
||||
|
@ -117,9 +84,6 @@ sensor:
|
|||
tts:
|
||||
- platform: google
|
||||
|
||||
# Cloud
|
||||
cloud:
|
||||
|
||||
group: !include groups.yaml
|
||||
automation: !include automations.yaml
|
||||
script: !include scripts.yaml
|
||||
|
|
|
@ -63,7 +63,7 @@ async def _async_process_dependencies(
|
|||
blacklisted = [dep for dep in dependencies
|
||||
if dep in loader.DEPENDENCY_BLACKLIST]
|
||||
|
||||
if blacklisted:
|
||||
if blacklisted and name != 'default_config':
|
||||
_LOGGER.error("Unable to set up dependencies of %s: "
|
||||
"found blacklisted dependencies: %s",
|
||||
name, ', '.join(blacklisted))
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
"""Tests for the default config component."""
|
|
@ -0,0 +1,27 @@
|
|||
"""Test the default_config init."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.common import MockDependency
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def netdisco_mock():
|
||||
"""Mock netdisco."""
|
||||
with MockDependency('netdisco', 'discovery'):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def recorder_url_mock():
|
||||
"""Mock recorder url."""
|
||||
with patch('homeassistant.components.recorder.DEFAULT_URL', 'sqlite://'):
|
||||
yield
|
||||
|
||||
|
||||
async def test_setup(hass):
|
||||
"""Test setup."""
|
||||
assert await async_setup_component(hass, 'default_config', {})
|
Loading…
Reference in New Issue