Add default asound for pulse (#1538)

* Add default asound for pulse

* fix lint

* fix config
This commit is contained in:
Pascal Vizeli 2020-02-28 01:14:43 +01:00 committed by GitHub
parent 19ca836b78
commit c36a6dcd65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 4 deletions

View File

@ -4,6 +4,7 @@ from contextlib import suppress
import logging import logging
from pathlib import Path from pathlib import Path
from typing import Awaitable, Optional from typing import Awaitable, Optional
import shutil
import jinja2 import jinja2
@ -18,6 +19,7 @@ from .validate import SCHEMA_AUDIO_CONFIG
_LOGGER: logging.Logger = logging.getLogger(__name__) _LOGGER: logging.Logger = logging.getLogger(__name__)
PULSE_CLIENT_TMPL: Path = Path(__file__).parents[0].joinpath("data/pulse-client.tmpl") PULSE_CLIENT_TMPL: Path = Path(__file__).parents[0].joinpath("data/pulse-client.tmpl")
ASOUND_TMPL: Path = Path(__file__).parents[0].joinpath("data/asound.tmpl")
class Audio(JsonConfig, CoreSysAttributes): class Audio(JsonConfig, CoreSysAttributes):
@ -31,9 +33,14 @@ class Audio(JsonConfig, CoreSysAttributes):
self.client_template: Optional[jinja2.Template] = None self.client_template: Optional[jinja2.Template] = None
@property @property
def path_extern_data(self) -> Path: def path_extern_pulse(self) -> Path:
"""Return path of pulse cookie file.""" """Return path of pulse socket file."""
return self.sys_config.path_extern_audio.joinpath("external") return self.sys_config.path_extern_audio.joinpath("external/pulse.sock")
@property
def path_extern_asound(self) -> Path:
"""Return path of default asound config file."""
return self.sys_config.path_extern_audio.joinpath("asound")
@property @property
def version(self) -> Optional[str]: def version(self) -> Optional[str]:
@ -90,6 +97,14 @@ class Audio(JsonConfig, CoreSysAttributes):
except OSError as err: except OSError as err:
_LOGGER.error("Can't read pulse-client.tmpl: %s", err) _LOGGER.error("Can't read pulse-client.tmpl: %s", err)
# Setup default asound config
asound = self.sys_config.path_audio.joinpath("asound")
if not asound.exists():
try:
shutil.copy(ASOUND_TMPL, asound)
except OSError as err:
_LOGGER.error("Can't create default asound: %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")

View File

@ -0,0 +1,13 @@
# Default to PulseAudio
pcm.!default {
type pulse
hint {
show on
description "Default ALSA Output (Home Assistant PulseAudio Sound Server)"
}
}
ctl.!default {
type pulse
}

View File

@ -308,10 +308,14 @@ class DockerAddon(DockerInterface):
"bind": "/etc/pulse/client.conf", "bind": "/etc/pulse/client.conf",
"mode": "ro", "mode": "ro",
}, },
str(self.sys_audio.path_extern_data.joinpath("pulse.sock")): { str(self.sys_audio.path_extern_pulse): {
"bind": "/run/pulse.sock", "bind": "/run/pulse.sock",
"mode": "rw", "mode": "rw",
}, },
str(self.sys_audio.path_extern_asound): {
"bind": "/etc/asound.conf",
"mode": "ro",
},
} }
) )