Restart add-ons attach to audio with update pulse (#1540)

This commit is contained in:
Pascal Vizeli 2020-02-28 14:05:31 +01:00 committed by GitHub
parent ae6f8bd345
commit 87170a4497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,12 +3,12 @@ import asyncio
from contextlib import suppress
import logging
from pathlib import Path
from typing import Awaitable, Optional
import shutil
from typing import Awaitable, List, Optional
import jinja2
from .const import ATTR_VERSION, FILE_HASSIO_AUDIO
from .const import ATTR_VERSION, FILE_HASSIO_AUDIO, STATE_STARTED
from .coresys import CoreSys, CoreSysAttributes
from .docker.audio import DockerAudio
from .docker.stats import DockerStats
@ -157,6 +157,8 @@ class Audio(JsonConfig, CoreSysAttributes):
_LOGGER.error("Can't start Audio plugin")
raise AudioError() from None
await self._restart_audio_addons()
async def start(self) -> None:
"""Run CoreDNS."""
# Start Instance
@ -167,6 +169,8 @@ class Audio(JsonConfig, CoreSysAttributes):
_LOGGER.error("Can't start Audio plugin")
raise AudioError() from None
await self._restart_audio_addons()
def logs(self) -> Awaitable[bytes]:
"""Get CoreDNS docker logs.
@ -217,3 +221,22 @@ class Audio(JsonConfig, CoreSysAttributes):
default_source=input_profile,
default_sink=output_profile,
)
async def _restart_audio_addons(self):
"""Restart all Add-ons they can be connect to unix socket."""
tasks: List[Awaitable[None]] = []
# Find all Add-ons running with audio
for addon in self.sys_addons.installed:
if not addon.with_audio:
continue
if await addon.state() != STATE_STARTED:
continue
tasks.append(addon.restart())
if not tasks:
return
# restart
_LOGGER.info("Restart all Add-ons attach to pulse server: %d", len(tasks))
await asyncio.wait(tasks)