2016-07-29 03:40:58 +00:00
|
|
|
"""The tests for the Demo Media player platform."""
|
2017-05-15 07:42:45 +00:00
|
|
|
import datetime
|
2016-11-04 04:23:37 +00:00
|
|
|
import socket
|
2016-07-29 03:40:58 +00:00
|
|
|
import unittest
|
2018-09-20 21:50:11 +00:00
|
|
|
import pysonos.snapshot
|
2016-07-29 03:40:58 +00:00
|
|
|
from unittest import mock
|
2018-09-20 21:50:11 +00:00
|
|
|
import pysonos
|
|
|
|
from pysonos import alarms
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2017-03-05 09:41:54 +00:00
|
|
|
from homeassistant.setup import setup_component
|
2019-02-01 23:45:44 +00:00
|
|
|
from homeassistant.components.sonos import media_player as sonos
|
2019-02-08 22:18:18 +00:00
|
|
|
from homeassistant.components.media_player.const import DOMAIN
|
2019-02-01 23:45:44 +00:00
|
|
|
from homeassistant.components.sonos.media_player import CONF_INTERFACE_ADDR
|
2016-12-02 06:22:03 +00:00
|
|
|
from homeassistant.const import CONF_HOSTS, CONF_PLATFORM
|
2019-03-13 09:17:09 +00:00
|
|
|
from homeassistant.util.async_ import run_coroutine_threadsafe
|
2016-07-29 03:40:58 +00:00
|
|
|
|
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
|
|
ENTITY_ID = 'media_player.kitchen'
|
|
|
|
|
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
class pysonosDiscoverMock():
|
|
|
|
"""Mock class for the pysonos.discover method."""
|
2016-07-30 08:30:13 +00:00
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
def discover(interface_addr, all_households=False):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Return tuple of pysonos.SoCo objects representing found speakers."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return {SoCoMock('192.0.2.1')}
|
|
|
|
|
|
|
|
|
2016-10-25 22:37:47 +00:00
|
|
|
class AvTransportMock():
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Mock class for the avTransport property on pysonos.SoCo object."""
|
2016-12-02 05:45:19 +00:00
|
|
|
|
2016-10-25 22:37:47 +00:00
|
|
|
def __init__(self):
|
2016-12-02 05:45:19 +00:00
|
|
|
"""Initialize ethe Transport mock."""
|
2016-10-25 22:37:47 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def GetMediaInfo(self, _):
|
2016-12-02 05:45:19 +00:00
|
|
|
"""Get the media details."""
|
|
|
|
return {
|
|
|
|
'CurrentURI': '',
|
|
|
|
'CurrentURIMetaData': ''
|
|
|
|
}
|
2016-10-25 22:37:47 +00:00
|
|
|
|
|
|
|
|
2018-02-18 19:05:20 +00:00
|
|
|
class MusicLibraryMock():
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Mock class for the music_library property on pysonos.SoCo object."""
|
2018-02-18 19:05:20 +00:00
|
|
|
|
|
|
|
def get_sonos_favorites(self):
|
|
|
|
"""Return favorites."""
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
2019-02-25 21:03:15 +00:00
|
|
|
class CacheMock():
|
|
|
|
"""Mock class for the _zgs_cache property on pysonos.SoCo object."""
|
|
|
|
|
|
|
|
def clear(self):
|
|
|
|
"""Clear cache."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
class SoCoMock():
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Mock class for the pysonos.SoCo object."""
|
2016-07-30 08:30:13 +00:00
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
def __init__(self, ip):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Initialize SoCo object."""
|
2016-07-29 03:40:58 +00:00
|
|
|
self.ip_address = ip
|
|
|
|
self.is_visible = True
|
2018-02-18 19:05:20 +00:00
|
|
|
self.volume = 50
|
|
|
|
self.mute = False
|
2018-10-03 12:50:13 +00:00
|
|
|
self.shuffle = False
|
2018-02-18 19:05:20 +00:00
|
|
|
self.night_mode = False
|
|
|
|
self.dialog_mode = False
|
|
|
|
self.music_library = MusicLibraryMock()
|
2016-10-25 22:37:47 +00:00
|
|
|
self.avTransport = AvTransportMock()
|
2019-02-25 21:03:15 +00:00
|
|
|
self._zgs_cache = CacheMock()
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2017-02-07 08:27:55 +00:00
|
|
|
def get_sonos_favorites(self):
|
|
|
|
"""Get favorites list from sonos."""
|
|
|
|
return {'favorites': []}
|
|
|
|
|
2016-11-01 17:42:38 +00:00
|
|
|
def get_speaker_info(self, force):
|
2016-07-30 08:30:13 +00:00
|
|
|
"""Return a dict with various data points about the speaker."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return {'serial_number': 'B8-E9-37-BO-OC-BA:2',
|
|
|
|
'software_version': '32.11-30071',
|
|
|
|
'uid': 'RINCON_B8E937BOOCBA02500',
|
|
|
|
'zone_icon': 'x-rincon-roomicon:kitchen',
|
|
|
|
'mac_address': 'B8:E9:37:BO:OC:BA',
|
|
|
|
'zone_name': 'Kitchen',
|
2018-02-18 19:05:20 +00:00
|
|
|
'model_name': 'Sonos PLAY:1',
|
2016-07-29 03:40:58 +00:00
|
|
|
'hardware_version': '1.8.1.2-1'}
|
|
|
|
|
|
|
|
def get_current_transport_info(self):
|
2016-07-30 08:30:13 +00:00
|
|
|
"""Return a dict with the current state of the speaker."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return {'current_transport_speed': '1',
|
|
|
|
'current_transport_state': 'STOPPED',
|
|
|
|
'current_transport_status': 'OK'}
|
|
|
|
|
|
|
|
def get_current_track_info(self):
|
2016-07-30 08:30:13 +00:00
|
|
|
"""Return a dict with the current track information."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return {'album': '',
|
|
|
|
'uri': '',
|
|
|
|
'title': '',
|
|
|
|
'artist': '',
|
|
|
|
'duration': '0:00:00',
|
|
|
|
'album_art': '',
|
|
|
|
'position': '0:00:00',
|
|
|
|
'playlist_position': '0',
|
|
|
|
'metadata': ''}
|
|
|
|
|
|
|
|
def is_coordinator(self):
|
2016-07-30 08:30:13 +00:00
|
|
|
"""Return true if coordinator."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return True
|
|
|
|
|
2017-01-27 06:50:36 +00:00
|
|
|
def join(self, master):
|
|
|
|
"""Join speaker to a group."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return
|
|
|
|
|
2016-10-26 06:22:17 +00:00
|
|
|
def set_sleep_timer(self, sleep_time_seconds):
|
|
|
|
"""Set the sleep timer."""
|
|
|
|
return
|
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
def unjoin(self):
|
2016-07-30 08:30:13 +00:00
|
|
|
"""Cause the speaker to separate itself from other speakers."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return
|
|
|
|
|
2016-10-20 15:36:48 +00:00
|
|
|
def uid(self):
|
|
|
|
"""Return a player uid."""
|
|
|
|
return "RINCON_XXXXXXXXXXXXXXXXX"
|
|
|
|
|
2017-01-27 06:50:36 +00:00
|
|
|
def group(self):
|
|
|
|
"""Return all group data of this player."""
|
|
|
|
return
|
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def add_entities_factory(hass):
|
2019-02-24 17:45:08 +00:00
|
|
|
"""Add entities factory."""
|
|
|
|
def add_entities(entities, update_befor_add=False):
|
|
|
|
"""Fake add entity."""
|
2019-02-25 21:03:15 +00:00
|
|
|
hass.data[sonos.DATA_SONOS].entities = list(entities)
|
2018-03-08 23:39:31 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
return add_entities
|
2016-11-05 23:58:29 +00:00
|
|
|
|
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
class TestSonosMediaPlayer(unittest.TestCase):
|
|
|
|
"""Test the media_player module."""
|
|
|
|
|
2016-12-02 05:45:19 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def setUp(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-07-29 03:40:58 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
|
|
|
|
|
|
|
def monkey_available(self):
|
2016-12-02 05:45:19 +00:00
|
|
|
"""Make a monkey available."""
|
2016-07-29 03:40:58 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
# Monkey patches
|
2019-02-24 17:45:08 +00:00
|
|
|
self.real_available = sonos.SonosEntity.available
|
|
|
|
sonos.SonosEntity.available = monkey_available
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2016-12-02 05:45:19 +00:00
|
|
|
# pylint: disable=invalid-name
|
|
|
|
def tearDown(self):
|
2016-07-29 03:40:58 +00:00
|
|
|
"""Stop everything that was started."""
|
|
|
|
# Monkey patches
|
2019-02-24 17:45:08 +00:00
|
|
|
sonos.SonosEntity.available = self.real_available
|
2016-07-29 03:40:58 +00:00
|
|
|
self.hass.stop()
|
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
|
|
|
def test_ensure_setup_discovery(self, *args):
|
2016-07-29 03:40:58 +00:00
|
|
|
"""Test a single device using the autodiscovery provided by HASS."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-04-12 03:10:02 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2019-02-25 21:03:15 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
2019-02-24 17:45:08 +00:00
|
|
|
assert len(entities) == 1
|
|
|
|
assert entities[0].name == 'Kitchen'
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.discover')
|
2016-12-02 06:22:03 +00:00
|
|
|
def test_ensure_setup_config_interface_addr(self, discover_mock, *args):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Test an interface address config'd by the HASS config file."""
|
2016-12-02 06:22:03 +00:00
|
|
|
discover_mock.return_value = {SoCoMock('192.0.2.1')}
|
|
|
|
|
|
|
|
config = {
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'sonos',
|
|
|
|
CONF_INTERFACE_ADDR: '192.0.1.1',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert setup_component(self.hass, DOMAIN, config)
|
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
assert len(self.hass.data[sonos.DATA_SONOS].entities) == 1
|
2018-10-24 10:10:05 +00:00
|
|
|
assert discover_mock.call_count == 1
|
2016-12-02 06:22:03 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-12-02 06:22:03 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
|
|
|
def test_ensure_setup_config_hosts_string_single(self, *args):
|
2016-07-29 03:40:58 +00:00
|
|
|
"""Test a single address config'd by the HASS config file."""
|
2016-12-02 06:22:03 +00:00
|
|
|
config = {
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'sonos',
|
|
|
|
CONF_HOSTS: ['192.0.2.1'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert setup_component(self.hass, DOMAIN, config)
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
|
|
|
assert len(entities) == 1
|
|
|
|
assert entities[0].name == 'Kitchen'
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-12-02 06:22:03 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
|
|
|
def test_ensure_setup_config_hosts_string_multiple(self, *args):
|
|
|
|
"""Test multiple address string config'd by the HASS config file."""
|
|
|
|
config = {
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'sonos',
|
|
|
|
CONF_HOSTS: ['192.0.2.1,192.168.2.2'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert setup_component(self.hass, DOMAIN, config)
|
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
|
|
|
assert len(entities) == 2
|
|
|
|
assert entities[0].name == 'Kitchen'
|
2016-12-02 06:22:03 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-12-02 06:22:03 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
|
|
|
def test_ensure_setup_config_hosts_list(self, *args):
|
|
|
|
"""Test a multiple address list config'd by the HASS config file."""
|
|
|
|
config = {
|
|
|
|
DOMAIN: {
|
|
|
|
CONF_PLATFORM: 'sonos',
|
|
|
|
CONF_HOSTS: ['192.0.2.1', '192.168.2.2'],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert setup_component(self.hass, DOMAIN, config)
|
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
|
|
|
assert len(entities) == 2
|
|
|
|
assert entities[0].name == 'Kitchen'
|
2016-12-02 06:22:03 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
|
|
|
@mock.patch.object(pysonos, 'discover', new=pysonosDiscoverMock.discover)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
|
|
|
def test_ensure_setup_sonos_discovery(self, *args):
|
2016-07-29 03:40:58 +00:00
|
|
|
"""Test a single device using the autodiscovery provided by Sonos."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass))
|
2019-02-25 21:03:15 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
2019-02-24 17:45:08 +00:00
|
|
|
assert len(entities) == 1
|
|
|
|
assert entities[0].name == 'Kitchen'
|
2017-12-07 19:44:06 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2016-10-26 06:22:17 +00:00
|
|
|
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
2016-11-04 04:23:37 +00:00
|
|
|
def test_sonos_set_sleep_timer(self, set_sleep_timerMock, *args):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Ensure pysonos methods called for sonos_set_sleep_timer service."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-04-12 03:10:02 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2019-02-25 21:03:15 +00:00
|
|
|
entity = self.hass.data[sonos.DATA_SONOS].entities[-1]
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.hass = self.hass
|
2017-04-06 06:24:30 +00:00
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.set_sleep_timer(30)
|
2016-10-26 06:22:17 +00:00
|
|
|
set_sleep_timerMock.assert_called_once_with(30)
|
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2016-10-26 06:22:17 +00:00
|
|
|
@mock.patch.object(SoCoMock, 'set_sleep_timer')
|
2016-11-04 04:23:37 +00:00
|
|
|
def test_sonos_clear_sleep_timer(self, set_sleep_timerMock, *args):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Ensure pysonos method called for sonos_clear_sleep_timer service."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-04-12 03:10:02 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2019-02-25 21:03:15 +00:00
|
|
|
entity = self.hass.data[sonos.DATA_SONOS].entities[-1]
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.hass = self.hass
|
2017-04-06 06:24:30 +00:00
|
|
|
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.set_sleep_timer(None)
|
2016-10-26 06:22:17 +00:00
|
|
|
set_sleep_timerMock.assert_called_once_with(None)
|
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
|
|
|
@mock.patch('pysonos.alarms.Alarm')
|
2017-05-15 07:42:45 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2018-09-20 21:50:11 +00:00
|
|
|
def test_set_alarm(self, pysonos_mock, alarm_mock, *args):
|
|
|
|
"""Ensure pysonos methods called for sonos_set_sleep_timer service."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-05-15 07:42:45 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2019-02-25 21:03:15 +00:00
|
|
|
entity = self.hass.data[sonos.DATA_SONOS].entities[-1]
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.hass = self.hass
|
2018-09-20 21:50:11 +00:00
|
|
|
alarm1 = alarms.Alarm(pysonos_mock)
|
2017-05-15 07:42:45 +00:00
|
|
|
alarm1.configure_mock(_alarm_id="1", start_time=None, enabled=False,
|
|
|
|
include_linked_zones=False, volume=100)
|
2018-09-20 21:50:11 +00:00
|
|
|
with mock.patch('pysonos.alarms.get_alarms', return_value=[alarm1]):
|
2017-05-15 07:42:45 +00:00
|
|
|
attrs = {
|
|
|
|
'time': datetime.time(12, 00),
|
|
|
|
'enabled': True,
|
|
|
|
'include_linked_zones': True,
|
|
|
|
'volume': 0.30,
|
|
|
|
}
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.set_alarm(alarm_id=2)
|
2017-05-15 07:42:45 +00:00
|
|
|
alarm1.save.assert_not_called()
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.set_alarm(alarm_id=1, **attrs)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert alarm1.enabled == attrs['enabled']
|
|
|
|
assert alarm1.start_time == attrs['time']
|
|
|
|
assert alarm1.include_linked_zones == \
|
|
|
|
attrs['include_linked_zones']
|
|
|
|
assert alarm1.volume == 30
|
2017-05-15 07:42:45 +00:00
|
|
|
alarm1.save.assert_called_once_with()
|
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch.object(pysonos.snapshot.Snapshot, 'snapshot')
|
2016-11-04 04:23:37 +00:00
|
|
|
def test_sonos_snapshot(self, snapshotMock, *args):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Ensure pysonos methods called for sonos_snapshot service."""
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-04-12 03:10:02 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2019-02-25 21:03:15 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
|
|
|
entity = entities[-1]
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.hass = self.hass
|
2017-04-06 06:24:30 +00:00
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
snapshotMock.return_value = True
|
2019-02-25 21:03:15 +00:00
|
|
|
entity.soco.group = mock.MagicMock()
|
|
|
|
entity.soco.group.members = [e.soco for e in entities]
|
2019-03-13 09:17:09 +00:00
|
|
|
run_coroutine_threadsafe(
|
|
|
|
sonos.SonosEntity.snapshot_multi(self.hass, entities, True),
|
|
|
|
self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert snapshotMock.call_count == 1
|
|
|
|
assert snapshotMock.call_args == mock.call()
|
2016-07-29 03:40:58 +00:00
|
|
|
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch('pysonos.SoCo', new=SoCoMock)
|
2016-11-04 04:23:37 +00:00
|
|
|
@mock.patch('socket.create_connection', side_effect=socket.error())
|
2018-09-20 21:50:11 +00:00
|
|
|
@mock.patch.object(pysonos.snapshot.Snapshot, 'restore')
|
2016-11-04 04:23:37 +00:00
|
|
|
def test_sonos_restore(self, restoreMock, *args):
|
2018-09-20 21:50:11 +00:00
|
|
|
"""Ensure pysonos methods called for sonos_restore service."""
|
|
|
|
from pysonos.snapshot import Snapshot
|
2017-04-06 06:24:30 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
sonos.setup_platform(self.hass, {}, add_entities_factory(self.hass), {
|
2017-04-12 03:10:02 +00:00
|
|
|
'host': '192.0.2.1'
|
|
|
|
})
|
2019-02-25 21:03:15 +00:00
|
|
|
entities = self.hass.data[sonos.DATA_SONOS].entities
|
|
|
|
entity = entities[-1]
|
2019-02-24 17:45:08 +00:00
|
|
|
entity.hass = self.hass
|
2017-04-06 06:24:30 +00:00
|
|
|
|
2016-07-29 03:40:58 +00:00
|
|
|
restoreMock.return_value = True
|
2019-02-25 21:03:15 +00:00
|
|
|
entity._snapshot_group = mock.MagicMock()
|
|
|
|
entity._snapshot_group.members = [e.soco for e in entities]
|
|
|
|
entity._soco_snapshot = Snapshot(entity.soco)
|
2019-03-13 09:17:09 +00:00
|
|
|
run_coroutine_threadsafe(
|
|
|
|
sonos.SonosEntity.restore_multi(self.hass, entities, True),
|
|
|
|
self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert restoreMock.call_count == 1
|
2019-02-25 21:03:15 +00:00
|
|
|
assert restoreMock.call_args == mock.call()
|