mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Bump arcam library to 0.12 with new series support (#53843)
This commit is contained in:
parent
b1360ffafb
commit
8da3b4c79f
@ -3,7 +3,7 @@
|
|||||||
"name": "Arcam FMJ Receivers",
|
"name": "Arcam FMJ Receivers",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/arcam_fmj",
|
"documentation": "https://www.home-assistant.io/integrations/arcam_fmj",
|
||||||
"requirements": ["arcam-fmj==0.7.0"],
|
"requirements": ["arcam-fmj==0.12.0"],
|
||||||
"ssdp": [
|
"ssdp": [
|
||||||
{
|
{
|
||||||
"deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1",
|
"deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Arcam media player."""
|
"""Arcam media player."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from arcam.fmj import DecodeMode2CH, DecodeModeMCH, IncomingAudioFormat, SourceCodes
|
from arcam.fmj import SourceCodes
|
||||||
from arcam.fmj.state import State
|
from arcam.fmj.state import State
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -92,19 +92,6 @@ class ArcamFmj(MediaPlayerEntity):
|
|||||||
self._attr_unique_id = f"{uuid}-{state.zn}"
|
self._attr_unique_id = f"{uuid}-{state.zn}"
|
||||||
self._attr_entity_registry_enabled_default = state.zn == 1
|
self._attr_entity_registry_enabled_default = state.zn == 1
|
||||||
|
|
||||||
def _get_2ch(self):
|
|
||||||
"""Return if source is 2 channel or not."""
|
|
||||||
audio_format, _ = self._state.get_incoming_audio_format()
|
|
||||||
return bool(
|
|
||||||
audio_format
|
|
||||||
in (
|
|
||||||
IncomingAudioFormat.PCM,
|
|
||||||
IncomingAudioFormat.ANALOGUE_DIRECT,
|
|
||||||
IncomingAudioFormat.UNDETECTED,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
@ -128,6 +115,7 @@ class ArcamFmj(MediaPlayerEntity):
|
|||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Once registered, add listener for events."""
|
"""Once registered, add listener for events."""
|
||||||
await self._state.start()
|
await self._state.start()
|
||||||
|
await self._state.update()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _data(host):
|
def _data(host):
|
||||||
@ -186,11 +174,8 @@ class ArcamFmj(MediaPlayerEntity):
|
|||||||
async def async_select_sound_mode(self, sound_mode):
|
async def async_select_sound_mode(self, sound_mode):
|
||||||
"""Select a specific source."""
|
"""Select a specific source."""
|
||||||
try:
|
try:
|
||||||
if self._get_2ch():
|
await self._state.set_decode_mode(sound_mode)
|
||||||
await self._state.set_decode_mode_2ch(DecodeMode2CH[sound_mode])
|
except (KeyError, ValueError):
|
||||||
else:
|
|
||||||
await self._state.set_decode_mode_mch(DecodeModeMCH[sound_mode])
|
|
||||||
except KeyError:
|
|
||||||
_LOGGER.error("Unsupported sound_mode %s", sound_mode)
|
_LOGGER.error("Unsupported sound_mode %s", sound_mode)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -283,26 +268,18 @@ class ArcamFmj(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def sound_mode(self):
|
def sound_mode(self):
|
||||||
"""Name of the current sound mode."""
|
"""Name of the current sound mode."""
|
||||||
if self._state.zn != 1:
|
value = self._state.get_decode_mode()
|
||||||
|
if value is None:
|
||||||
return None
|
return None
|
||||||
|
return value.name
|
||||||
if self._get_2ch():
|
|
||||||
value = self._state.get_decode_mode_2ch()
|
|
||||||
else:
|
|
||||||
value = self._state.get_decode_mode_mch()
|
|
||||||
if value:
|
|
||||||
return value.name
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sound_mode_list(self):
|
def sound_mode_list(self):
|
||||||
"""List of available sound modes."""
|
"""List of available sound modes."""
|
||||||
if self._state.zn != 1:
|
values = self._state.get_decode_modes()
|
||||||
|
if values is None:
|
||||||
return None
|
return None
|
||||||
|
return [x.name for x in values]
|
||||||
if self._get_2ch():
|
|
||||||
return [x.name for x in DecodeMode2CH]
|
|
||||||
return [x.name for x in DecodeModeMCH]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_volume_muted(self):
|
def is_volume_muted(self):
|
||||||
|
@ -318,7 +318,7 @@ aprslib==0.6.46
|
|||||||
aqualogic==2.6
|
aqualogic==2.6
|
||||||
|
|
||||||
# homeassistant.components.arcam_fmj
|
# homeassistant.components.arcam_fmj
|
||||||
arcam-fmj==0.7.0
|
arcam-fmj==0.12.0
|
||||||
|
|
||||||
# homeassistant.components.arris_tg2492lg
|
# homeassistant.components.arris_tg2492lg
|
||||||
arris-tg2492lg==1.1.0
|
arris-tg2492lg==1.1.0
|
||||||
|
@ -224,7 +224,7 @@ apprise==0.9.5.1
|
|||||||
aprslib==0.6.46
|
aprslib==0.6.46
|
||||||
|
|
||||||
# homeassistant.components.arcam_fmj
|
# homeassistant.components.arcam_fmj
|
||||||
arcam-fmj==0.7.0
|
arcam-fmj==0.12.0
|
||||||
|
|
||||||
# homeassistant.components.dlna_dmr
|
# homeassistant.components.dlna_dmr
|
||||||
# homeassistant.components.ssdp
|
# homeassistant.components.ssdp
|
||||||
|
@ -44,6 +44,7 @@ def state_1_fixture(client):
|
|||||||
state.get_source_list.return_value = []
|
state.get_source_list.return_value = []
|
||||||
state.get_incoming_audio_format.return_value = (0, 0)
|
state.get_incoming_audio_format.return_value = (0, 0)
|
||||||
state.get_mute.return_value = None
|
state.get_mute.return_value = None
|
||||||
|
state.get_decode_modes.return_value = []
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ def state_2_fixture(client):
|
|||||||
state.get_source_list.return_value = []
|
state.get_source_list.return_value = []
|
||||||
state.get_incoming_audio_format.return_value = (0, 0)
|
state.get_incoming_audio_format.return_value = (0, 0)
|
||||||
state.get_mute.return_value = None
|
state.get_mute.return_value = None
|
||||||
|
state.get_decode_modes.return_value = []
|
||||||
return state
|
return state
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
"""Tests for arcam fmj receivers."""
|
"""Tests for arcam fmj receivers."""
|
||||||
from math import isclose
|
from math import isclose
|
||||||
from unittest.mock import ANY, MagicMock, Mock, PropertyMock, patch
|
from unittest.mock import ANY, MagicMock, PropertyMock, patch
|
||||||
|
|
||||||
from arcam.fmj import DecodeMode2CH, DecodeModeMCH, IncomingAudioFormat, SourceCodes
|
from arcam.fmj import DecodeMode2CH, DecodeModeMCH, SourceCodes
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
ATTR_INPUT_SOURCE,
|
ATTR_INPUT_SOURCE,
|
||||||
|
ATTR_SOUND_MODE,
|
||||||
|
ATTR_SOUND_MODE_LIST,
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
SERVICE_SELECT_SOURCE,
|
SERVICE_SELECT_SOURCE,
|
||||||
)
|
)
|
||||||
@ -100,21 +102,6 @@ async def test_update(player, state):
|
|||||||
state.update.assert_called_with()
|
state.update.assert_called_with()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"fmt, result",
|
|
||||||
[
|
|
||||||
(None, True),
|
|
||||||
(IncomingAudioFormat.PCM, True),
|
|
||||||
(IncomingAudioFormat.ANALOGUE_DIRECT, True),
|
|
||||||
(IncomingAudioFormat.DOLBY_DIGITAL, False),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_2ch(player, state, fmt, result):
|
|
||||||
"""Test selection of 2ch mode."""
|
|
||||||
state.get_incoming_audio_format.return_value = (fmt, None)
|
|
||||||
assert player._get_2ch() == result # pylint: disable=W0212
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"source, value",
|
"source, value",
|
||||||
[("PVR", SourceCodes.PVR), ("BD", SourceCodes.BD), ("INVALID", None)],
|
[("PVR", SourceCodes.PVR), ("BD", SourceCodes.BD), ("INVALID", None)],
|
||||||
@ -142,27 +129,16 @@ async def test_source_list(player, state):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode, mode_sel, mode_2ch, mode_mch",
|
"mode",
|
||||||
[
|
[
|
||||||
("STEREO", True, DecodeMode2CH.STEREO, None),
|
("STEREO"),
|
||||||
("STEREO", False, None, None),
|
("DOLBY_PL"),
|
||||||
("STEREO", False, None, None),
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_select_sound_mode(player, state, mode, mode_sel, mode_2ch, mode_mch):
|
async def test_select_sound_mode(player, state, mode):
|
||||||
"""Test selection sound mode."""
|
"""Test selection sound mode."""
|
||||||
player._get_2ch = Mock(return_value=mode_sel) # pylint: disable=W0212
|
|
||||||
|
|
||||||
await player.async_select_sound_mode(mode)
|
await player.async_select_sound_mode(mode)
|
||||||
if mode_2ch:
|
state.set_decode_mode.assert_called_with(mode)
|
||||||
state.set_decode_mode_2ch.assert_called_with(mode_2ch)
|
|
||||||
else:
|
|
||||||
state.set_decode_mode_2ch.assert_not_called()
|
|
||||||
|
|
||||||
if mode_mch:
|
|
||||||
state.set_decode_mode_mch.assert_called_with(mode_mch)
|
|
||||||
else:
|
|
||||||
state.set_decode_mode_mch.assert_not_called()
|
|
||||||
|
|
||||||
|
|
||||||
async def test_volume_up(player, state):
|
async def test_volume_up(player, state):
|
||||||
@ -180,35 +156,33 @@ async def test_volume_down(player, state):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mode, mode_sel, mode_2ch, mode_mch",
|
"mode, mode_enum",
|
||||||
[
|
[
|
||||||
("STEREO", True, DecodeMode2CH.STEREO, None),
|
("STEREO", DecodeMode2CH.STEREO),
|
||||||
("STEREO_DOWNMIX", False, None, DecodeModeMCH.STEREO_DOWNMIX),
|
("STEREO_DOWNMIX", DecodeModeMCH.STEREO_DOWNMIX),
|
||||||
(None, False, None, None),
|
(None, None),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_sound_mode(player, state, mode, mode_sel, mode_2ch, mode_mch):
|
async def test_sound_mode(player, state, mode, mode_enum):
|
||||||
"""Test selection sound mode."""
|
"""Test selection sound mode."""
|
||||||
player._get_2ch = Mock(return_value=mode_sel) # pylint: disable=W0212
|
state.get_decode_mode.return_value = mode_enum
|
||||||
state.get_decode_mode_2ch.return_value = mode_2ch
|
data = await update(player)
|
||||||
state.get_decode_mode_mch.return_value = mode_mch
|
assert data.attributes.get(ATTR_SOUND_MODE) == mode
|
||||||
|
|
||||||
assert player.sound_mode == mode
|
|
||||||
|
|
||||||
|
|
||||||
async def test_sound_mode_list(player, state):
|
@pytest.mark.parametrize(
|
||||||
|
"modes, modes_enum",
|
||||||
|
[
|
||||||
|
(["STEREO", "DOLBY_PL"], [DecodeMode2CH.STEREO, DecodeMode2CH.DOLBY_PL]),
|
||||||
|
(["STEREO_DOWNMIX"], [DecodeModeMCH.STEREO_DOWNMIX]),
|
||||||
|
(None, None),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_sound_mode_list(player, state, modes, modes_enum):
|
||||||
"""Test sound mode list."""
|
"""Test sound mode list."""
|
||||||
player._get_2ch = Mock(return_value=True) # pylint: disable=W0212
|
state.get_decode_modes.return_value = modes_enum
|
||||||
assert sorted(player.sound_mode_list) == sorted(x.name for x in DecodeMode2CH)
|
data = await update(player)
|
||||||
player._get_2ch = Mock(return_value=False) # pylint: disable=W0212
|
assert data.attributes.get(ATTR_SOUND_MODE_LIST) == modes
|
||||||
assert sorted(player.sound_mode_list) == sorted(x.name for x in DecodeModeMCH)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_sound_mode_zone_x(player, state):
|
|
||||||
"""Test second zone sound mode."""
|
|
||||||
state.zn = 2
|
|
||||||
assert player.sound_mode is None
|
|
||||||
assert player.sound_mode_list is None
|
|
||||||
|
|
||||||
|
|
||||||
async def test_is_volume_muted(player, state):
|
async def test_is_volume_muted(player, state):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user