Use shorter function for soundcard (#1535)

This commit is contained in:
Pascal Vizeli 2020-02-27 17:22:12 +01:00 committed by GitHub
parent 6721b8f265
commit 8a6ea7ab50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 19 deletions

2
API.md
View File

@ -866,7 +866,7 @@ return:
"card": [ "card": [
{ {
"name": "...", "name": "...",
"description": "...", "driver": "...",
"profiles": [ "profiles": [
{ {
"name": "...", "name": "...",

@ -1 +1 @@
Subproject commit 6b1e5a525f7dac6867af8dd937100ce402aedac9 Subproject commit 8518f774d44d4b9cd7e9b824dc9e9372e665347d

View File

@ -10,7 +10,7 @@ gitpython==3.1.0
jinja2==2.11.1 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.4
pytz==2019.3 pytz==2019.3
pyudev==0.22.0 pyudev==0.22.0
ruamel.yaml==0.15.100 ruamel.yaml==0.15.100

View File

@ -45,7 +45,7 @@ class SoundCard:
"""Represent a Sound Card.""" """Represent a Sound Card."""
name: str = attr.ib() name: str = attr.ib()
description: str = attr.ib() driver: str = attr.ib()
profiles: List[SoundProfile] = attr.ib() profiles: List[SoundProfile] = attr.ib()
@ -122,20 +122,8 @@ class SoundControl(CoreSysAttributes):
"""Set a profile to volume input/output.""" """Set a profile to volume input/output."""
try: try:
with Pulse(PULSE_NAME) as pulse: with Pulse(PULSE_NAME) as pulse:
card = pulse.get_sink_by_name(card_name)
# Get card pulse.card_profile_set(card, profile_name)
select_card = None
for card in pulse.card_list():
if card.name != card_name:
continue
select_card = card
break
if not select_card:
raise PulseIndexError()
# set profile
pulse.card_profile_set(select_card, profile_name)
except PulseIndexError: except PulseIndexError:
_LOGGER.error("Can't find %s profile %s", card_name, profile_name) _LOGGER.error("Can't find %s profile %s", card_name, profile_name)
@ -201,7 +189,7 @@ class SoundControl(CoreSysAttributes):
) )
self._cards.append( self._cards.append(
SoundCard(card.name, card.description, sound_profiles) SoundCard(card.name, card.driver, sound_profiles)
) )
except PulseOperationFailed as err: except PulseOperationFailed as err: