* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
"""The tests for the Yamaha Media player platform."""
|
|
import unittest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from homeassistant.setup import setup_component
|
|
import homeassistant.components.media_player as mp
|
|
from homeassistant.components.yamaha import media_player as yamaha
|
|
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
|
|
|
|
|
|
class FakeYamahaDevice:
|
|
"""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."""
|
|
|
|
def setUp(self):
|
|
"""Set up things to be run when tests are started."""
|
|
self.hass = get_test_home_assistant()
|
|
self.main_zone = _create_zone_mock('Main zone', 'http://main')
|
|
self.device = FakeYamahaDevice(
|
|
'http://receiver', 'Receiver', zones=[self.main_zone])
|
|
|
|
def tearDown(self):
|
|
"""Stop everything that was started."""
|
|
self.hass.stop()
|
|
|
|
def enable_output(self, port, enabled):
|
|
"""Enable output on a specific port."""
|
|
data = {
|
|
'entity_id': 'media_player.yamaha_receiver_main_zone',
|
|
'port': port,
|
|
'enabled': enabled
|
|
}
|
|
|
|
self.hass.services.call(yamaha.DOMAIN,
|
|
yamaha.SERVICE_ENABLE_OUTPUT,
|
|
data,
|
|
True)
|
|
|
|
def create_receiver(self, mock_rxv):
|
|
"""Create a mocked receiver."""
|
|
mock_rxv.return_value = self.device
|
|
|
|
config = {
|
|
'media_player': {
|
|
'platform': 'yamaha',
|
|
'host': '127.0.0.1'
|
|
}
|
|
}
|
|
|
|
assert setup_component(self.hass, mp.DOMAIN, config)
|
|
|
|
@patch('rxv.RXV')
|
|
def test_enable_output(self, mock_rxv):
|
|
"""Test enabling and disabling outputs."""
|
|
self.create_receiver(mock_rxv)
|
|
|
|
self.enable_output('hdmi1', True)
|
|
self.main_zone.enable_output.assert_called_with('hdmi1', True)
|
|
|
|
self.enable_output('hdmi2', False)
|
|
self.main_zone.enable_output.assert_called_with('hdmi2', False)
|