Move Sonos to upstream SoCo (#53351)

This commit is contained in:
Anders Melchiorsen 2021-07-23 00:40:30 +02:00 committed by GitHub
parent bfdbb93d2d
commit e85b0ec052
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 44 additions and 44 deletions

View file

@ -9,10 +9,10 @@ import logging
import socket import socket
from urllib.parse import urlparse from urllib.parse import urlparse
import pysonos from soco import events_asyncio
from pysonos import events_asyncio import soco.config as soco_config
from pysonos.core import SoCo from soco.core import SoCo
from pysonos.exceptions import SoCoException from soco.exceptions import SoCoException
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
@ -109,7 +109,7 @@ async def async_setup(hass, config):
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Sonos from a config entry.""" """Set up Sonos from a config entry."""
pysonos.config.EVENTS_MODULE = events_asyncio soco_config.EVENTS_MODULE = events_asyncio
if DATA_SONOS not in hass.data: if DATA_SONOS not in hass.data:
hass.data[DATA_SONOS] = SonosData() hass.data[DATA_SONOS] = SonosData()
@ -121,7 +121,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
advertise_addr = config.get(CONF_ADVERTISE_ADDR) advertise_addr = config.get(CONF_ADVERTISE_ADDR)
if advertise_addr: if advertise_addr:
pysonos.config.EVENT_ADVERTISE_IP = advertise_addr soco_config.EVENT_ADVERTISE_IP = advertise_addr
if deprecated_address := config.get(CONF_INTERFACE_ADDR): if deprecated_address := config.get(CONF_INTERFACE_ADDR):
_LOGGER.warning( _LOGGER.warning(
@ -140,7 +140,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
def _create_soco(ip_address: str, source: SoCoCreationSource) -> SoCo | None: def _create_soco(ip_address: str, source: SoCoCreationSource) -> SoCo | None:
"""Create a soco instance and return if successful.""" """Create a soco instance and return if successful."""
try: try:
soco = pysonos.SoCo(ip_address) soco = SoCo(ip_address)
# Ensure that the player is available and UID is cached # Ensure that the player is available and UID is cached
_ = soco.uid _ = soco.uid
_ = soco.volume _ = soco.volume

View file

@ -5,9 +5,9 @@ from collections.abc import Iterator
import logging import logging
from typing import Any from typing import Any
from pysonos import SoCo from soco import SoCo
from pysonos.alarms import Alarm, get_alarms from soco.alarms import Alarm, get_alarms
from pysonos.exceptions import SoCoException from soco.exceptions import SoCoException
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send

View file

@ -1,7 +1,7 @@
"""Config flow for SONOS.""" """Config flow for SONOS."""
import logging import logging
import pysonos import soco
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.const import CONF_HOST from homeassistant.const import CONF_HOST
@ -18,7 +18,7 @@ _LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass: HomeAssistant) -> bool: async def _async_has_devices(hass: HomeAssistant) -> bool:
"""Return if there are devices that can be discovered.""" """Return if there are devices that can be discovered."""
result = await hass.async_add_executor_job(pysonos.discover) result = await hass.async_add_executor_job(soco.discover)
return bool(result) return bool(result)

View file

@ -4,8 +4,8 @@ from __future__ import annotations
import datetime import datetime
import logging import logging
from pysonos.core import SoCo from soco.core import SoCo
from pysonos.exceptions import SoCoException from soco.exceptions import SoCoException
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.dispatcher import ( from homeassistant.helpers.dispatcher import (

View file

@ -5,9 +5,9 @@ from collections.abc import Iterator
import logging import logging
from typing import Any from typing import Any
from pysonos import SoCo from soco import SoCo
from pysonos.data_structures import DidlFavorite from soco.data_structures import DidlFavorite
from pysonos.exceptions import SoCoException from soco.exceptions import SoCoException
from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.dispatcher import async_dispatcher_send

View file

@ -5,7 +5,7 @@ import functools as ft
import logging import logging
from typing import Any, Callable from typing import Any, Callable
from pysonos.exceptions import SoCoException, SoCoUPnPException from soco.exceptions import SoCoException, SoCoUPnPException
from homeassistant.exceptions import HomeAssistantError from homeassistant.exceptions import HomeAssistantError

View file

@ -6,7 +6,7 @@ from collections.abc import Callable, Coroutine
import logging import logging
from typing import Any from typing import Any
from pysonos import SoCo from soco import SoCo
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.debounce import Debouncer

View file

@ -3,7 +3,7 @@
"name": "Sonos", "name": "Sonos",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/sonos", "documentation": "https://www.home-assistant.io/integrations/sonos",
"requirements": ["pysonos==0.0.53"], "requirements": ["soco==0.23.1"],
"dependencies": ["ssdp"], "dependencies": ["ssdp"],
"after_dependencies": ["plex", "zeroconf"], "after_dependencies": ["plex", "zeroconf"],
"zeroconf": ["_sonos._tcp.local."], "zeroconf": ["_sonos._tcp.local."],

View file

@ -6,8 +6,8 @@ import logging
from typing import Any from typing import Any
import urllib.parse import urllib.parse
from pysonos import alarms from soco import alarms
from pysonos.core import ( from soco.core import (
MUSIC_SRC_LINE_IN, MUSIC_SRC_LINE_IN,
MUSIC_SRC_RADIO, MUSIC_SRC_RADIO,
PLAY_MODE_BY_MEANING, PLAY_MODE_BY_MEANING,

View file

@ -11,13 +11,13 @@ from typing import Any, Callable
import urllib.parse import urllib.parse
import async_timeout import async_timeout
from pysonos.core import MUSIC_SRC_LINE_IN, MUSIC_SRC_RADIO, MUSIC_SRC_TV, SoCo from soco.core import MUSIC_SRC_LINE_IN, MUSIC_SRC_RADIO, MUSIC_SRC_TV, SoCo
from pysonos.data_structures import DidlAudioBroadcast, DidlPlaylistContainer from soco.data_structures import DidlAudioBroadcast, DidlPlaylistContainer
from pysonos.events_base import Event as SonosEvent, SubscriptionBase from soco.events_base import Event as SonosEvent, SubscriptionBase
from pysonos.exceptions import SoCoException, SoCoUPnPException from soco.exceptions import SoCoException, SoCoUPnPException
from pysonos.music_library import MusicLibrary from soco.music_library import MusicLibrary
from pysonos.plugins.sharelink import ShareLinkPlugin from soco.plugins.sharelink import ShareLinkPlugin
from pysonos.snapshot import Snapshot from soco.snapshot import Snapshot
from homeassistant.components import zeroconf from homeassistant.components import zeroconf
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import datetime import datetime
import logging import logging
from pysonos.exceptions import SoCoException, SoCoUPnPException from soco.exceptions import SoCoException, SoCoUPnPException
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity
from homeassistant.const import ATTR_TIME from homeassistant.const import ATTR_TIME

View file

@ -1779,9 +1779,6 @@ pysnmp==4.4.12
# homeassistant.components.soma # homeassistant.components.soma
pysoma==0.0.10 pysoma==0.0.10
# homeassistant.components.sonos
pysonos==0.0.53
# homeassistant.components.spc # homeassistant.components.spc
pyspcwebgw==0.4.0 pyspcwebgw==0.4.0
@ -2146,6 +2143,9 @@ smhi-pkg==1.0.15
# homeassistant.components.snapcast # homeassistant.components.snapcast
snapcast==2.1.3 snapcast==2.1.3
# homeassistant.components.sonos
soco==0.23.1
# homeassistant.components.solaredge_local # homeassistant.components.solaredge_local
solaredge-local==0.2.0 solaredge-local==0.2.0

View file

@ -1015,9 +1015,6 @@ pysmartthings==0.7.6
# homeassistant.components.soma # homeassistant.components.soma
pysoma==0.0.10 pysoma==0.0.10
# homeassistant.components.sonos
pysonos==0.0.53
# homeassistant.components.spc # homeassistant.components.spc
pyspcwebgw==0.4.0 pyspcwebgw==0.4.0
@ -1175,6 +1172,9 @@ smarthab==0.21
# homeassistant.components.smhi # homeassistant.components.smhi
smhi-pkg==1.0.15 smhi-pkg==1.0.15
# homeassistant.components.sonos
soco==0.23.1
# homeassistant.components.solaredge # homeassistant.components.solaredge
solaredge==0.0.2 solaredge==0.0.2

View file

@ -49,8 +49,8 @@ def config_entry_fixture():
@pytest.fixture(name="soco") @pytest.fixture(name="soco")
def soco_fixture(music_library, speaker_info, battery_info, alarm_clock): def soco_fixture(music_library, speaker_info, battery_info, alarm_clock):
"""Create a mock pysonos SoCo fixture.""" """Create a mock soco SoCo fixture."""
with patch("pysonos.SoCo", autospec=True) as mock, patch( with patch("homeassistant.components.sonos.SoCo", autospec=True) as mock, patch(
"socket.gethostbyname", return_value="192.168.42.2" "socket.gethostbyname", return_value="192.168.42.2"
): ):
mock_soco = mock.return_value mock_soco = mock.return_value
@ -76,7 +76,7 @@ def soco_fixture(music_library, speaker_info, battery_info, alarm_clock):
@pytest.fixture(name="discover", autouse=True) @pytest.fixture(name="discover", autouse=True)
def discover_fixture(soco): def discover_fixture(soco):
"""Create a mock pysonos discover fixture.""" """Create a mock soco discover fixture."""
def do_callback(hass, callback, *args, **kwargs): def do_callback(hass, callback, *args, **kwargs):
callback( callback(

View file

@ -7,7 +7,7 @@ from homeassistant import config_entries, core, setup
from homeassistant.components.sonos.const import DATA_SONOS_DISCOVERY_MANAGER, DOMAIN from homeassistant.components.sonos.const import DATA_SONOS_DISCOVERY_MANAGER, DOMAIN
@patch("homeassistant.components.sonos.config_flow.pysonos.discover", return_value=True) @patch("homeassistant.components.sonos.config_flow.soco.discover", return_value=True)
async def test_user_form(discover_mock: MagicMock, hass: core.HomeAssistant): async def test_user_form(discover_mock: MagicMock, hass: core.HomeAssistant):
"""Test we get the user initiated form.""" """Test we get the user initiated form."""
await setup.async_setup_component(hass, "persistent_notification", {}) await setup.async_setup_component(hass, "persistent_notification", {})

View file

@ -13,7 +13,7 @@ async def test_creating_entry_sets_up_media_player(hass):
with patch( with patch(
"homeassistant.components.sonos.media_player.async_setup_entry", "homeassistant.components.sonos.media_player.async_setup_entry",
return_value=mock_coro(True), return_value=mock_coro(True),
) as mock_setup, patch("pysonos.discover", return_value=True): ) as mock_setup, patch("soco.discover", return_value=True):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
sonos.DOMAIN, context={"source": config_entries.SOURCE_USER} sonos.DOMAIN, context={"source": config_entries.SOURCE_USER}
) )
@ -33,7 +33,7 @@ async def test_configuring_sonos_creates_entry(hass):
"""Test that specifying config will create an entry.""" """Test that specifying config will create an entry."""
with patch( with patch(
"homeassistant.components.sonos.async_setup_entry", return_value=mock_coro(True) "homeassistant.components.sonos.async_setup_entry", return_value=mock_coro(True)
) as mock_setup, patch("pysonos.discover", return_value=True): ) as mock_setup, patch("soco.discover", return_value=True):
await async_setup_component( await async_setup_component(
hass, hass,
sonos.DOMAIN, sonos.DOMAIN,
@ -48,7 +48,7 @@ async def test_not_configuring_sonos_not_creates_entry(hass):
"""Test that no config will not create an entry.""" """Test that no config will not create an entry."""
with patch( with patch(
"homeassistant.components.sonos.async_setup_entry", return_value=mock_coro(True) "homeassistant.components.sonos.async_setup_entry", return_value=mock_coro(True)
) as mock_setup, patch("pysonos.discover", return_value=True): ) as mock_setup, patch("soco.discover", return_value=True):
await async_setup_component(hass, sonos.DOMAIN, {}) await async_setup_component(hass, sonos.DOMAIN, {})
await hass.async_block_till_done() await hass.async_block_till_done()

View file

@ -1,5 +1,5 @@
"""Tests for the Sonos battery sensor platform.""" """Tests for the Sonos battery sensor platform."""
from pysonos.exceptions import NotSupportedException from soco.exceptions import NotSupportedException
from homeassistant.components.sonos import DOMAIN from homeassistant.components.sonos import DOMAIN
from homeassistant.components.sonos.binary_sensor import ATTR_BATTERY_POWER_SOURCE from homeassistant.components.sonos.binary_sensor import ATTR_BATTERY_POWER_SOURCE