Update SoCo to 0.16 (#16007)

This commit is contained in:
Anders Melchiorsen 2018-08-17 07:41:56 +02:00 committed by Fabian Affolter
parent 07840f5397
commit f2e399ccf3
4 changed files with 12 additions and 22 deletions

View file

@ -33,6 +33,7 @@ _LOGGER = logging.getLogger(__name__)
# Quiet down soco logging to just actual problems. # Quiet down soco logging to just actual problems.
logging.getLogger('soco').setLevel(logging.WARNING) logging.getLogger('soco').setLevel(logging.WARNING)
logging.getLogger('soco.events').setLevel(logging.ERROR)
logging.getLogger('soco.data_structures_entry').setLevel(logging.ERROR) logging.getLogger('soco.data_structures_entry').setLevel(logging.ERROR)
_SOCO_SERVICES_LOGGER = logging.getLogger('soco.services') _SOCO_SERVICES_LOGGER = logging.getLogger('soco.services')
@ -55,6 +56,7 @@ DATA_SONOS = 'sonos_devices'
SOURCE_LINEIN = 'Line-in' SOURCE_LINEIN = 'Line-in'
SOURCE_TV = 'TV' SOURCE_TV = 'TV'
CONF_ADVERTISE_ADDR = 'advertise_addr'
CONF_INTERFACE_ADDR = 'interface_addr' CONF_INTERFACE_ADDR = 'interface_addr'
# Service call validation schemas # Service call validation schemas
@ -73,6 +75,7 @@ ATTR_SONOS_GROUP = 'sonos_group'
UPNP_ERRORS_TO_IGNORE = ['701', '711'] UPNP_ERRORS_TO_IGNORE = ['701', '711']
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_ADVERTISE_ADDR): cv.string,
vol.Optional(CONF_INTERFACE_ADDR): cv.string, vol.Optional(CONF_INTERFACE_ADDR): cv.string,
vol.Optional(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_HOSTS): vol.All(cv.ensure_list, [cv.string]),
}) })
@ -141,25 +144,14 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
def _setup_platform(hass, config, add_devices, discovery_info): def _setup_platform(hass, config, add_devices, discovery_info):
"""Set up the Sonos platform.""" """Set up the Sonos platform."""
import soco import soco
import soco.events
import soco.exceptions
orig_parse_event_xml = soco.events.parse_event_xml
def safe_parse_event_xml(xml):
"""Avoid SoCo 0.14 event thread dying from invalid xml."""
try:
return orig_parse_event_xml(xml)
# pylint: disable=broad-except
except Exception as ex:
_LOGGER.debug("Dodged exception: %s %s", type(ex), str(ex))
return {}
soco.events.parse_event_xml = safe_parse_event_xml
if DATA_SONOS not in hass.data: if DATA_SONOS not in hass.data:
hass.data[DATA_SONOS] = SonosData() hass.data[DATA_SONOS] = SonosData()
advertise_addr = config.get(CONF_ADVERTISE_ADDR)
if advertise_addr:
soco.config.EVENT_ADVERTISE_IP = advertise_addr
players = [] players = []
if discovery_info: if discovery_info:
player = soco.SoCo(discovery_info.get('host')) player = soco.SoCo(discovery_info.get('host'))
@ -451,7 +443,7 @@ class SonosDevice(MediaPlayerDevice):
def _set_favorites(self): def _set_favorites(self):
"""Set available favorites.""" """Set available favorites."""
# SoCo 0.14 raises a generic Exception on invalid xml in favorites. # SoCo 0.16 raises a generic Exception on invalid xml in favorites.
# Filter those out now so our list is safe to use. # Filter those out now so our list is safe to use.
# pylint: disable=broad-except # pylint: disable=broad-except
try: try:
@ -863,9 +855,7 @@ class SonosDevice(MediaPlayerDevice):
src = fav.pop() src = fav.pop()
uri = src.reference.get_uri() uri = src.reference.get_uri()
if _is_radio_uri(uri): if _is_radio_uri(uri):
# SoCo 0.14 fails to XML escape the title parameter self.soco.play_uri(uri, title=source)
from xml.sax.saxutils import escape
self.soco.play_uri(uri, title=escape(source))
else: else:
self.soco.clear_queue() self.soco.clear_queue()
self.soco.add_to_queue(src.reference) self.soco.add_to_queue(src.reference)

View file

@ -4,7 +4,7 @@ from homeassistant.helpers import config_entry_flow
DOMAIN = 'sonos' DOMAIN = 'sonos'
REQUIREMENTS = ['SoCo==0.14'] REQUIREMENTS = ['SoCo==0.16']
async def async_setup(hass, config): async def async_setup(hass, config):

View file

@ -59,7 +59,7 @@ PyXiaomiGateway==0.9.5
RtmAPI==0.7.0 RtmAPI==0.7.0
# homeassistant.components.sonos # homeassistant.components.sonos
SoCo==0.14 SoCo==0.16
# homeassistant.components.sensor.travisci # homeassistant.components.sensor.travisci
TravisPy==0.3.5 TravisPy==0.3.5

View file

@ -25,7 +25,7 @@ HAP-python==2.2.2
PyRMVtransport==0.0.7 PyRMVtransport==0.0.7
# homeassistant.components.sonos # homeassistant.components.sonos
SoCo==0.14 SoCo==0.16
# homeassistant.components.device_tracker.automatic # homeassistant.components.device_tracker.automatic
aioautomatic==0.6.5 aioautomatic==0.6.5