"""Component to configure Home Assistant via an API."""
import asyncio
import os

import voluptuous as vol

from homeassistant.core import callback
from homeassistant.const import EVENT_COMPONENT_LOADED, CONF_ID
from homeassistant.setup import (
    async_prepare_setup_platform, ATTR_COMPONENT)
from homeassistant.components.http import HomeAssistantView
from homeassistant.util.yaml import load_yaml, dump

DOMAIN = 'config'
DEPENDENCIES = ['http']
SECTIONS = (
    'automation',
    'config_entries',
    'core',
    'customize',
    'device_registry',
    'entity_registry',
    'group',
    'hassbian',
    'script',
)
ON_DEMAND = ('zwave',)


async def async_setup(hass, config):
    """Set up the config component."""
    await hass.components.frontend.async_register_built_in_panel(
        'config', 'config', 'hass:settings')

    async def setup_panel(panel_name):
        """Set up a panel."""
        panel = await async_prepare_setup_platform(
            hass, config, DOMAIN, panel_name)

        if not panel:
            return

        success = await panel.async_setup(hass)

        if success:
            key = '{}.{}'.format(DOMAIN, panel_name)
            hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: key})
            hass.config.components.add(key)

    @callback
    def component_loaded(event):
        """Respond to components being loaded."""
        panel_name = event.data.get(ATTR_COMPONENT)