From f2e399ccf3b790df3c9cc57fb430cfbd3981780b Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Fri, 17 Aug 2018 07:41:56 +0200 Subject: [PATCH] Update SoCo to 0.16 (#16007) --- .../components/media_player/sonos.py | 28 ++++++------------- homeassistant/components/sonos/__init__.py | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/media_player/sonos.py b/homeassistant/components/media_player/sonos.py index 5375001f75c..96038e7bb2b 100644 --- a/homeassistant/components/media_player/sonos.py +++ b/homeassistant/components/media_player/sonos.py @@ -33,6 +33,7 @@ _LOGGER = logging.getLogger(__name__) # Quiet down soco logging to just actual problems. logging.getLogger('soco').setLevel(logging.WARNING) +logging.getLogger('soco.events').setLevel(logging.ERROR) logging.getLogger('soco.data_structures_entry').setLevel(logging.ERROR) _SOCO_SERVICES_LOGGER = logging.getLogger('soco.services') @@ -55,6 +56,7 @@ DATA_SONOS = 'sonos_devices' SOURCE_LINEIN = 'Line-in' SOURCE_TV = 'TV' +CONF_ADVERTISE_ADDR = 'advertise_addr' CONF_INTERFACE_ADDR = 'interface_addr' # Service call validation schemas @@ -73,6 +75,7 @@ ATTR_SONOS_GROUP = 'sonos_group' UPNP_ERRORS_TO_IGNORE = ['701', '711'] PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Optional(CONF_ADVERTISE_ADDR): cv.string, vol.Optional(CONF_INTERFACE_ADDR): 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): """Set up the Sonos platform.""" 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: hass.data[DATA_SONOS] = SonosData() + advertise_addr = config.get(CONF_ADVERTISE_ADDR) + if advertise_addr: + soco.config.EVENT_ADVERTISE_IP = advertise_addr + players = [] if discovery_info: player = soco.SoCo(discovery_info.get('host')) @@ -451,7 +443,7 @@ class SonosDevice(MediaPlayerDevice): def _set_favorites(self): """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. # pylint: disable=broad-except try: @@ -863,9 +855,7 @@ class SonosDevice(MediaPlayerDevice): src = fav.pop() uri = src.reference.get_uri() if _is_radio_uri(uri): - # SoCo 0.14 fails to XML escape the title parameter - from xml.sax.saxutils import escape - self.soco.play_uri(uri, title=escape(source)) + self.soco.play_uri(uri, title=source) else: self.soco.clear_queue() self.soco.add_to_queue(src.reference) diff --git a/homeassistant/components/sonos/__init__.py b/homeassistant/components/sonos/__init__.py index bbc05a3aa61..6c9280195cc 100644 --- a/homeassistant/components/sonos/__init__.py +++ b/homeassistant/components/sonos/__init__.py @@ -4,7 +4,7 @@ from homeassistant.helpers import config_entry_flow DOMAIN = 'sonos' -REQUIREMENTS = ['SoCo==0.14'] +REQUIREMENTS = ['SoCo==0.16'] async def async_setup(hass, config): diff --git a/requirements_all.txt b/requirements_all.txt index 652a546641f..38b1d071c5c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -59,7 +59,7 @@ PyXiaomiGateway==0.9.5 RtmAPI==0.7.0 # homeassistant.components.sonos -SoCo==0.14 +SoCo==0.16 # homeassistant.components.sensor.travisci TravisPy==0.3.5 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8b153494025..3d0274e859b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -25,7 +25,7 @@ HAP-python==2.2.2 PyRMVtransport==0.0.7 # homeassistant.components.sonos -SoCo==0.14 +SoCo==0.16 # homeassistant.components.device_tracker.automatic aioautomatic==0.6.5