mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-18 22:56:31 +00:00
Support for central log level handling (#1032)
* Support for central log level handling * Fix API
This commit is contained in:
parent
d9d438d571
commit
214c6f919e
5
API.md
5
API.md
@ -41,6 +41,7 @@ The addons from `addons` are only installed one.
|
|||||||
"arch": "armhf|aarch64|i386|amd64",
|
"arch": "armhf|aarch64|i386|amd64",
|
||||||
"channel": "stable|beta|dev",
|
"channel": "stable|beta|dev",
|
||||||
"timezone": "TIMEZONE",
|
"timezone": "TIMEZONE",
|
||||||
|
"logging": "debug|info|warning|error|critical",
|
||||||
"ip_address": "ip address",
|
"ip_address": "ip address",
|
||||||
"wait_boot": "int",
|
"wait_boot": "int",
|
||||||
"addons": [
|
"addons": [
|
||||||
@ -79,6 +80,7 @@ Optional:
|
|||||||
"channel": "stable|beta|dev",
|
"channel": "stable|beta|dev",
|
||||||
"timezone": "TIMEZONE",
|
"timezone": "TIMEZONE",
|
||||||
"wait_boot": "int",
|
"wait_boot": "int",
|
||||||
|
"logging": "debug|info|warning|error|critical",
|
||||||
"addons_repositories": [
|
"addons_repositories": [
|
||||||
"REPO_URL"
|
"REPO_URL"
|
||||||
]
|
]
|
||||||
@ -704,7 +706,8 @@ return:
|
|||||||
"machine": "type",
|
"machine": "type",
|
||||||
"arch": "arch",
|
"arch": "arch",
|
||||||
"supported_arch": ["arch1", "arch2"],
|
"supported_arch": ["arch1", "arch2"],
|
||||||
"channel": "stable|beta|dev"
|
"channel": "stable|beta|dev",
|
||||||
|
"logging": "debug|info|warning|error|critical"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
"""Init file for Hass.io info RESTful API."""
|
"""Init file for Hass.io info RESTful API."""
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
from ..const import (ATTR_ARCH, ATTR_CHANNEL, ATTR_HASSOS, ATTR_HOMEASSISTANT,
|
from aiohttp import web
|
||||||
ATTR_HOSTNAME, ATTR_MACHINE, ATTR_SUPERVISOR,
|
|
||||||
ATTR_SUPPORTED_ARCH)
|
from ..const import (
|
||||||
|
ATTR_ARCH,
|
||||||
|
ATTR_CHANNEL,
|
||||||
|
ATTR_HASSOS,
|
||||||
|
ATTR_HOMEASSISTANT,
|
||||||
|
ATTR_HOSTNAME,
|
||||||
|
ATTR_LOGGING,
|
||||||
|
ATTR_MACHINE,
|
||||||
|
ATTR_SUPERVISOR,
|
||||||
|
ATTR_SUPPORTED_ARCH,
|
||||||
|
)
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from .utils import api_process
|
from .utils import api_process
|
||||||
|
|
||||||
@ -14,7 +25,7 @@ class APIInfo(CoreSysAttributes):
|
|||||||
"""Handle RESTful API for info functions."""
|
"""Handle RESTful API for info functions."""
|
||||||
|
|
||||||
@api_process
|
@api_process
|
||||||
async def info(self, request):
|
async def info(self, request: web.Request) -> Dict[str, Any]:
|
||||||
"""Show system info."""
|
"""Show system info."""
|
||||||
return {
|
return {
|
||||||
ATTR_SUPERVISOR: self.sys_supervisor.version,
|
ATTR_SUPERVISOR: self.sys_supervisor.version,
|
||||||
@ -25,4 +36,5 @@ class APIInfo(CoreSysAttributes):
|
|||||||
ATTR_ARCH: self.sys_arch.default,
|
ATTR_ARCH: self.sys_arch.default,
|
||||||
ATTR_SUPPORTED_ARCH: self.sys_arch.supported,
|
ATTR_SUPPORTED_ARCH: self.sys_arch.supported,
|
||||||
ATTR_CHANNEL: self.sys_updater.channel,
|
ATTR_CHANNEL: self.sys_updater.channel,
|
||||||
|
ATTR_LOGGING: self.sys_config.logging,
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ from ..const import (
|
|||||||
ATTR_DESCRIPTON,
|
ATTR_DESCRIPTON,
|
||||||
ATTR_ICON,
|
ATTR_ICON,
|
||||||
ATTR_INSTALLED,
|
ATTR_INSTALLED,
|
||||||
|
ATTR_IP_ADDRESS,
|
||||||
ATTR_LAST_VERSION,
|
ATTR_LAST_VERSION,
|
||||||
|
ATTR_LOGGING,
|
||||||
ATTR_LOGO,
|
ATTR_LOGO,
|
||||||
ATTR_MEMORY_LIMIT,
|
ATTR_MEMORY_LIMIT,
|
||||||
ATTR_MEMORY_USAGE,
|
ATTR_MEMORY_USAGE,
|
||||||
@ -30,14 +32,13 @@ from ..const import (
|
|||||||
ATTR_TIMEZONE,
|
ATTR_TIMEZONE,
|
||||||
ATTR_VERSION,
|
ATTR_VERSION,
|
||||||
ATTR_WAIT_BOOT,
|
ATTR_WAIT_BOOT,
|
||||||
ATTR_IP_ADDRESS,
|
|
||||||
CONTENT_TYPE_BINARY,
|
CONTENT_TYPE_BINARY,
|
||||||
HASSIO_VERSION,
|
HASSIO_VERSION,
|
||||||
)
|
)
|
||||||
from ..coresys import CoreSysAttributes
|
from ..coresys import CoreSysAttributes
|
||||||
from ..exceptions import APIError
|
from ..exceptions import APIError
|
||||||
from ..utils.validate import validate_timezone
|
from ..utils.validate import validate_timezone
|
||||||
from ..validate import CHANNELS, REPOSITORIES, WAIT_BOOT
|
from ..validate import CHANNELS, LOG_LEVEL, REPOSITORIES, WAIT_BOOT
|
||||||
from .utils import api_process, api_process_raw, api_validate
|
from .utils import api_process, api_process_raw, api_validate
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -48,6 +49,7 @@ SCHEMA_OPTIONS = vol.Schema(
|
|||||||
vol.Optional(ATTR_ADDONS_REPOSITORIES): REPOSITORIES,
|
vol.Optional(ATTR_ADDONS_REPOSITORIES): REPOSITORIES,
|
||||||
vol.Optional(ATTR_TIMEZONE): validate_timezone,
|
vol.Optional(ATTR_TIMEZONE): validate_timezone,
|
||||||
vol.Optional(ATTR_WAIT_BOOT): WAIT_BOOT,
|
vol.Optional(ATTR_WAIT_BOOT): WAIT_BOOT,
|
||||||
|
vol.Optional(ATTR_LOGGING): LOG_LEVEL,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -90,6 +92,7 @@ class APISupervisor(CoreSysAttributes):
|
|||||||
ATTR_IP_ADDRESS: str(self.sys_supervisor.ip_address),
|
ATTR_IP_ADDRESS: str(self.sys_supervisor.ip_address),
|
||||||
ATTR_WAIT_BOOT: self.sys_config.wait_boot,
|
ATTR_WAIT_BOOT: self.sys_config.wait_boot,
|
||||||
ATTR_TIMEZONE: self.sys_config.timezone,
|
ATTR_TIMEZONE: self.sys_config.timezone,
|
||||||
|
ATTR_LOGGING: self.sys_config.logging,
|
||||||
ATTR_ADDONS: list_addons,
|
ATTR_ADDONS: list_addons,
|
||||||
ATTR_ADDONS_REPOSITORIES: self.sys_config.addons_repositories,
|
ATTR_ADDONS_REPOSITORIES: self.sys_config.addons_repositories,
|
||||||
}
|
}
|
||||||
@ -108,6 +111,9 @@ class APISupervisor(CoreSysAttributes):
|
|||||||
if ATTR_WAIT_BOOT in body:
|
if ATTR_WAIT_BOOT in body:
|
||||||
self.sys_config.wait_boot = body[ATTR_WAIT_BOOT]
|
self.sys_config.wait_boot = body[ATTR_WAIT_BOOT]
|
||||||
|
|
||||||
|
if ATTR_LOGGING in body:
|
||||||
|
self.sys_config.logging = body[ATTR_LOGGING]
|
||||||
|
|
||||||
if ATTR_ADDONS_REPOSITORIES in body:
|
if ATTR_ADDONS_REPOSITORIES in body:
|
||||||
new = set(body[ATTR_ADDONS_REPOSITORIES])
|
new = set(body[ATTR_ADDONS_REPOSITORIES])
|
||||||
await asyncio.shield(self.sys_addons.load_repositories(new))
|
await asyncio.shield(self.sys_addons.load_repositories(new))
|
||||||
|
@ -8,15 +8,21 @@ from pathlib import Path, PurePath
|
|||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
FILE_HASSIO_CONFIG, HASSIO_DATA, ATTR_TIMEZONE, ATTR_ADDONS_CUSTOM_LIST,
|
FILE_HASSIO_CONFIG,
|
||||||
ATTR_LAST_BOOT, ATTR_WAIT_BOOT)
|
HASSIO_DATA,
|
||||||
|
ATTR_TIMEZONE,
|
||||||
|
ATTR_ADDONS_CUSTOM_LIST,
|
||||||
|
ATTR_LAST_BOOT,
|
||||||
|
ATTR_WAIT_BOOT,
|
||||||
|
ATTR_LOGGING,
|
||||||
|
)
|
||||||
from .utils.dt import parse_datetime
|
from .utils.dt import parse_datetime
|
||||||
from .utils.json import JsonConfig
|
from .utils.json import JsonConfig
|
||||||
from .validate import SCHEMA_HASSIO_CONFIG
|
from .validate import SCHEMA_HASSIO_CONFIG
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
HOMEASSISTANT_CONFIG = PurePath('homeassistant')
|
HOMEASSISTANT_CONFIG = PurePath("homeassistant")
|
||||||
|
|
||||||
HASSIO_SSL = PurePath("ssl")
|
HASSIO_SSL = PurePath("ssl")
|
||||||
|
|
||||||
@ -45,7 +51,7 @@ 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')
|
config_file = Path(self.path_homeassistant, "configuration.yaml")
|
||||||
try:
|
try:
|
||||||
assert config_file.exists()
|
assert config_file.exists()
|
||||||
configuration = config_file.read_text()
|
configuration = config_file.read_text()
|
||||||
@ -53,7 +59,7 @@ class CoreConfig(JsonConfig):
|
|||||||
data = RE_TIMEZONE.search(configuration)
|
data = RE_TIMEZONE.search(configuration)
|
||||||
assert data
|
assert data
|
||||||
|
|
||||||
timezone = data.group('timezone')
|
timezone = data.group("timezone")
|
||||||
pytz.timezone(timezone)
|
pytz.timezone(timezone)
|
||||||
except (pytz.exceptions.UnknownTimeZoneError, OSError, AssertionError):
|
except (pytz.exceptions.UnknownTimeZoneError, OSError, AssertionError):
|
||||||
_LOGGER.debug("Can't parse Home Assistant timezone")
|
_LOGGER.debug("Can't parse Home Assistant timezone")
|
||||||
@ -67,15 +73,25 @@ class CoreConfig(JsonConfig):
|
|||||||
self._data[ATTR_TIMEZONE] = value
|
self._data[ATTR_TIMEZONE] = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def wait_boot(self):
|
def wait_boot(self) -> int:
|
||||||
"""Return wait time for auto boot stages."""
|
"""Return wait time for auto boot stages."""
|
||||||
return self._data[ATTR_WAIT_BOOT]
|
return self._data[ATTR_WAIT_BOOT]
|
||||||
|
|
||||||
@wait_boot.setter
|
@wait_boot.setter
|
||||||
def wait_boot(self, value):
|
def wait_boot(self, value: int):
|
||||||
"""Set wait boot time."""
|
"""Set wait boot time."""
|
||||||
self._data[ATTR_WAIT_BOOT] = value
|
self._data[ATTR_WAIT_BOOT] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logging(self) -> str:
|
||||||
|
"""Return log level of system."""
|
||||||
|
return self._data[ATTR_LOGGING]
|
||||||
|
|
||||||
|
@logging.setter
|
||||||
|
def logging(self, value: str):
|
||||||
|
"""Set system log level."""
|
||||||
|
self._data[ATTR_LOGGING] = value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_boot(self):
|
def last_boot(self):
|
||||||
"""Return last boot datetime."""
|
"""Return last boot datetime."""
|
||||||
@ -99,7 +115,7 @@ class CoreConfig(JsonConfig):
|
|||||||
@property
|
@property
|
||||||
def path_extern_hassio(self):
|
def path_extern_hassio(self):
|
||||||
"""Return Hass.io data path external for Docker."""
|
"""Return Hass.io data path external for Docker."""
|
||||||
return PurePath(os.environ['SUPERVISOR_SHARE'])
|
return PurePath(os.environ["SUPERVISOR_SHARE"])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def path_extern_homeassistant(self):
|
def path_extern_homeassistant(self):
|
||||||
|
@ -67,6 +67,7 @@ ATTR_WAIT_BOOT = "wait_boot"
|
|||||||
ATTR_DEPLOYMENT = "deployment"
|
ATTR_DEPLOYMENT = "deployment"
|
||||||
ATTR_WATCHDOG = "watchdog"
|
ATTR_WATCHDOG = "watchdog"
|
||||||
ATTR_CHANGELOG = "changelog"
|
ATTR_CHANGELOG = "changelog"
|
||||||
|
ATTR_LOGGING = "logging"
|
||||||
ATTR_DATE = "date"
|
ATTR_DATE = "date"
|
||||||
ATTR_ARCH = "arch"
|
ATTR_ARCH = "arch"
|
||||||
ATTR_LONG_DESCRIPTION = "long_description"
|
ATTR_LONG_DESCRIPTION = "long_description"
|
||||||
|
@ -16,6 +16,7 @@ from .const import (
|
|||||||
ATTR_IMAGE,
|
ATTR_IMAGE,
|
||||||
ATTR_LAST_BOOT,
|
ATTR_LAST_BOOT,
|
||||||
ATTR_LAST_VERSION,
|
ATTR_LAST_VERSION,
|
||||||
|
ATTR_LOGGING,
|
||||||
ATTR_PASSWORD,
|
ATTR_PASSWORD,
|
||||||
ATTR_PORT,
|
ATTR_PORT,
|
||||||
ATTR_PORTS,
|
ATTR_PORTS,
|
||||||
@ -42,6 +43,7 @@ CHANNELS = vol.In([CHANNEL_STABLE, CHANNEL_BETA, CHANNEL_DEV])
|
|||||||
UUID_MATCH = vol.Match(r"^[0-9a-f]{32}$")
|
UUID_MATCH = vol.Match(r"^[0-9a-f]{32}$")
|
||||||
SHA256 = vol.Match(r"^[0-9a-f]{64}$")
|
SHA256 = vol.Match(r"^[0-9a-f]{64}$")
|
||||||
TOKEN = vol.Match(r"^[0-9a-f]{32,256}$")
|
TOKEN = vol.Match(r"^[0-9a-f]{32,256}$")
|
||||||
|
LOG_LEVEL = vol.In(["debug", "info", "warning", "error", "critical"])
|
||||||
|
|
||||||
|
|
||||||
def validate_repository(repository):
|
def validate_repository(repository):
|
||||||
@ -117,6 +119,7 @@ SCHEMA_HASSIO_CONFIG = vol.Schema(
|
|||||||
default=["https://github.com/hassio-addons/repository"],
|
default=["https://github.com/hassio-addons/repository"],
|
||||||
): REPOSITORIES,
|
): REPOSITORIES,
|
||||||
vol.Optional(ATTR_WAIT_BOOT, default=5): WAIT_BOOT,
|
vol.Optional(ATTR_WAIT_BOOT, default=5): WAIT_BOOT,
|
||||||
|
vol.Optional(ATTR_LOGGING, default="info"): LOG_LEVEL,
|
||||||
},
|
},
|
||||||
extra=vol.REMOVE_EXTRA,
|
extra=vol.REMOVE_EXTRA,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user