Update pyheos and log service errors in HEOS integration (#23222)
* Update pyheos and command error handling * Correct comment and remove unnecessary autospec
This commit is contained in:
1 parent
6d31d56c03
commit
a2565ad3b4
6 files changed
+192
-59
No files matched your search
@@ -3,7 +3,7 @@
|
||||
"name": "Heos",
|
||||
"documentation": "https://www.home-assistant.io/components/heos",
|
||||
"requirements": [
|
||||
"pyheos==0.3.1"
|
||||
"pyheos==0.4.0"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Denon HEOS Media Player."""
|
||||
from functools import reduce
|
||||
from functools import reduce, wraps
|
||||
import logging
|
||||
from operator import ior
|
||||
from typing import Sequence
|
||||
|
||||
@@ -21,6 +22,8 @@ BASE_SUPPORTED_FEATURES = SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET | \
|
||||
SUPPORT_VOLUME_STEP | SUPPORT_CLEAR_PLAYLIST | \
|
||||
SUPPORT_SHUFFLE_SET | SUPPORT_SELECT_SOURCE
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass, config, async_add_entities, discovery_info=None):
|
||||
@@ -36,6 +39,20 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry,
|
||||
async_add_entities(devices, True)
|
||||
|
||||
|
||||
def log_command_error(command: str):
|
||||
"""Return decorator that logs command failure."""
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
async def wrapper(*args, **kwargs):
|
||||
from pyheos import CommandError
|
||||
try:
|
||||
await func(*args, **kwargs)
|
||||
except CommandError as ex:
|
||||
_LOGGER.error("Unable to %s: %s", command, ex)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
|
||||
class HeosMediaPlayer(MediaPlayerDevice):
|
||||
"""The HEOS player."""
|
||||
|
||||
@@ -101,42 +118,52 @@ class HeosMediaPlayer(MediaPlayerDevice):
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_HEOS_SOURCES_UPDATED, self._sources_updated))
|
||||
|
||||
@log_command_error("clear playlist")
|
||||
async def async_clear_playlist(self):
|
||||
"""Clear players playlist."""
|
||||
await self._player.clear_queue()
|
||||
|
||||
@log_command_error("pause")
|
||||
async def async_media_pause(self):
|
||||
"""Send pause command."""
|
||||
await self._player.pause()
|
||||
|
||||
@log_command_error("play")
|
||||
async def async_media_play(self):
|
||||
"""Send play command."""
|
||||
await self._player.play()
|
||||
|
||||
@log_command_error("move to previous track")
|
||||
async def async_media_previous_track(self):
|
||||
"""Send previous track command."""
|
||||
await self._player.play_previous()
|
||||
|
||||
@log_command_error("move to next track")
|
||||
async def async_media_next_track(self):
|
||||
"""Send next track command."""
|
||||
await self._player.play_next()
|
||||
|
||||
@log_command_error("stop")
|
||||
async def async_media_stop(self):
|
||||
"""Send stop command."""
|
||||
await self._player.stop()
|
||||
|
||||
@log_command_error("set mute")
|
||||
async def async_mute_volume(self, mute):
|
||||
"""Mute the volume."""
|
||||
await self._player.set_mute(mute)
|
||||
|
||||
@log_command_error("select source")
|
||||
async def async_select_source(self, source):
|
||||
"""Select input source."""
|
||||
await self._source_manager.play_source(source, self._player)
|
||||
|
||||
@log_command_error("set shuffle")
|
||||
async def async_set_shuffle(self, shuffle):
|
||||
"""Enable/disable shuffle mode."""
|
||||
await self._player.set_play_mode(self._player.repeat, shuffle)
|
||||
|
||||
@log_command_error("set volume level")
|
||||
async def async_set_volume_level(self, volume):
|
||||
"""Set volume level, range 0..1."""
|
||||
await self._player.set_volume(int(volume * 100))
|
||||
|
||||
Reference in new issue
Block a user