diff --git a/homeassistant/components/arcam_fmj/manifest.json b/homeassistant/components/arcam_fmj/manifest.json index 6685ea240eb..08545f4c5b0 100644 --- a/homeassistant/components/arcam_fmj/manifest.json +++ b/homeassistant/components/arcam_fmj/manifest.json @@ -3,7 +3,7 @@ "name": "Arcam FMJ Receivers", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/arcam_fmj", - "requirements": ["arcam-fmj==0.7.0"], + "requirements": ["arcam-fmj==0.12.0"], "ssdp": [ { "deviceType": "urn:schemas-upnp-org:device:MediaRenderer:1", diff --git a/homeassistant/components/arcam_fmj/media_player.py b/homeassistant/components/arcam_fmj/media_player.py index acccb91c98e..b63279d9c26 100644 --- a/homeassistant/components/arcam_fmj/media_player.py +++ b/homeassistant/components/arcam_fmj/media_player.py @@ -1,7 +1,7 @@ """Arcam media player.""" import logging -from arcam.fmj import DecodeMode2CH, DecodeModeMCH, IncomingAudioFormat, SourceCodes +from arcam.fmj import SourceCodes from arcam.fmj.state import State from homeassistant import config_entries @@ -92,19 +92,6 @@ class ArcamFmj(MediaPlayerEntity): self._attr_unique_id = f"{uuid}-{state.zn}" 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 def state(self): """Return the state of the device.""" @@ -128,6 +115,7 @@ class ArcamFmj(MediaPlayerEntity): async def async_added_to_hass(self): """Once registered, add listener for events.""" await self._state.start() + await self._state.update() @callback def _data(host): @@ -186,11 +174,8 @@ class ArcamFmj(MediaPlayerEntity): async def async_select_sound_mode(self, sound_mode): """Select a specific source.""" try: - if self._get_2ch(): - await self._state.set_decode_mode_2ch(DecodeMode2CH[sound_mode]) - else: - await self._state.set_decode_mode_mch(DecodeModeMCH[sound_mode]) - except KeyError: + await self._state.set_decode_mode(sound_mode) + except (KeyError, ValueError): _LOGGER.error("Unsupported sound_mode %s", sound_mode) return @@ -283,26 +268,18 @@ class ArcamFmj(MediaPlayerEntity): @property def sound_mode(self): """Name of the current sound mode.""" - if self._state.zn != 1: + value = self._state.get_decode_mode() + if value is None: return None - - 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 + return value.name @property def sound_mode_list(self): """List of available sound modes.""" - if self._state.zn != 1: + values = self._state.get_decode_modes() + if values is None: return None - - if self._get_2ch(): - return [x.name for x in DecodeMode2CH] - return [x.name for x in DecodeModeMCH] + return [x.name for x in values] @property def is_volume_muted(self): diff --git a/requirements_all.txt b/requirements_all.txt index d40d4f7d2d2..58d4a230d3c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -318,7 +318,7 @@ aprslib==0.6.46 aqualogic==2.6 # homeassistant.components.arcam_fmj -arcam-fmj==0.7.0 +arcam-fmj==0.12.0 # homeassistant.components.arris_tg2492lg arris-tg2492lg==1.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 81e969b6d74..7e672541079 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -224,7 +224,7 @@ apprise==0.9.5.1 aprslib==0.6.46 # homeassistant.components.arcam_fmj -arcam-fmj==0.7.0 +arcam-fmj==0.12.0 # homeassistant.components.dlna_dmr # homeassistant.components.ssdp diff --git a/tests/components/arcam_fmj/conftest.py b/tests/components/arcam_fmj/conftest.py index 2ef0df9511e..39b44d2ad9e 100644 --- a/tests/components/arcam_fmj/conftest.py +++ b/tests/components/arcam_fmj/conftest.py @@ -44,6 +44,7 @@ def state_1_fixture(client): state.get_source_list.return_value = [] state.get_incoming_audio_format.return_value = (0, 0) state.get_mute.return_value = None + state.get_decode_modes.return_value = [] return state @@ -58,6 +59,7 @@ def state_2_fixture(client): state.get_source_list.return_value = [] state.get_incoming_audio_format.return_value = (0, 0) state.get_mute.return_value = None + state.get_decode_modes.return_value = [] return state diff --git a/tests/components/arcam_fmj/test_media_player.py b/tests/components/arcam_fmj/test_media_player.py index 58609da6d6a..db12f715b3c 100644 --- a/tests/components/arcam_fmj/test_media_player.py +++ b/tests/components/arcam_fmj/test_media_player.py @@ -1,12 +1,14 @@ """Tests for arcam fmj receivers.""" 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 from homeassistant.components.media_player.const import ( ATTR_INPUT_SOURCE, + ATTR_SOUND_MODE, + ATTR_SOUND_MODE_LIST, MEDIA_TYPE_MUSIC, SERVICE_SELECT_SOURCE, ) @@ -100,21 +102,6 @@ async def test_update(player, state): 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( "source, value", [("PVR", SourceCodes.PVR), ("BD", SourceCodes.BD), ("INVALID", None)], @@ -142,27 +129,16 @@ async def test_source_list(player, state): @pytest.mark.parametrize( - "mode, mode_sel, mode_2ch, mode_mch", + "mode", [ - ("STEREO", True, DecodeMode2CH.STEREO, None), - ("STEREO", False, None, None), - ("STEREO", False, None, None), + ("STEREO"), + ("DOLBY_PL"), ], ) -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.""" - player._get_2ch = Mock(return_value=mode_sel) # pylint: disable=W0212 - await player.async_select_sound_mode(mode) - if mode_2ch: - 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() + state.set_decode_mode.assert_called_with(mode) async def test_volume_up(player, state): @@ -180,35 +156,33 @@ async def test_volume_down(player, state): @pytest.mark.parametrize( - "mode, mode_sel, mode_2ch, mode_mch", + "mode, mode_enum", [ - ("STEREO", True, DecodeMode2CH.STEREO, None), - ("STEREO_DOWNMIX", False, None, DecodeModeMCH.STEREO_DOWNMIX), - (None, False, None, None), + ("STEREO", DecodeMode2CH.STEREO), + ("STEREO_DOWNMIX", DecodeModeMCH.STEREO_DOWNMIX), + (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.""" - player._get_2ch = Mock(return_value=mode_sel) # pylint: disable=W0212 - state.get_decode_mode_2ch.return_value = mode_2ch - state.get_decode_mode_mch.return_value = mode_mch - - assert player.sound_mode == mode + state.get_decode_mode.return_value = mode_enum + data = await update(player) + assert data.attributes.get(ATTR_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.""" - player._get_2ch = Mock(return_value=True) # pylint: disable=W0212 - assert sorted(player.sound_mode_list) == sorted(x.name for x in DecodeMode2CH) - player._get_2ch = Mock(return_value=False) # pylint: disable=W0212 - 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 + state.get_decode_modes.return_value = modes_enum + data = await update(player) + assert data.attributes.get(ATTR_SOUND_MODE_LIST) == modes async def test_is_volume_muted(player, state):