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