Move Sonos to upstream SoCo (#53351)

pull/53386/head
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
from urllib.parse import urlparse
import pysonos
from pysonos import events_asyncio
from pysonos.core import SoCo
from pysonos.exceptions import SoCoException
from soco import events_asyncio
import soco.config as soco_config
from soco.core import SoCo
from soco.exceptions import SoCoException
import voluptuous as vol
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:
"""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:
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)
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):
_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:
"""Create a soco instance and return if successful."""
try:
soco = pysonos.SoCo(ip_address)
soco = SoCo(ip_address)
# Ensure that the player is available and UID is cached
_ = soco.uid
_ = soco.volume

View File

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

View File

@ -1,7 +1,7 @@
"""Config flow for SONOS."""
import logging
import pysonos
import soco
from homeassistant import config_entries
from homeassistant.const import CONF_HOST
@ -18,7 +18,7 @@ _LOGGER = logging.getLogger(__name__)
async def _async_has_devices(hass: HomeAssistant) -> bool:
"""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)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ from __future__ import annotations
import datetime
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.const import ATTR_TIME

View File

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

View File

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

View File

@ -49,8 +49,8 @@ def config_entry_fixture():
@pytest.fixture(name="soco")
def soco_fixture(music_library, speaker_info, battery_info, alarm_clock):
"""Create a mock pysonos SoCo fixture."""
with patch("pysonos.SoCo", autospec=True) as mock, patch(
"""Create a mock soco SoCo fixture."""
with patch("homeassistant.components.sonos.SoCo", autospec=True) as mock, patch(
"socket.gethostbyname", return_value="192.168.42.2"
):
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)
def discover_fixture(soco):
"""Create a mock pysonos discover fixture."""
"""Create a mock soco discover fixture."""
def do_callback(hass, callback, *args, **kwargs):
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
@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):
"""Test we get the user initiated form."""
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(
"homeassistant.components.sonos.media_player.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):
result = await hass.config_entries.flow.async_init(
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."""
with patch(
"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,
@ -48,7 +48,7 @@ async def test_not_configuring_sonos_not_creates_entry(hass):
"""Test that no config will not create an entry."""
with patch(
"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 hass.async_block_till_done()

View File

@ -1,5 +1,5 @@
"""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.binary_sensor import ATTR_BATTERY_POWER_SOURCE