2016-11-16 05:56:40 +00:00
|
|
|
"""The tests for the Yamaha Media player platform."""
|
|
|
|
import unittest
|
2018-01-17 18:34:21 +00:00
|
|
|
|
|
|
|
import homeassistant.components.media_player as mp
|
2019-03-19 06:07:39 +00:00
|
|
|
from homeassistant.components.yamaha import media_player as yamaha
|
2019-12-09 13:57:42 +00:00
|
|
|
from homeassistant.setup import setup_component
|
|
|
|
|
2020-05-03 18:27:19 +00:00
|
|
|
from tests.async_mock import MagicMock, patch
|
2018-01-17 18:34:21 +00:00
|
|
|
from tests.common import get_test_home_assistant
|
|
|
|
|
|
|
|
|
|
|
|
def _create_zone_mock(name, url):
|
|
|
|
zone = MagicMock()
|
|
|
|
zone.ctrl_url = url
|
|
|
|
zone.zone = name
|
|
|
|
return zone
|
|
|
|
|
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class FakeYamahaDevice:
|
2018-01-17 18:34:21 +00:00
|
|
|
"""A fake Yamaha device."""
|
|
|
|
|
|
|
|
def __init__(self, ctrl_url, name, zones=None):
|
|
|
|
"""Initialize the fake Yamaha device."""
|
|
|
|
self.ctrl_url = ctrl_url
|
|
|
|
self.name = name
|
|
|
|
self.zones = zones or []
|
|
|
|
|
|
|
|
def zone_controllers(self):
|
|
|
|
"""Return controllers for all available zones."""
|
|
|
|
return self.zones
|
|
|
|
|
|
|
|
|
|
|
|
class TestYamahaMediaPlayer(unittest.TestCase):
|
|
|
|
"""Test the Yamaha media player."""
|
2016-11-16 05:56:40 +00:00
|
|
|
|
2016-11-18 22:05:03 +00:00
|
|
|
def setUp(self):
|
2018-08-19 20:29:08 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
2018-01-17 18:34:21 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2019-07-31 19:25:30 +00:00
|
|
|
self.main_zone = _create_zone_mock("Main zone", "http://main")
|
2018-01-17 18:34:21 +00:00
|
|
|
self.device = FakeYamahaDevice(
|
2019-07-31 19:25:30 +00:00
|
|
|
"http://receiver", "Receiver", zones=[self.main_zone]
|
|
|
|
)
|
2018-01-17 18:34:21 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""Stop everything that was started."""
|
|
|
|
self.hass.stop()
|
|
|
|
|
|
|
|
def enable_output(self, port, enabled):
|
2018-01-27 19:58:27 +00:00
|
|
|
"""Enable output on a specific port."""
|
2018-01-17 18:34:21 +00:00
|
|
|
data = {
|
2019-07-31 19:25:30 +00:00
|
|
|
"entity_id": "media_player.yamaha_receiver_main_zone",
|
|
|
|
"port": port,
|
|
|
|
"enabled": enabled,
|
2018-01-17 18:34:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.hass.services.call(yamaha.DOMAIN, yamaha.SERVICE_ENABLE_OUTPUT, data, True)
|
2018-01-17 18:34:21 +00:00
|
|
|
|
|
|
|
def create_receiver(self, mock_rxv):
|
|
|
|
"""Create a mocked receiver."""
|
|
|
|
mock_rxv.return_value = self.device
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
config = {"media_player": {"platform": "yamaha", "host": "127.0.0.1"}}
|
2018-01-17 18:34:21 +00:00
|
|
|
|
2018-10-24 10:10:05 +00:00
|
|
|
assert setup_component(self.hass, mp.DOMAIN, config)
|
2020-06-01 05:18:30 +00:00
|
|
|
self.hass.block_till_done()
|
2018-01-17 18:34:21 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
@patch("rxv.RXV")
|
2018-01-17 18:34:21 +00:00
|
|
|
def test_enable_output(self, mock_rxv):
|
|
|
|
"""Test enabling and disabling outputs."""
|
|
|
|
self.create_receiver(mock_rxv)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.enable_output("hdmi1", True)
|
|
|
|
self.main_zone.enable_output.assert_called_with("hdmi1", True)
|
2018-01-17 18:34:21 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self.enable_output("hdmi2", False)
|
|
|
|
self.main_zone.enable_output.assert_called_with("hdmi2", False)
|