Skip to content

Commit

Permalink
Fix source handling
Browse files Browse the repository at this point in the history
  • Loading branch information
akropp committed Sep 23, 2022
1 parent 6232190 commit c4f5f3a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion custom_components/savantaudio/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_polling",
"name": "Savant Audio",
"requirements": ["savantaudio-client==0.1.18"],
"version": "0.1.6"
"version": "0.1.7"
}
26 changes: 16 additions & 10 deletions custom_components/savantaudio/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,10 @@ async def _sync_link(self):
self._pwstate = STATE_ON
else:
self._pwstate = STATE_OFF
self._attributes.pop(ATTR_PASSTHRU, None)
self._attributes.pop(ATTR_STEREO, None)
self._attributes.pop(ATTR_DELAY_LEFT, None)
self._attributes.pop(ATTR_DELAY_RIGHT, None)
return
# self._attributes.pop(ATTR_PASSTHRU, None)
# self._attributes.pop(ATTR_STEREO, None)
# self._attributes.pop(ATTR_DELAY_LEFT, None)
# self._attributes.pop(ATTR_DELAY_RIGHT, None)

async def _sync_output(self):
volume_raw = self._output.volume
Expand Down Expand Up @@ -417,6 +416,7 @@ def device_class(self):
async def async_turn_off(self):
"""Turn the media player off."""
await self._switch.unlink(self._output.number)
self._pwstate = STATE_OFF

async def async_set_volume_level(self, volume):
"""
Expand All @@ -442,20 +442,25 @@ async def async_mute_volume(self, mute):

async def async_turn_on(self):
"""Turn the media player on."""
if self._pwstate == STATE_OFF and self._default_source is not None:
if self._default_source is not None:
await self._switch.link(self._output.number, self._default_source)
elif self._current_source is not None:
if self._pwstate == STATE_OFF:
if self._current_source is not None:
await self._switch.link(self._output.number, self._current_source)
elif self._default_source is not None:
await self._switch.link(self._output.number, self._default_source)
self._current_source = self._default_source
self._pwstate = STATE_ON

async def async_select_source(self, source):
"""Set the source source."""
if source is not None:
if source in self._source_list:
source = self._reverse_mapping[source]
await self._switch.link(self._output.number, source)
self._current_source = source
if self._pwstate == STATE_ON:
await self._switch.link(self._output.number, source)
else:
await self._switch.unlink(self._output.number)
self._current_source = None

async def async_select_sound_mode(self, sound_mode: str):
"""Set the sound mode."""
Expand Down Expand Up @@ -488,6 +493,7 @@ async def async_join_players(self, group_members: list[str]) -> None:
async def async_unjoin_player(self) -> None:
"""Remove this player from any group."""
await self._switch.unlink(self._output.number)
self._current_source = None

@property
def icon(self):
Expand Down

0 comments on commit c4f5f3a

Please sign in to comment.