diff --git a/hassio/bootstrap.py b/hassio/bootstrap.py index 1d661f752..9773d04d8 100644 --- a/hassio/bootstrap.py +++ b/hassio/bootstrap.py @@ -66,10 +66,11 @@ def initialize_system_data(coresys): config = coresys.config # homeassistant config folder - if not config.path_config.is_dir(): + if not config.path_homeassistant.is_dir(): _LOGGER.info( - "Create Home-Assistant config folder %s", config.path_config) - config.path_config.mkdir() + "Create Home-Assistant config folder %s", + config.path_homeassistant) + config.path_homeassistant.mkdir() # hassio ssl folder if not config.path_ssl.is_dir(): diff --git a/hassio/config.py b/hassio/config.py index 6f1aafd5a..c4198352d 100644 --- a/hassio/config.py +++ b/hassio/config.py @@ -2,8 +2,11 @@ from datetime import datetime import logging import os +import re from pathlib import Path, PurePath +import pytz + from .const import ( FILE_HASSIO_CONFIG, HASSIO_DATA, ATTR_TIMEZONE, ATTR_ADDONS_CUSTOM_LIST, ATTR_LAST_BOOT, ATTR_WAIT_BOOT) @@ -29,6 +32,8 @@ APPARMOR_DATA = PurePath("apparmor") DEFAULT_BOOT_TIME = datetime.utcfromtimestamp(0).isoformat() +RE_TIMEZONE = re.compile(r"time_zone: (?P[\w/\-+]+)") + class CoreConfig(JsonConfig): """Hold all core config data.""" @@ -40,7 +45,21 @@ class CoreConfig(JsonConfig): @property def timezone(self): """Return system timezone.""" - return self._data[ATTR_TIMEZONE] + config_file = Path(self.path_homeassistant, 'configuration.yaml') + try: + assert config_file.exists() + configuration = config_file.read_text() + + data = RE_TIMEZONE.search(configuration) + assert data + + timezone = data.group('timezone') + pytz.timezone(timezone) + except (pytz.exceptions.UnknownTimeZoneError, OSError, AssertionError): + _LOGGER.debug("Can't parse HomeAssistant timezone") + return self._data[ATTR_TIMEZONE] + + return timezone @timezone.setter def timezone(self, value): @@ -83,12 +102,12 @@ class CoreConfig(JsonConfig): return PurePath(os.environ['SUPERVISOR_SHARE']) @property - def path_extern_config(self): + def path_extern_homeassistant(self): """Return config path extern for docker.""" return str(PurePath(self.path_extern_hassio, HOMEASSISTANT_CONFIG)) @property - def path_config(self): + def path_homeassistant(self): """Return config path inside supervisor.""" return Path(HASSIO_DATA, HOMEASSISTANT_CONFIG) diff --git a/hassio/coresys.py b/hassio/coresys.py index af00041d9..5e27edd36 100644 --- a/hassio/coresys.py +++ b/hassio/coresys.py @@ -66,6 +66,11 @@ class CoreSys: """Return True if we run dev modus.""" return self._updater.channel == CHANNEL_DEV + @property + def timezone(self): + """Return timezone.""" + return self._config.timezone + @property def loop(self): """Return loop object.""" diff --git a/hassio/docker/addon.py b/hassio/docker/addon.py index 1b858dbbe..260a4e9ca 100644 --- a/hassio/docker/addon.py +++ b/hassio/docker/addon.py @@ -86,7 +86,7 @@ class DockerAddon(DockerInterface): return { **addon_env, - ENV_TIME: self.sys_config.timezone, + ENV_TIME: self.sys_timezone, ENV_TOKEN: self.addon.uuid, } @@ -173,7 +173,7 @@ class DockerAddon(DockerInterface): # setup config mappings if MAP_CONFIG in addon_mapping: volumes.update({ - str(self.sys_config.path_extern_config): { + str(self.sys_config.path_extern_homeassistant): { 'bind': "/config", 'mode': addon_mapping[MAP_CONFIG] }}) diff --git a/hassio/docker/homeassistant.py b/hassio/docker/homeassistant.py index 4a85a3493..ea54f00cf 100644 --- a/hassio/docker/homeassistant.py +++ b/hassio/docker/homeassistant.py @@ -61,11 +61,11 @@ class DockerHomeAssistant(DockerInterface): network_mode='host', environment={ 'HASSIO': self.sys_docker.network.supervisor, - ENV_TIME: self.sys_config.timezone, + ENV_TIME: self.sys_timezone, ENV_TOKEN: self.sys_homeassistant.uuid, }, volumes={ - str(self.sys_config.path_extern_config): + str(self.sys_config.path_extern_homeassistant): {'bind': '/config', 'mode': 'rw'}, str(self.sys_config.path_extern_ssl): {'bind': '/ssl', 'mode': 'ro'}, @@ -95,10 +95,10 @@ class DockerHomeAssistant(DockerInterface): stdout=True, stderr=True, environment={ - ENV_TIME: self.sys_config.timezone, + ENV_TIME: self.sys_timezone, }, volumes={ - str(self.sys_config.path_extern_config): + str(self.sys_config.path_extern_homeassistant): {'bind': '/config', 'mode': 'rw'}, str(self.sys_config.path_extern_ssl): {'bind': '/ssl', 'mode': 'ro'}, diff --git a/hassio/utils/dt.py b/hassio/utils/dt.py index c5ff11316..5a3a1825d 100644 --- a/hassio/utils/dt.py +++ b/hassio/utils/dt.py @@ -9,7 +9,6 @@ UTC = pytz.utc _LOGGER = logging.getLogger(__name__) -FREEGEOIP_URL = "https://freegeoip.net/json/" # Copyright (c) Django Software Foundation and individual contributors. # All rights reserved.