2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the Universal Media player platform."""
|
2019-10-01 14:59:06 +00:00
|
|
|
import asyncio
|
2016-01-12 05:43:34 +00:00
|
|
|
from copy import copy
|
|
|
|
import unittest
|
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
from voluptuous.error import MultipleInvalid
|
|
|
|
|
2017-10-03 19:34:13 +00:00
|
|
|
import homeassistant.components.input_number as input_number
|
2016-12-04 04:09:28 +00:00
|
|
|
import homeassistant.components.input_select as input_select
|
2016-01-12 05:43:34 +00:00
|
|
|
import homeassistant.components.media_player as media_player
|
2019-12-09 18:07:32 +00:00
|
|
|
import homeassistant.components.switch as switch
|
2019-03-19 06:07:39 +00:00
|
|
|
import homeassistant.components.universal.media_player as universal
|
2019-12-09 18:07:32 +00:00
|
|
|
from homeassistant.const import STATE_OFF, STATE_ON, STATE_PAUSED, STATE_PLAYING
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2019-12-09 18:07:32 +00:00
|
|
|
from tests.common import get_test_home_assistant, mock_service
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
def validate_config(config):
|
|
|
|
"""Use the platform schema to validate configuration."""
|
|
|
|
validated_config = universal.PLATFORM_SCHEMA(config)
|
2019-07-31 19:25:30 +00:00
|
|
|
validated_config.pop("platform")
|
2017-11-14 10:41:19 +00:00
|
|
|
return validated_config
|
|
|
|
|
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
class MockMediaPlayer(media_player.MediaPlayerDevice):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock media player for testing."""
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def __init__(self, hass, name):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Initialize the media player."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self.hass = hass
|
|
|
|
self._name = name
|
|
|
|
self.entity_id = media_player.ENTITY_ID_FORMAT.format(name)
|
|
|
|
self._state = STATE_OFF
|
|
|
|
self._volume_level = 0
|
|
|
|
self._is_volume_muted = False
|
|
|
|
self._media_title = None
|
2017-02-08 04:42:45 +00:00
|
|
|
self._supported_features = 0
|
2016-03-27 18:41:52 +00:00
|
|
|
self._source = None
|
2016-07-15 16:00:41 +00:00
|
|
|
self._tracks = 12
|
2016-12-06 02:07:04 +00:00
|
|
|
self._media_image_url = None
|
2017-04-30 19:41:21 +00:00
|
|
|
self._shuffle = False
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
self.service_calls = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"turn_on": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_TURN_ON
|
|
|
|
),
|
|
|
|
"turn_off": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_TURN_OFF
|
|
|
|
),
|
|
|
|
"mute_volume": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_MUTE
|
|
|
|
),
|
|
|
|
"set_volume_level": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_SET
|
|
|
|
),
|
|
|
|
"media_play": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PLAY
|
|
|
|
),
|
|
|
|
"media_pause": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PAUSE
|
|
|
|
),
|
|
|
|
"media_previous_track": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PREVIOUS_TRACK
|
|
|
|
),
|
|
|
|
"media_next_track": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_NEXT_TRACK
|
|
|
|
),
|
|
|
|
"media_seek": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_SEEK
|
|
|
|
),
|
|
|
|
"play_media": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_PLAY_MEDIA
|
|
|
|
),
|
|
|
|
"volume_up": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_UP
|
|
|
|
),
|
|
|
|
"volume_down": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_VOLUME_DOWN
|
|
|
|
),
|
|
|
|
"media_play_pause": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_MEDIA_PLAY_PAUSE
|
|
|
|
),
|
|
|
|
"select_source": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_SELECT_SOURCE
|
|
|
|
),
|
|
|
|
"clear_playlist": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_CLEAR_PLAYLIST
|
|
|
|
),
|
|
|
|
"shuffle_set": mock_service(
|
|
|
|
hass, media_player.DOMAIN, media_player.SERVICE_SHUFFLE_SET
|
|
|
|
),
|
2016-03-18 12:33:52 +00:00
|
|
|
}
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Return the name of player."""
|
2016-01-12 05:43:34 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Return the state of the player."""
|
2016-01-12 05:43:34 +00:00
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def volume_level(self):
|
2018-08-24 08:28:43 +00:00
|
|
|
"""Return the volume level of player."""
|
2016-01-12 05:43:34 +00:00
|
|
|
return self._volume_level
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_volume_muted(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Return true if the media player is muted."""
|
2016-01-12 05:43:34 +00:00
|
|
|
return self._is_volume_muted
|
|
|
|
|
|
|
|
@property
|
2017-02-08 04:42:45 +00:00
|
|
|
def supported_features(self):
|
|
|
|
"""Flag media player features that are supported."""
|
|
|
|
return self._supported_features
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-12-06 02:07:04 +00:00
|
|
|
@property
|
|
|
|
def media_image_url(self):
|
|
|
|
"""Image url of current playing media."""
|
|
|
|
return self._media_image_url
|
|
|
|
|
2017-04-30 19:41:21 +00:00
|
|
|
@property
|
|
|
|
def shuffle(self):
|
|
|
|
"""Return true if the media player is shuffling."""
|
|
|
|
return self._shuffle
|
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def turn_on(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock turn_on function."""
|
2019-01-24 07:20:20 +00:00
|
|
|
self._state = None
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def turn_off(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock turn_off function."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self._state = STATE_OFF
|
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
def mute_volume(self, mute):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock mute function."""
|
2017-11-14 10:41:19 +00:00
|
|
|
self._is_volume_muted = mute
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def set_volume_level(self, volume):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock set volume level."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self._volume_level = volume
|
|
|
|
|
|
|
|
def media_play(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock play."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self._state = STATE_PLAYING
|
|
|
|
|
|
|
|
def media_pause(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Mock pause."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self._state = STATE_PAUSED
|
|
|
|
|
2016-03-27 18:41:52 +00:00
|
|
|
def select_source(self, source):
|
|
|
|
"""Set the input source."""
|
2018-01-18 05:19:34 +00:00
|
|
|
self._source = source
|
2016-03-27 18:41:52 +00:00
|
|
|
|
2016-07-15 16:00:41 +00:00
|
|
|
def clear_playlist(self):
|
|
|
|
"""Clear players playlist."""
|
|
|
|
self._tracks = 0
|
|
|
|
|
2017-04-30 19:41:21 +00:00
|
|
|
def set_shuffle(self, shuffle):
|
|
|
|
"""Clear players playlist."""
|
|
|
|
self._shuffle = shuffle
|
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
class TestMediaPlayer(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the media_player module."""
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_mp_1 = MockMediaPlayer(self.hass, "mock1")
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_mp_2 = MockMediaPlayer(self.hass, "mock2")
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_2.schedule_update_ha_state()
|
|
|
|
|
|
|
|
self.hass.block_till_done()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_mute_switch_id = switch.ENTITY_ID_FORMAT.format("mute")
|
2016-01-12 05:43:34 +00:00
|
|
|
self.hass.states.set(self.mock_mute_switch_id, STATE_OFF)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_state_switch_id = switch.ENTITY_ID_FORMAT.format("state")
|
2016-01-12 05:43:34 +00:00
|
|
|
self.hass.states.set(self.mock_state_switch_id, STATE_OFF)
|
|
|
|
|
2020-02-28 11:39:29 +00:00
|
|
|
self.mock_volume_id = f"{input_number.DOMAIN}.volume_level"
|
2016-12-04 04:09:28 +00:00
|
|
|
self.hass.states.set(self.mock_volume_id, 0)
|
|
|
|
|
2020-02-28 11:39:29 +00:00
|
|
|
self.mock_source_list_id = f"{input_select.DOMAIN}.source_list"
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set(self.mock_source_list_id, ["dvd", "htpc"])
|
2016-12-04 04:09:28 +00:00
|
|
|
|
2020-02-28 11:39:29 +00:00
|
|
|
self.mock_source_id = f"{input_select.DOMAIN}.source"
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set(self.mock_source_id, "dvd")
|
2016-12-04 04:09:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.mock_shuffle_switch_id = switch.ENTITY_ID_FORMAT.format("shuffle")
|
2017-04-30 19:41:21 +00:00
|
|
|
self.hass.states.set(self.mock_shuffle_switch_id, STATE_OFF)
|
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
self.config_children_only = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"name": "test",
|
|
|
|
"platform": "universal",
|
|
|
|
"children": [
|
|
|
|
media_player.ENTITY_ID_FORMAT.format("mock1"),
|
|
|
|
media_player.ENTITY_ID_FORMAT.format("mock2"),
|
|
|
|
],
|
2016-03-18 12:33:52 +00:00
|
|
|
}
|
|
|
|
self.config_children_and_attr = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"name": "test",
|
|
|
|
"platform": "universal",
|
|
|
|
"children": [
|
|
|
|
media_player.ENTITY_ID_FORMAT.format("mock1"),
|
|
|
|
media_player.ENTITY_ID_FORMAT.format("mock2"),
|
|
|
|
],
|
|
|
|
"attributes": {
|
|
|
|
"is_volume_muted": self.mock_mute_switch_id,
|
|
|
|
"volume_level": self.mock_volume_id,
|
|
|
|
"source": self.mock_source_id,
|
|
|
|
"source_list": self.mock_source_list_id,
|
|
|
|
"state": self.mock_state_switch_id,
|
|
|
|
"shuffle": self.mock_shuffle_switch_id,
|
|
|
|
},
|
2016-03-18 12:33:52 +00:00
|
|
|
}
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2016-01-12 05:43:34 +00:00
|
|
|
self.hass.stop()
|
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_children_only(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with only children."""
|
2016-01-12 05:43:34 +00:00
|
|
|
config_start = copy(self.config_children_only)
|
2019-07-31 19:25:30 +00:00
|
|
|
del config_start["platform"]
|
|
|
|
config_start["commands"] = {}
|
|
|
|
config_start["attributes"] = {}
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert config_start == config
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_children_and_attr(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with children and attributes."""
|
2016-01-12 05:43:34 +00:00
|
|
|
config_start = copy(self.config_children_and_attr)
|
2019-07-31 19:25:30 +00:00
|
|
|
del config_start["platform"]
|
|
|
|
config_start["commands"] = {}
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert config_start == config
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_no_name(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with no Name entry."""
|
2017-11-14 10:41:19 +00:00
|
|
|
response = True
|
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
validate_config({"platform": "universal"})
|
2017-11-14 10:41:19 +00:00
|
|
|
except MultipleInvalid:
|
|
|
|
response = False
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not response
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_bad_children(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with bad children entry."""
|
2019-07-31 19:25:30 +00:00
|
|
|
config_no_children = {"name": "test", "platform": "universal"}
|
|
|
|
config_bad_children = {"name": "test", "children": {}, "platform": "universal"}
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config_no_children = validate_config(config_no_children)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert [] == config_no_children["children"]
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config_bad_children = validate_config(config_bad_children)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert [] == config_bad_children["children"]
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_bad_commands(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with bad commands entry."""
|
2019-07-31 19:25:30 +00:00
|
|
|
config = {"name": "test", "platform": "universal"}
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert {} == config["commands"]
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_bad_attributes(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with bad attributes."""
|
2019-07-31 19:25:30 +00:00
|
|
|
config = {"name": "test", "platform": "universal"}
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert {} == config["attributes"]
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_config_bad_key(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Check config with bad key."""
|
2019-07-31 19:25:30 +00:00
|
|
|
config = {"name": "test", "asdf": 5, "platform": "universal"}
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert not ("asdf" in config)
|
2016-01-30 12:18:37 +00:00
|
|
|
|
|
|
|
def test_platform_setup(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test platform setup."""
|
2019-07-31 19:25:30 +00:00
|
|
|
config = {"name": "test", "platform": "universal"}
|
|
|
|
bad_config = {"platform": "universal"}
|
2016-01-30 12:18:37 +00:00
|
|
|
entities = []
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def add_entities(new_entities):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Add devices to list."""
|
2016-01-30 12:18:37 +00:00
|
|
|
for dev in new_entities:
|
|
|
|
entities.append(dev)
|
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
setup_ok = True
|
|
|
|
try:
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2017-11-14 10:41:19 +00:00
|
|
|
universal.async_setup_platform(
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass, validate_config(bad_config), add_entities
|
|
|
|
),
|
|
|
|
self.hass.loop,
|
|
|
|
).result()
|
2017-11-14 10:41:19 +00:00
|
|
|
except MultipleInvalid:
|
|
|
|
setup_ok = False
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not setup_ok
|
|
|
|
assert 0 == len(entities)
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2017-11-14 10:41:19 +00:00
|
|
|
universal.async_setup_platform(
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass, validate_config(config), add_entities
|
|
|
|
),
|
|
|
|
self.hass.loop,
|
|
|
|
).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 1 == len(entities)
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "test" == entities[0].name
|
2016-01-30 12:18:37 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def test_master_state(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test master state property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.master_state is None
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def test_master_state_with_attrs(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test master state property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_OFF == ump.master_state
|
2016-01-12 05:43:34 +00:00
|
|
|
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_ON == ump.master_state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-11-14 10:41:19 +00:00
|
|
|
def test_master_state_with_template(self):
|
|
|
|
"""Test the state_template option."""
|
|
|
|
config = copy(self.config_children_and_attr)
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("input_boolean.test", STATE_OFF)
|
|
|
|
templ = (
|
|
|
|
'{% if states.input_boolean.test.state == "off" %}on'
|
|
|
|
"{% else %}{{ states.media_player.mock1.state }}{% endif %}"
|
|
|
|
)
|
|
|
|
config["state_template"] = templ
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_ON == ump.master_state
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set("input_boolean.test", STATE_ON)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_OFF == ump.master_state
|
2017-11-14 10:41:19 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def test_master_state_with_bad_attrs(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test master state property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = copy(self.config_children_and_attr)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["attributes"]["state"] = "bad.entity_id"
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_OFF == ump.master_state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def test_active_child_state(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test active child state property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump._child_state is None
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.mock_mp_1.entity_id == ump._child_state.entity_id
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_2._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_2.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.mock_mp_1.entity_id == ump._child_state.entity_id
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_OFF
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert self.mock_mp_2.entity_id == ump._child_state.entity_id
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def test_name(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test name property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert config["name"] == ump.name
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-03-18 12:33:52 +00:00
|
|
|
def test_polling(self):
|
|
|
|
"""Test should_poll property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-03-18 12:33:52 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.should_poll is False
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def test_state_children_only(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test media player state with only children."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.state, STATE_OFF
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_PLAYING == ump.state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def test_state_with_children_and_attrs(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test media player with children and master state."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_OFF == ump.state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.hass.states.set(self.mock_state_switch_id, STATE_ON)
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_ON == ump.state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_PLAYING == ump.state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.hass.states.set(self.mock_state_switch_id, STATE_OFF)
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert STATE_OFF == ump.state
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
def test_volume_level(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test volume level property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.volume_level is None
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 0 == ump.volume_level
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._volume_level = 1
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 1 == ump.volume_level
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-12-06 02:07:04 +00:00
|
|
|
def test_media_image_url(self):
|
|
|
|
"""Test media_image_url property."""
|
2017-11-14 10:41:19 +00:00
|
|
|
test_url = "test_url"
|
|
|
|
config = validate_config(self.config_children_only)
|
2016-12-06 02:07:04 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-12-06 02:07:04 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.media_image_url is None
|
2016-12-06 02:07:04 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-11-14 10:41:19 +00:00
|
|
|
self.mock_mp_1._media_image_url = test_url
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-12-06 02:07:04 +00:00
|
|
|
# mock_mp_1 will convert the url to the api proxy url. This test
|
|
|
|
# ensures ump passes through the same url without an additional proxy.
|
2018-10-24 10:10:05 +00:00
|
|
|
assert self.mock_mp_1.entity_picture == ump.entity_picture
|
2016-12-06 02:07:04 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def test_is_volume_muted_children_only(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test is volume muted property w/ children only."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not ump.is_volume_muted
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not ump.is_volume_muted
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._is_volume_muted = True
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.is_volume_muted
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2016-12-04 04:09:28 +00:00
|
|
|
def test_source_list_children_and_attr(self):
|
|
|
|
"""Test source list property w/ children and attrs."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert "['dvd', 'htpc']" == ump.source_list
|
2016-12-04 04:09:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set(self.mock_source_list_id, ["dvd", "htpc", "game"])
|
2018-10-24 10:10:05 +00:00
|
|
|
assert "['dvd', 'htpc', 'game']" == ump.source_list
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
def test_source_children_and_attr(self):
|
|
|
|
"""Test source property w/ children and attrs."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert "dvd" == ump.source
|
2016-12-04 04:09:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.states.set(self.mock_source_id, "htpc")
|
|
|
|
assert "htpc" == ump.source
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
def test_volume_level_children_and_attr(self):
|
|
|
|
"""Test volume level property w/ children and attrs."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2019-11-26 02:01:24 +00:00
|
|
|
assert 0 == ump.volume_level
|
2016-12-04 04:09:28 +00:00
|
|
|
|
|
|
|
self.hass.states.set(self.mock_volume_id, 100)
|
2019-11-26 02:01:24 +00:00
|
|
|
assert 100 == ump.volume_level
|
2016-12-04 04:09:28 +00:00
|
|
|
|
2016-01-12 05:43:34 +00:00
|
|
|
def test_is_volume_muted_children_and_attr(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test is volume muted property w/ children and attrs."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert not ump.is_volume_muted
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
|
2018-10-24 10:10:05 +00:00
|
|
|
assert ump.is_volume_muted
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-02-08 04:42:45 +00:00
|
|
|
def test_supported_features_children_only(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test supported media commands with only children."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 0 == ump.supported_features
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-02-08 04:42:45 +00:00
|
|
|
self.mock_mp_1._supported_features = 512
|
2016-01-12 05:43:34 +00:00
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 512 == ump.supported_features
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2017-02-08 04:42:45 +00:00
|
|
|
def test_supported_features_children_and_cmds(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test supported media commands with children and attrs."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = copy(self.config_children_and_attr)
|
2019-07-31 19:25:30 +00:00
|
|
|
excmd = {"service": "media_player.test", "data": {"entity_id": "test"}}
|
|
|
|
config["commands"] = {
|
|
|
|
"turn_on": excmd,
|
|
|
|
"turn_off": excmd,
|
|
|
|
"volume_up": excmd,
|
|
|
|
"volume_down": excmd,
|
|
|
|
"volume_mute": excmd,
|
|
|
|
"volume_set": excmd,
|
|
|
|
"select_source": excmd,
|
|
|
|
"shuffle_set": excmd,
|
2017-11-14 10:41:19 +00:00
|
|
|
}
|
|
|
|
config = validate_config(config)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
check_flags = (
|
|
|
|
universal.SUPPORT_TURN_ON
|
|
|
|
| universal.SUPPORT_TURN_OFF
|
|
|
|
| universal.SUPPORT_VOLUME_STEP
|
|
|
|
| universal.SUPPORT_VOLUME_MUTE
|
|
|
|
| universal.SUPPORT_SELECT_SOURCE
|
|
|
|
| universal.SUPPORT_SHUFFLE_SET
|
2019-02-06 19:16:21 +00:00
|
|
|
| universal.SUPPORT_VOLUME_SET
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2016-01-12 05:43:34 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert check_flags == ump.supported_features
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2017-01-18 06:15:37 +00:00
|
|
|
def test_service_call_no_active_child(self):
|
|
|
|
"""Test a service call to children with no active child."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_and_attr)
|
2017-01-18 06:15:37 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2017-01-18 06:15:37 +00:00
|
|
|
|
|
|
|
self.mock_mp_1._state = STATE_OFF
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_1.schedule_update_ha_state()
|
2017-01-18 06:15:37 +00:00
|
|
|
self.mock_mp_2._state = STATE_OFF
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_2.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2017-01-18 06:15:37 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 0 == len(self.mock_mp_1.service_calls["turn_off"])
|
|
|
|
assert 0 == len(self.mock_mp_2.service_calls["turn_off"])
|
2017-01-18 06:15:37 +00:00
|
|
|
|
2016-01-30 17:26:28 +00:00
|
|
|
def test_service_call_to_child(self):
|
2016-03-18 12:33:52 +00:00
|
|
|
"""Test service calls that should be routed to a child."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(self.config_children_only)
|
2016-01-30 17:26:28 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-30 17:26:28 +00:00
|
|
|
|
|
|
|
self.mock_mp_2._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_2.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["turn_off"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_turn_on(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["turn_on"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_mute_volume(True), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["mute_volume"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.async_set_volume_level(0.5), self.hass.loop
|
|
|
|
).result()
|
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["set_volume_level"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_media_play(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_play"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_media_pause(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_pause"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.async_media_previous_track(), self.hass.loop
|
|
|
|
).result()
|
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_previous_track"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_media_next_track(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_next_track"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_media_seek(100), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_seek"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.async_play_media("movie", "batman"), self.hass.loop
|
|
|
|
).result()
|
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["play_media"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_volume_up(), self.hass.loop).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["volume_up"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_volume_down(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["volume_down"])
|
2016-03-18 12:33:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_media_play_pause(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["media_play_pause"])
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.async_select_source("dvd"), self.hass.loop
|
|
|
|
).result()
|
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["select_source"])
|
2016-03-27 18:41:52 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_clear_playlist(), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["clear_playlist"])
|
2016-07-15 16:00:41 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(
|
|
|
|
ump.async_set_shuffle(True), self.hass.loop
|
|
|
|
).result()
|
2019-07-31 19:25:30 +00:00
|
|
|
assert 1 == len(self.mock_mp_2.service_calls["shuffle_set"])
|
2017-04-30 19:41:21 +00:00
|
|
|
|
2016-01-30 17:26:28 +00:00
|
|
|
def test_service_call_to_command(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test service call to command."""
|
2017-11-14 10:41:19 +00:00
|
|
|
config = copy(self.config_children_only)
|
2019-07-31 19:25:30 +00:00
|
|
|
config["commands"] = {"turn_off": {"service": "test.turn_off", "data": {}}}
|
2017-11-14 10:41:19 +00:00
|
|
|
config = validate_config(config)
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
service = mock_service(self.hass, "test", "turn_off")
|
2016-01-30 17:26:28 +00:00
|
|
|
|
|
|
|
ump = universal.UniversalMediaPlayer(self.hass, **config)
|
2019-07-31 19:25:30 +00:00
|
|
|
ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-30 17:26:28 +00:00
|
|
|
|
|
|
|
self.mock_mp_2._state = STATE_PLAYING
|
2017-03-04 23:10:36 +00:00
|
|
|
self.mock_mp_2.schedule_update_ha_state()
|
|
|
|
self.hass.block_till_done()
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
|
2016-01-30 17:26:28 +00:00
|
|
|
|
2019-10-01 14:59:06 +00:00
|
|
|
asyncio.run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
|
2018-10-24 10:10:05 +00:00
|
|
|
assert 1 == len(service)
|