mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
Support profiles on template (#1527)
This commit is contained in:
parent
2495cda5ec
commit
10230b0b4c
@ -19,7 +19,7 @@ WORKDIR /usr/src
|
||||
# Install requirements
|
||||
COPY requirements.txt .
|
||||
RUN export MAKEFLAGS="-j$(nproc)" \
|
||||
&& pip3 install --no-cache-dir --no-index --only-binary=:all: \
|
||||
&& pip3 install --no-cache-dir --no-index --only-binary=:all: --find-links \
|
||||
"https://wheels.home-assistant.io/alpine-$(cut -d '.' -f 1-2 < /etc/alpine-release)/${BUILD_ARCH}/" \
|
||||
-r ./requirements.txt \
|
||||
&& rm -f requirements.txt
|
||||
|
@ -7,6 +7,7 @@ cpe==1.2.1
|
||||
cryptography==2.8
|
||||
docker==4.2.0
|
||||
gitpython==3.1.0
|
||||
jinja2==2.11.1
|
||||
packaging==20.1
|
||||
ptvsd==4.3.2
|
||||
pulsectl==20.2.2
|
||||
|
@ -3,9 +3,10 @@ import asyncio
|
||||
from contextlib import suppress
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from string import Template
|
||||
from typing import Awaitable, Optional
|
||||
|
||||
import jinja2
|
||||
|
||||
from .const import ATTR_VERSION, FILE_HASSIO_AUDIO
|
||||
from .coresys import CoreSys, CoreSysAttributes
|
||||
from .docker.audio import DockerAudio
|
||||
@ -27,6 +28,7 @@ class Audio(JsonConfig, CoreSysAttributes):
|
||||
super().__init__(FILE_HASSIO_AUDIO, SCHEMA_AUDIO_CONFIG)
|
||||
self.coresys: CoreSys = coresys
|
||||
self.instance: DockerAudio = DockerAudio(coresys)
|
||||
self.client_template: Optional[jinja2.Template] = None
|
||||
|
||||
@property
|
||||
def path_extern_data(self) -> Path:
|
||||
@ -60,7 +62,6 @@ class Audio(JsonConfig, CoreSysAttributes):
|
||||
|
||||
async def load(self) -> None:
|
||||
"""Load Audio setup."""
|
||||
|
||||
# Check Audio state
|
||||
try:
|
||||
# Evaluate Version if we lost this information
|
||||
@ -71,20 +72,26 @@ class Audio(JsonConfig, CoreSysAttributes):
|
||||
except DockerAPIError:
|
||||
_LOGGER.info("No Audio plugin Docker image %s found.", self.instance.image)
|
||||
|
||||
# Install CoreDNS
|
||||
# Install PulseAudio
|
||||
with suppress(AudioError):
|
||||
await self.install()
|
||||
else:
|
||||
self.version = self.instance.version
|
||||
self.save_data()
|
||||
|
||||
# Run CoreDNS
|
||||
# Run PulseAudio
|
||||
with suppress(AudioError):
|
||||
if await self.instance.is_running():
|
||||
await self.restart()
|
||||
else:
|
||||
await self.start()
|
||||
|
||||
# Initialize Client Template
|
||||
try:
|
||||
self.client_template = jinja2.Template(PULSE_CLIENT_TMPL.read_text())
|
||||
except OSError as err:
|
||||
_LOGGER.error("Can't read pulse-client.tmpl: %s", err)
|
||||
|
||||
async def install(self) -> None:
|
||||
"""Install Audio."""
|
||||
_LOGGER.info("Setup Audio plugin")
|
||||
@ -184,16 +191,12 @@ class Audio(JsonConfig, CoreSysAttributes):
|
||||
|
||||
def pulse_client(self, input_profile=None, output_profile=None) -> str:
|
||||
"""Generate an /etc/pulse/client.conf data."""
|
||||
|
||||
# Read Template
|
||||
try:
|
||||
config_data = PULSE_CLIENT_TMPL.read_text()
|
||||
except OSError as err:
|
||||
_LOGGER.error("Can't read pulse-client.tmpl: %s", err)
|
||||
if self.client_template is None:
|
||||
return ""
|
||||
|
||||
# Process Template
|
||||
config_template = Template(config_data)
|
||||
return config_template.safe_substitute(
|
||||
audio_address=self.sys_docker.network.audio
|
||||
return self.client_template.render(
|
||||
audio_address=self.sys_docker.network.audio,
|
||||
default_source=input_profile,
|
||||
default_sink=output_profile,
|
||||
)
|
||||
|
@ -145,6 +145,10 @@ class Core(CoreSysAttributes):
|
||||
_LOGGER.info("Supervisor is up and running")
|
||||
self.state = CoreStates.RUNNING
|
||||
|
||||
# On full host boot, relaod information
|
||||
self.sys_create_task(self.sys_host.reload())
|
||||
self.sys_create_task(self.sys_updater.reload())
|
||||
|
||||
async def stop(self):
|
||||
"""Stop a running orchestration."""
|
||||
# don't process scheduler anymore
|
||||
|
@ -17,8 +17,9 @@
|
||||
## more information. Default values are commented out. Use either ; or # for
|
||||
## commenting.
|
||||
|
||||
; default-sink =
|
||||
; default-source =
|
||||
{% if default_sink %}default-sink = {{ default_sink }}{% endif %}
|
||||
{% if default_source %}default-source = {{ default_source }}{% endif %}
|
||||
|
||||
default-server = unix://run/pulse.sock
|
||||
; default-dbus-server =
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user