mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-10 10:46:29 +00:00
Change timezone handling (#641)
* Change timezone handling * Update dt.py * Update homeassistant.py * fix * Use new timezone * fix handling * fix regex * fix regex * Rename old config * fix lint * simplify * fix regex * fix * cleanup * cleanup * fix * fix find * mm
This commit is contained in:
parent
0d4a808449
commit
6e6c2c3efb
@ -66,10 +66,11 @@ def initialize_system_data(coresys):
|
|||||||
config = coresys.config
|
config = coresys.config
|
||||||
|
|
||||||
# homeassistant config folder
|
# homeassistant config folder
|
||||||
if not config.path_config.is_dir():
|
if not config.path_homeassistant.is_dir():
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Create Home-Assistant config folder %s", config.path_config)
|
"Create Home-Assistant config folder %s",
|
||||||
config.path_config.mkdir()
|
config.path_homeassistant)
|
||||||
|
config.path_homeassistant.mkdir()
|
||||||
|
|
||||||
# hassio ssl folder
|
# hassio ssl folder
|
||||||
if not config.path_ssl.is_dir():
|
if not config.path_ssl.is_dir():
|
||||||
|
@ -2,8 +2,11 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
|
|
||||||
|
import pytz
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
FILE_HASSIO_CONFIG, HASSIO_DATA, ATTR_TIMEZONE, ATTR_ADDONS_CUSTOM_LIST,
|
FILE_HASSIO_CONFIG, HASSIO_DATA, ATTR_TIMEZONE, ATTR_ADDONS_CUSTOM_LIST,
|
||||||
ATTR_LAST_BOOT, ATTR_WAIT_BOOT)
|
ATTR_LAST_BOOT, ATTR_WAIT_BOOT)
|
||||||
@ -29,6 +32,8 @@ APPARMOR_DATA = PurePath("apparmor")
|
|||||||
|
|
||||||
DEFAULT_BOOT_TIME = datetime.utcfromtimestamp(0).isoformat()
|
DEFAULT_BOOT_TIME = datetime.utcfromtimestamp(0).isoformat()
|
||||||
|
|
||||||
|
RE_TIMEZONE = re.compile(r"time_zone: (?P<timezone>[\w/\-+]+)")
|
||||||
|
|
||||||
|
|
||||||
class CoreConfig(JsonConfig):
|
class CoreConfig(JsonConfig):
|
||||||
"""Hold all core config data."""
|
"""Hold all core config data."""
|
||||||
@ -40,8 +45,22 @@ class CoreConfig(JsonConfig):
|
|||||||
@property
|
@property
|
||||||
def timezone(self):
|
def timezone(self):
|
||||||
"""Return system timezone."""
|
"""Return system 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 self._data[ATTR_TIMEZONE]
|
||||||
|
|
||||||
|
return timezone
|
||||||
|
|
||||||
@timezone.setter
|
@timezone.setter
|
||||||
def timezone(self, value):
|
def timezone(self, value):
|
||||||
"""Set system timezone."""
|
"""Set system timezone."""
|
||||||
@ -83,12 +102,12 @@ class CoreConfig(JsonConfig):
|
|||||||
return PurePath(os.environ['SUPERVISOR_SHARE'])
|
return PurePath(os.environ['SUPERVISOR_SHARE'])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path_extern_config(self):
|
def path_extern_homeassistant(self):
|
||||||
"""Return config path extern for docker."""
|
"""Return config path extern for docker."""
|
||||||
return str(PurePath(self.path_extern_hassio, HOMEASSISTANT_CONFIG))
|
return str(PurePath(self.path_extern_hassio, HOMEASSISTANT_CONFIG))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path_config(self):
|
def path_homeassistant(self):
|
||||||
"""Return config path inside supervisor."""
|
"""Return config path inside supervisor."""
|
||||||
return Path(HASSIO_DATA, HOMEASSISTANT_CONFIG)
|
return Path(HASSIO_DATA, HOMEASSISTANT_CONFIG)
|
||||||
|
|
||||||
|
@ -66,6 +66,11 @@ class CoreSys:
|
|||||||
"""Return True if we run dev modus."""
|
"""Return True if we run dev modus."""
|
||||||
return self._updater.channel == CHANNEL_DEV
|
return self._updater.channel == CHANNEL_DEV
|
||||||
|
|
||||||
|
@property
|
||||||
|
def timezone(self):
|
||||||
|
"""Return timezone."""
|
||||||
|
return self._config.timezone
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def loop(self):
|
def loop(self):
|
||||||
"""Return loop object."""
|
"""Return loop object."""
|
||||||
|
@ -86,7 +86,7 @@ class DockerAddon(DockerInterface):
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
**addon_env,
|
**addon_env,
|
||||||
ENV_TIME: self.sys_config.timezone,
|
ENV_TIME: self.sys_timezone,
|
||||||
ENV_TOKEN: self.addon.uuid,
|
ENV_TOKEN: self.addon.uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +173,7 @@ class DockerAddon(DockerInterface):
|
|||||||
# setup config mappings
|
# setup config mappings
|
||||||
if MAP_CONFIG in addon_mapping:
|
if MAP_CONFIG in addon_mapping:
|
||||||
volumes.update({
|
volumes.update({
|
||||||
str(self.sys_config.path_extern_config): {
|
str(self.sys_config.path_extern_homeassistant): {
|
||||||
'bind': "/config", 'mode': addon_mapping[MAP_CONFIG]
|
'bind': "/config", 'mode': addon_mapping[MAP_CONFIG]
|
||||||
}})
|
}})
|
||||||
|
|
||||||
|
@ -61,11 +61,11 @@ class DockerHomeAssistant(DockerInterface):
|
|||||||
network_mode='host',
|
network_mode='host',
|
||||||
environment={
|
environment={
|
||||||
'HASSIO': self.sys_docker.network.supervisor,
|
'HASSIO': self.sys_docker.network.supervisor,
|
||||||
ENV_TIME: self.sys_config.timezone,
|
ENV_TIME: self.sys_timezone,
|
||||||
ENV_TOKEN: self.sys_homeassistant.uuid,
|
ENV_TOKEN: self.sys_homeassistant.uuid,
|
||||||
},
|
},
|
||||||
volumes={
|
volumes={
|
||||||
str(self.sys_config.path_extern_config):
|
str(self.sys_config.path_extern_homeassistant):
|
||||||
{'bind': '/config', 'mode': 'rw'},
|
{'bind': '/config', 'mode': 'rw'},
|
||||||
str(self.sys_config.path_extern_ssl):
|
str(self.sys_config.path_extern_ssl):
|
||||||
{'bind': '/ssl', 'mode': 'ro'},
|
{'bind': '/ssl', 'mode': 'ro'},
|
||||||
@ -95,10 +95,10 @@ class DockerHomeAssistant(DockerInterface):
|
|||||||
stdout=True,
|
stdout=True,
|
||||||
stderr=True,
|
stderr=True,
|
||||||
environment={
|
environment={
|
||||||
ENV_TIME: self.sys_config.timezone,
|
ENV_TIME: self.sys_timezone,
|
||||||
},
|
},
|
||||||
volumes={
|
volumes={
|
||||||
str(self.sys_config.path_extern_config):
|
str(self.sys_config.path_extern_homeassistant):
|
||||||
{'bind': '/config', 'mode': 'rw'},
|
{'bind': '/config', 'mode': 'rw'},
|
||||||
str(self.sys_config.path_extern_ssl):
|
str(self.sys_config.path_extern_ssl):
|
||||||
{'bind': '/ssl', 'mode': 'ro'},
|
{'bind': '/ssl', 'mode': 'ro'},
|
||||||
|
@ -9,7 +9,6 @@ UTC = pytz.utc
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
FREEGEOIP_URL = "https://freegeoip.net/json/"
|
|
||||||
|
|
||||||
# Copyright (c) Django Software Foundation and individual contributors.
|
# Copyright (c) Django Software Foundation and individual contributors.
|
||||||
# All rights reserved.
|
# All rights reserved.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user