Merge pull request #1035 from jodal/feature/none-mixer-adjustments
core/mpd: None-mixer adjustments
This commit is contained in:
commit
980e04537b
@ -25,10 +25,11 @@ class MixerController(object):
|
|||||||
def set_volume(self, volume):
|
def set_volume(self, volume):
|
||||||
"""Set the volume.
|
"""Set the volume.
|
||||||
|
|
||||||
The volume is defined as an integer in range [0..100] or :class:`None`
|
The volume is defined as an integer in range [0..100].
|
||||||
if the mixer is disabled.
|
|
||||||
|
|
||||||
The volume scale is linear.
|
The volume scale is linear.
|
||||||
|
|
||||||
|
Returns :class:`True` if call is successful, otherwise :class:`False`.
|
||||||
"""
|
"""
|
||||||
if self._mixer is None:
|
if self._mixer is None:
|
||||||
return False
|
return False
|
||||||
@ -41,9 +42,7 @@ class MixerController(object):
|
|||||||
:class:`True` if muted, :class:`False` unmuted, :class:`None` if
|
:class:`True` if muted, :class:`False` unmuted, :class:`None` if
|
||||||
unknown.
|
unknown.
|
||||||
"""
|
"""
|
||||||
if self._mixer is None:
|
if self._mixer is not None:
|
||||||
return False
|
|
||||||
else:
|
|
||||||
return self._mixer.get_mute().get()
|
return self._mixer.get_mute().get()
|
||||||
|
|
||||||
def set_mute(self, mute):
|
def set_mute(self, mute):
|
||||||
|
|||||||
@ -14,7 +14,7 @@ def disableoutput(context, outputid):
|
|||||||
"""
|
"""
|
||||||
if outputid == 0:
|
if outputid == 0:
|
||||||
success = context.core.mixer.set_mute(False).get()
|
success = context.core.mixer.set_mute(False).get()
|
||||||
if success is False:
|
if not success:
|
||||||
raise exceptions.MpdSystemError('problems disabling output')
|
raise exceptions.MpdSystemError('problems disabling output')
|
||||||
else:
|
else:
|
||||||
raise exceptions.MpdNoExistError('No such audio output')
|
raise exceptions.MpdNoExistError('No such audio output')
|
||||||
@ -31,7 +31,7 @@ def enableoutput(context, outputid):
|
|||||||
"""
|
"""
|
||||||
if outputid == 0:
|
if outputid == 0:
|
||||||
success = context.core.mixer.set_mute(True).get()
|
success = context.core.mixer.set_mute(True).get()
|
||||||
if success is False:
|
if not success:
|
||||||
raise exceptions.MpdSystemError('problems enabling output')
|
raise exceptions.MpdSystemError('problems enabling output')
|
||||||
else:
|
else:
|
||||||
raise exceptions.MpdNoExistError('No such audio output')
|
raise exceptions.MpdNoExistError('No such audio output')
|
||||||
@ -49,7 +49,7 @@ def toggleoutput(context, outputid):
|
|||||||
if outputid == 0:
|
if outputid == 0:
|
||||||
mute_status = context.core.mixer.get_mute().get()
|
mute_status = context.core.mixer.get_mute().get()
|
||||||
success = context.core.mixer.set_mute(not mute_status)
|
success = context.core.mixer.set_mute(not mute_status)
|
||||||
if success is False:
|
if not success:
|
||||||
raise exceptions.MpdSystemError('problems toggling output')
|
raise exceptions.MpdSystemError('problems toggling output')
|
||||||
else:
|
else:
|
||||||
raise exceptions.MpdNoExistError('No such audio output')
|
raise exceptions.MpdNoExistError('No such audio output')
|
||||||
|
|||||||
@ -397,7 +397,7 @@ def setvol(context, volume):
|
|||||||
# NOTE: we use INT as clients can pass in +N etc.
|
# NOTE: we use INT as clients can pass in +N etc.
|
||||||
value = min(max(0, volume), 100)
|
value = min(max(0, volume), 100)
|
||||||
success = context.core.mixer.set_volume(value).get()
|
success = context.core.mixer.set_volume(value).get()
|
||||||
if success is False:
|
if not success:
|
||||||
raise exceptions.MpdSystemError('problems setting volume')
|
raise exceptions.MpdSystemError('problems setting volume')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -42,17 +42,17 @@ class CoreNoneMixerTest(unittest.TestCase):
|
|||||||
def setUp(self): # noqa: N802
|
def setUp(self): # noqa: N802
|
||||||
self.core = core.Core(mixer=None, backends=[])
|
self.core = core.Core(mixer=None, backends=[])
|
||||||
|
|
||||||
def test_get_volume_return_none(self):
|
def test_get_volume_return_none_because_it_is_unknown(self):
|
||||||
self.assertEqual(self.core.mixer.get_volume(), None)
|
self.assertEqual(self.core.mixer.get_volume(), None)
|
||||||
|
|
||||||
def test_set_volume_return_false(self):
|
def test_set_volume_return_false_because_it_failed(self):
|
||||||
self.assertEqual(self.core.mixer.set_volume(30), False)
|
self.assertEqual(self.core.mixer.set_volume(30), False)
|
||||||
|
|
||||||
def test_get_set_mute_return_proper_state(self):
|
def test_get_mute_return_none_because_it_is_unknown(self):
|
||||||
self.assertEqual(self.core.mixer.set_mute(False), False)
|
self.assertEqual(self.core.mixer.get_mute(), None)
|
||||||
self.assertEqual(self.core.mixer.get_mute(), False)
|
|
||||||
|
def test_set_mute_return_false_because_it_failed(self):
|
||||||
self.assertEqual(self.core.mixer.set_mute(True), False)
|
self.assertEqual(self.core.mixer.set_mute(True), False)
|
||||||
self.assertEqual(self.core.mixer.get_mute(), False)
|
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.object(mixer.MixerListener, 'send')
|
@mock.patch.object(mixer.MixerListener, 'send')
|
||||||
|
|||||||
@ -90,20 +90,22 @@ class AudioOutputHandlerNoneMixerTest(protocol.BaseTestCase):
|
|||||||
enable_mixer = False
|
enable_mixer = False
|
||||||
|
|
||||||
def test_enableoutput(self):
|
def test_enableoutput(self):
|
||||||
self.core.mixer.set_mute(False)
|
self.assertEqual(self.core.mixer.get_mute().get(), None)
|
||||||
|
|
||||||
self.send_request('enableoutput "0"')
|
self.send_request('enableoutput "0"')
|
||||||
self.assertInResponse(
|
self.assertInResponse(
|
||||||
'ACK [52@0] {enableoutput} problems enabling output')
|
'ACK [52@0] {enableoutput} problems enabling output')
|
||||||
self.assertEqual(self.core.mixer.get_mute().get(), False)
|
|
||||||
|
self.assertEqual(self.core.mixer.get_mute().get(), None)
|
||||||
|
|
||||||
def test_disableoutput(self):
|
def test_disableoutput(self):
|
||||||
self.core.mixer.set_mute(True)
|
self.assertEqual(self.core.mixer.get_mute().get(), None)
|
||||||
|
|
||||||
self.send_request('disableoutput "0"')
|
self.send_request('disableoutput "0"')
|
||||||
self.assertInResponse(
|
self.assertInResponse(
|
||||||
'ACK [52@0] {disableoutput} problems disabling output')
|
'ACK [52@0] {disableoutput} problems disabling output')
|
||||||
self.assertEqual(self.core.mixer.get_mute().get(), False)
|
|
||||||
|
self.assertEqual(self.core.mixer.get_mute().get(), None)
|
||||||
|
|
||||||
def test_outputs_when_unmuted(self):
|
def test_outputs_when_unmuted(self):
|
||||||
self.core.mixer.set_mute(False)
|
self.core.mixer.set_mute(False)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user