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 messagepull/2096/head
parent
0a79a5e964
commit
7208ff515e
|
@ -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 <player ip address>
|
||||
"""
|
||||
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue