From 7208ff515eb6a0d12daf4ecb249e1273ce175b96 Mon Sep 17 00:00:00 2001 From: Alexander Fortin Date: Tue, 17 May 2016 07:58:57 +0200 Subject: [PATCH] Better handle exceptions from Sonos players (#2085) Sonos players can be dynamically set in various modes, for example as TV players or Line-IN or straming from radios channels, therefore some methods could not be available, and when invoked they cause long exceptions to be logged. This partially solves the problem reducing the output and logging some more informative error message --- .../components/media_player/sonos.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/media_player/sonos.py b/homeassistant/components/media_player/sonos.py index 6f0513745f4..8f4bebdc19b 100644 --- a/homeassistant/components/media_player/sonos.py +++ b/homeassistant/components/media_player/sonos.py @@ -74,16 +74,26 @@ def only_if_coordinator(func): If used as decorator, avoid calling the decorated method if player is not a coordinator. If not, a grouped speaker (not in coordinator role) will - throw soco.exceptions.SoCoSlaveException + throw soco.exceptions.SoCoSlaveException. + + Also, partially catch exceptions like: + + soco.exceptions.SoCoUPnPException: UPnP Error 701 received: + Transition not available from """ def wrapper(*args, **kwargs): """Decorator wrapper.""" if args[0].is_coordinator: - return func(*args, **kwargs) + from soco.exceptions import SoCoUPnPException + try: + func(*args, **kwargs) + except SoCoUPnPException: + _LOGGER.error('command "%s" for Sonos device "%s" ' + 'not available in this mode', + func.__name__, args[0].name) else: - _LOGGER.debug('Ignore command "%s" for Sonos device "%s" ' - '(not coordinator)', - func.__name__, args[0].name) + _LOGGER.debug('Ignore command "%s" for Sonos device "%s" (%s)', + func.__name__, args[0].name, 'not coordinator') return wrapper