Move core service from core to components (#5787)

* Move core servcie from core to components

* add new handler for signals/exception

* Static persistent id

* Move unittest

* fix coro/callback

* Add more unittest for new services

* Address comments

* Update __init__.py
This commit is contained in:
Pascal Vizeli 2017-02-08 18:17:52 +01:00 committed by Paulus Schoutsen
parent 08efe2bf6d
commit 3f82ef64a1
6 changed files with 165 additions and 102 deletions

View file

@ -3,7 +3,9 @@ import asyncio
from collections import OrderedDict
import logging
import os
import re
import shutil
import sys
# pylint: disable=unused-import
from typing import Any, List, Tuple # NOQA
@ -453,3 +455,30 @@ def merge_packages_customize(core_customize, packages):
conf = schema(pkg)
cust.extend(conf.get(CONF_CORE, {}).get(CONF_CUSTOMIZE, []))
return cust
@asyncio.coroutine
def async_check_ha_config_file(hass):
"""Check if HA config file valid.
This method is a coroutine.
"""
import homeassistant.components.persistent_notification as pn
proc = yield from asyncio.create_subprocess_exec(
sys.argv[0],
'--script',
'check_config',
stdout=asyncio.subprocess.PIPE)
# Wait for the subprocess exit
(stdout_data, dummy) = yield from proc.communicate()
result = yield from proc.wait()
if result:
content = re.sub(r'\033\[[^m]*m', '', str(stdout_data, 'utf-8'))
# Put error cleaned from color codes in the error log so it
# will be visible at the UI.
_LOGGER.error(content)
pn.async_create(
hass, "Config error. See dev-info panel for details.",
"Config validating", "{0}.check_config".format(CONF_CORE))
raise HomeAssistantError("Invalid config")