mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
[core.config] Support customize in packages (#5543)
* Support customize in packages * GMT * Update test_config.py
This commit is contained in:
committed by
Paulus Schoutsen
parent
923431110a
commit
f2870c3103
@@ -4,7 +4,6 @@ from collections import OrderedDict
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
from types import MappingProxyType
|
||||
# pylint: disable=unused-import
|
||||
from typing import Any, List, Tuple # NOQA
|
||||
|
||||
@@ -121,9 +120,8 @@ CORE_CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_TEMPERATURE_UNIT): cv.temperature_unit,
|
||||
CONF_UNIT_SYSTEM: cv.unit_system,
|
||||
CONF_TIME_ZONE: cv.time_zone,
|
||||
vol.Required(CONF_CUSTOMIZE,
|
||||
default=MappingProxyType({})): vol.All(
|
||||
_convert_old_config, [CUSTOMIZE_SCHEMA_ENTRY]),
|
||||
vol.Optional(CONF_CUSTOMIZE, default=[]): vol.All(
|
||||
_convert_old_config, [CUSTOMIZE_SCHEMA_ENTRY]),
|
||||
vol.Optional(CONF_PACKAGES, default={}): PACKAGES_CONFIG_SCHEMA,
|
||||
})
|
||||
|
||||
@@ -308,7 +306,9 @@ def async_process_ha_core_config(hass, config):
|
||||
if CONF_TIME_ZONE in config:
|
||||
set_time_zone(config.get(CONF_TIME_ZONE))
|
||||
|
||||
set_customize(hass, config.get(CONF_CUSTOMIZE) or {})
|
||||
customize = merge_packages_customize(
|
||||
config[CONF_CUSTOMIZE], config[CONF_PACKAGES])
|
||||
set_customize(hass, customize)
|
||||
|
||||
if CONF_UNIT_SYSTEM in config:
|
||||
if config[CONF_UNIT_SYSTEM] == CONF_UNIT_SYSTEM_IMPERIAL:
|
||||
@@ -407,6 +407,8 @@ def merge_packages_config(config, packages):
|
||||
PACKAGES_CONFIG_SCHEMA(packages)
|
||||
for pack_name, pack_conf in packages.items():
|
||||
for comp_name, comp_conf in pack_conf.items():
|
||||
if comp_name == CONF_CORE:
|
||||
continue
|
||||
component = get_component(comp_name)
|
||||
|
||||
if component is None:
|
||||
@@ -459,3 +461,18 @@ def merge_packages_config(config, packages):
|
||||
config[comp_name] = comp_conf
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def merge_packages_customize(customize, packages):
|
||||
"""Merge customize from packages."""
|
||||
schema = vol.Schema({
|
||||
vol.Optional(CONF_CORE): vol.Schema({
|
||||
CONF_CUSTOMIZE: vol.All(
|
||||
_convert_old_config, [CUSTOMIZE_SCHEMA_ENTRY])})
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
cust = list(customize)
|
||||
for pkg in packages.values():
|
||||
conf = schema(pkg)
|
||||
cust.extend(conf.get(CONF_CORE, {}).get(CONF_CUSTOMIZE, []))
|
||||
return cust
|
||||
|
||||
Reference in New Issue
Block a user