mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fire event when core config is updated (#23922)
* Fire event when core config is updated
This commit is contained in:
@@ -23,14 +23,16 @@ from homeassistant.const import (
|
||||
__version__, CONF_CUSTOMIZE, CONF_CUSTOMIZE_DOMAIN, CONF_CUSTOMIZE_GLOB,
|
||||
CONF_WHITELIST_EXTERNAL_DIRS, CONF_AUTH_PROVIDERS, CONF_AUTH_MFA_MODULES,
|
||||
CONF_TYPE, CONF_ID)
|
||||
from homeassistant.core import callback, DOMAIN as CONF_CORE, HomeAssistant
|
||||
from homeassistant.core import (
|
||||
DOMAIN as CONF_CORE, SOURCE_DISCOVERED, SOURCE_YAML, HomeAssistant,
|
||||
callback)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.loader import (
|
||||
Integration, async_get_integration, IntegrationNotFound
|
||||
)
|
||||
from homeassistant.util.yaml import load_yaml, SECRET_YAML
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import dt as date_util, location as loc_util
|
||||
from homeassistant.util import location as loc_util
|
||||
from homeassistant.util.unit_system import IMPERIAL_SYSTEM, METRIC_SYSTEM
|
||||
from homeassistant.helpers.entity_values import EntityValues
|
||||
from homeassistant.helpers import config_per_platform, extract_domain_configs
|
||||
@@ -50,13 +52,6 @@ FILE_MIGRATION = (
|
||||
('ios.conf', '.ios.conf'),
|
||||
)
|
||||
|
||||
CORE_STORAGE_KEY = 'homeassistant.core_config'
|
||||
CORE_STORAGE_VERSION = 1
|
||||
|
||||
SOURCE_DISCOVERED = 'discovered'
|
||||
SOURCE_STORAGE = 'storage'
|
||||
SOURCE_YAML = 'yaml'
|
||||
|
||||
DEFAULT_CORE_CONFIG = (
|
||||
# Tuples (attribute, default, auto detect property, description)
|
||||
(CONF_NAME, 'Home', None, 'Name of the location where Home Assistant is '
|
||||
@@ -478,42 +473,6 @@ def _format_config_error(ex: vol.Invalid, domain: str, config: Dict) -> str:
|
||||
return message
|
||||
|
||||
|
||||
def _set_time_zone(hass: HomeAssistant, time_zone_str: Optional[str]) -> None:
|
||||
"""Help to set the time zone."""
|
||||
if time_zone_str is None:
|
||||
return
|
||||
|
||||
time_zone = date_util.get_time_zone(time_zone_str)
|
||||
|
||||
if time_zone:
|
||||
hass.config.time_zone = time_zone
|
||||
date_util.set_default_time_zone(time_zone)
|
||||
else:
|
||||
_LOGGER.error("Received invalid time zone %s", time_zone_str)
|
||||
|
||||
|
||||
async def async_load_ha_core_config(hass: HomeAssistant) -> None:
|
||||
"""Store [homeassistant] core config."""
|
||||
store = hass.helpers.storage.Store(CORE_STORAGE_VERSION, CORE_STORAGE_KEY,
|
||||
private=True)
|
||||
data = await store.async_load()
|
||||
if not data:
|
||||
return
|
||||
|
||||
hac = hass.config
|
||||
hac.config_source = SOURCE_STORAGE
|
||||
hac.latitude = data['latitude']
|
||||
hac.longitude = data['longitude']
|
||||
hac.elevation = data['elevation']
|
||||
unit_system = data['unit_system']
|
||||
if unit_system == CONF_UNIT_SYSTEM_IMPERIAL:
|
||||
hac.units = IMPERIAL_SYSTEM
|
||||
else:
|
||||
hac.units = METRIC_SYSTEM
|
||||
hac.location_name = data['location_name']
|
||||
_set_time_zone(hass, data['time_zone'])
|
||||
|
||||
|
||||
async def async_process_ha_core_config(
|
||||
hass: HomeAssistant, config: Dict,
|
||||
api_password: Optional[str] = None,
|
||||
@@ -552,7 +511,7 @@ async def async_process_ha_core_config(
|
||||
auth_conf,
|
||||
mfa_conf))
|
||||
|
||||
await async_load_ha_core_config(hass)
|
||||
await hass.config.async_load()
|
||||
|
||||
hac = hass.config
|
||||
|
||||
@@ -568,7 +527,8 @@ async def async_process_ha_core_config(
|
||||
if key in config:
|
||||
setattr(hac, attr, config[key])
|
||||
|
||||
_set_time_zone(hass, config.get(CONF_TIME_ZONE))
|
||||
if CONF_TIME_ZONE in config:
|
||||
hac.set_time_zone(config[CONF_TIME_ZONE])
|
||||
|
||||
# Init whitelist external dir
|
||||
hac.whitelist_external_dirs = {hass.config.path('www')}
|
||||
@@ -649,7 +609,7 @@ async def async_process_ha_core_config(
|
||||
discovered.append(('name', info.city))
|
||||
|
||||
if hac.time_zone is None:
|
||||
_set_time_zone(hass, info.time_zone)
|
||||
hac.set_time_zone(info.time_zone)
|
||||
discovered.append(('time_zone', info.time_zone))
|
||||
|
||||
if hac.elevation is None and hac.latitude is not None and \
|
||||
@@ -666,24 +626,6 @@ async def async_process_ha_core_config(
|
||||
", ".join('{}: {}'.format(key, val) for key, val in discovered))
|
||||
|
||||
|
||||
async def async_store_ha_core_config(hass: HomeAssistant) -> None:
|
||||
"""Store [homeassistant] core config."""
|
||||
config = hass.config.as_dict()
|
||||
|
||||
data = {
|
||||
'latitude': config['latitude'],
|
||||
'longitude': config['longitude'],
|
||||
'elevation': config['elevation'],
|
||||
'unit_system': hass.config.units.name,
|
||||
'location_name': config['location_name'],
|
||||
'time_zone': config['time_zone'],
|
||||
}
|
||||
|
||||
store = hass.helpers.storage.Store(CORE_STORAGE_VERSION, CORE_STORAGE_KEY,
|
||||
private=True)
|
||||
await store.async_save(data)
|
||||
|
||||
|
||||
def _log_pkg_error(
|
||||
package: str, component: str, config: Dict, message: str) -> None:
|
||||
"""Log an error while merging packages."""
|
||||
|
||||
Reference in New Issue
Block a user