desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Test the mean sensor.'
| def test_mean_sensor(self):
| config = {'sensor': {'platform': 'min_max', 'name': 'test_mean', 'type': 'mean', 'entity_ids': ['sensor.test_1', 'sensor.test_2', 'sensor.test_3']}}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
for (entity_id, value) in dict(zip(entity_ids, self.values)).items():
self.hass.states.set(entity_id, value)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_mean')
self.assertEqual(str(float(self.mean)), state.state)
self.assertEqual(self.min, state.attributes.get('min_value'))
self.assertEqual(self.max, state.attributes.get('max_value'))
|
'Test the mean with 1-digit precision sensor.'
| def test_mean_1_digit_sensor(self):
| config = {'sensor': {'platform': 'min_max', 'name': 'test_mean', 'type': 'mean', 'round_digits': 1, 'entity_ids': ['sensor.test_1', 'sensor.test_2', 'sensor.test_3']}}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
for (entity_id, value) in dict(zip(entity_ids, self.values)).items():
self.hass.states.set(entity_id, value)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_mean')
self.assertEqual(str(float(self.mean_1_digit)), state.state)
self.assertEqual(self.min, state.attributes.get('min_value'))
self.assertEqual(self.max, state.attributes.get('max_value'))
|
'Test the mean with 1-digit precision sensor.'
| def test_mean_4_digit_sensor(self):
| config = {'sensor': {'platform': 'min_max', 'name': 'test_mean', 'type': 'mean', 'round_digits': 4, 'entity_ids': ['sensor.test_1', 'sensor.test_2', 'sensor.test_3']}}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
for (entity_id, value) in dict(zip(entity_ids, self.values)).items():
self.hass.states.set(entity_id, value)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_mean')
self.assertEqual(str(float(self.mean_4_digits)), state.state)
self.assertEqual(self.min, state.attributes.get('min_value'))
self.assertEqual(self.max, state.attributes.get('max_value'))
|
'Test that there is nothing done if not enough values available.'
| def test_not_enough_sensor_value(self):
| config = {'sensor': {'platform': 'min_max', 'name': 'test_max', 'type': 'max', 'entity_ids': ['sensor.test_1', 'sensor.test_2', 'sensor.test_3']}}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
self.hass.states.set(entity_ids[0], STATE_UNKNOWN)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_max')
self.assertEqual(STATE_UNKNOWN, state.state)
self.hass.states.set(entity_ids[1], self.values[1])
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_max')
self.assertNotEqual(STATE_UNKNOWN, state.state)
self.hass.states.set(entity_ids[2], STATE_UNKNOWN)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_max')
self.assertNotEqual(STATE_UNKNOWN, state.state)
self.hass.states.set(entity_ids[1], STATE_UNKNOWN)
self.hass.block_till_done()
state = self.hass.states.get('sensor.test_max')
self.assertEqual(STATE_UNKNOWN, state.state)
|
'Test for different unit of measurement.'
| def test_different_unit_of_measurement(self):
| config = {'sensor': {'platform': 'min_max', 'name': 'test', 'type': 'mean', 'entity_ids': ['sensor.test_1', 'sensor.test_2', 'sensor.test_3']}}
assert setup_component(self.hass, 'sensor', config)
entity_ids = config['sensor']['entity_ids']
self.hass.states.set(entity_ids[0], self.values[0], {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS})
self.hass.block_till_done()
state = self.hass.states.get('sensor.test')
self.assertEqual(str(float(self.values[0])), state.state)
self.assertEqual('\xc2\xb0C', state.attributes.get('unit_of_measurement'))
self.hass.states.set(entity_ids[1], self.values[1], {ATTR_UNIT_OF_MEASUREMENT: TEMP_FAHRENHEIT})
self.hass.block_till_done()
state = self.hass.states.get('sensor.test')
self.assertEqual(STATE_UNKNOWN, state.state)
self.assertEqual('ERR', state.attributes.get('unit_of_measurement'))
self.hass.states.set(entity_ids[2], self.values[2], {ATTR_UNIT_OF_MEASUREMENT: '%'})
self.hass.block_till_done()
state = self.hass.states.get('sensor.test')
self.assertEqual(STATE_UNKNOWN, state.state)
self.assertEqual('ERR', state.attributes.get('unit_of_measurement'))
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test sensor setup.'
| def test_setup(self):
| config = {'name': 'Test', 'unit_of_measurement': 'in', 'command': 'echo 5'}
devices = []
def add_dev_callback(devs, update):
'Add callback to add devices.'
for dev in devs:
devices.append(dev)
command_line.setup_platform(self.hass, config, add_dev_callback)
self.assertEqual(1, len(devices))
entity = devices[0]
entity.update()
self.assertEqual('Test', entity.name)
self.assertEqual('in', entity.unit_of_measurement)
self.assertEqual('5', entity.state)
|
'Test setup with a bad configuration.'
| def test_setup_bad_config(self):
| config = {'name': 'test', 'platform': 'not_command_line'}
self.assertFalse(setup.setup_component(self.hass, 'test', {'command_line': config}))
|
'Test command sensor with template.'
| def test_template(self):
| data = command_line.CommandSensorData('echo 50')
entity = command_line.CommandSensor(self.hass, data, 'test', 'in', Template('{{ value | multiply(0.1) }}', self.hass))
entity.update()
self.assertEqual(5, float(entity.state))
|
'Test bad command.'
| def test_bad_command(self):
| data = command_line.CommandSensorData('asdfasdf')
data.update()
self.assertEqual(None, data.value)
|
'Setup things to be run when tests are started.'
| def setup_method(self, method):
| self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {sensor.DOMAIN: {CONF_PLATFORM: 'mqtt_room', CONF_NAME: NAME, CONF_DEVICE_ID: DEVICE_ID, CONF_STATE_TOPIC: 'room_presence', CONF_QOS: DEFAULT_QOS, CONF_TIMEOUT: 5}}))
self.hass.states.set(SENSOR_STATE, None)
|
'Stop everything that was started.'
| def teardown_method(self, method):
| self.hass.stop()
|
'Test the sending of a message.'
| def send_message(self, topic, message):
| fire_mqtt_message(self.hass, topic, json.dumps(message))
self.hass.block_till_done()
|
'Test the assertion of a room state.'
| def assert_state(self, room):
| state = self.hass.states.get(SENSOR_STATE)
self.assertEqual(state.state, room)
|
'Test the assertion of a distance state.'
| def assert_distance(self, distance):
| state = self.hass.states.get(SENSOR_STATE)
self.assertEqual(state.attributes.get('distance'), distance)
|
'Test the updating between rooms.'
| def test_room_update(self):
| self.send_message(BEDROOM_TOPIC, FAR_MESSAGE)
self.assert_state(BEDROOM)
self.assert_distance(10)
self.send_message(LIVING_ROOM_TOPIC, NEAR_MESSAGE)
self.assert_state(LIVING_ROOM)
self.assert_distance(1)
self.send_message(BEDROOM_TOPIC, FAR_MESSAGE)
self.assert_state(LIVING_ROOM)
self.assert_distance(1)
time = (dt.utcnow() + datetime.timedelta(seconds=7))
with patch('homeassistant.helpers.condition.dt_util.utcnow', return_value=time):
self.send_message(BEDROOM_TOPIC, FAR_MESSAGE)
self.assert_state(BEDROOM)
self.assert_distance(10)
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test if new entity is created.'
| def test_bad_config(self):
| self.assertFalse(setup_component(self.hass, 'weblink', {'weblink': {'entities': [{}]}}))
|
'Test if new entity is created.'
| def test_entities_get_created(self):
| self.assertTrue(setup_component(self.hass, weblink.DOMAIN, {weblink.DOMAIN: {'entities': [{weblink.CONF_NAME: 'My router', weblink.CONF_URL: 'http://127.0.0.1/'}]}}))
state = self.hass.states.get('weblink.my_router')
assert (state is not None)
assert (state.state == 'http://127.0.0.1/')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.hass = get_test_home_assistant()
self.config = {rc.DOMAIN: {'test_get': {'url': 'http://example.com/'}}}
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Test setup component.'
| def test_setup_component(self):
| with assert_setup_component(1):
setup_component(self.hass, rc.DOMAIN, self.config)
|
'Test setup component timeout.'
| def test_setup_component_timeout(self):
| self.config[rc.DOMAIN]['test_get']['timeout'] = 10
with assert_setup_component(1):
setup_component(self.hass, rc.DOMAIN, self.config)
|
'Test setup component and check if service exits.'
| def test_setup_component_test_service(self):
| with assert_setup_component(1):
setup_component(self.hass, rc.DOMAIN, self.config)
assert self.hass.services.has_service(rc.DOMAIN, 'test_get')
|
'Setup things to be run when tests are started.'
| def setup_method(self):
| self.url = 'https://example.com/'
self.config = {rc.DOMAIN: {'get_test': {'url': self.url, 'method': 'get'}, 'post_test': {'url': self.url, 'method': 'post'}, 'put_test': {'url': self.url, 'method': 'put'}, 'delete_test': {'url': self.url, 'method': 'delete'}}}
self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def teardown_method(self):
| self.hass.stop()
|
'Setup test config and test it.'
| def test_setup_tests(self):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
assert self.hass.services.has_service(rc.DOMAIN, 'get_test')
assert self.hass.services.has_service(rc.DOMAIN, 'post_test')
assert self.hass.services.has_service(rc.DOMAIN, 'put_test')
assert self.hass.services.has_service(rc.DOMAIN, 'delete_test')
|
'Call a rest command with timeout.'
| def test_rest_command_timeout(self, aioclient_mock):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.get(self.url, exc=asyncio.TimeoutError())
self.hass.services.call(rc.DOMAIN, 'get_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with aiohttp exception.'
| def test_rest_command_aiohttp_error(self, aioclient_mock):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.get(self.url, exc=aiohttp.ClientError())
self.hass.services.call(rc.DOMAIN, 'get_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with status code 400.'
| def test_rest_command_http_error(self, aioclient_mock):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.get(self.url, status=400)
self.hass.services.call(rc.DOMAIN, 'get_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with auth credential.'
| def test_rest_command_auth(self, aioclient_mock):
| data = {'username': 'test', 'password': '123456'}
self.config[rc.DOMAIN]['get_test'].update(data)
with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.get(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'get_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with post form data.'
| def test_rest_command_form_data(self, aioclient_mock):
| data = {'payload': 'test'}
self.config[rc.DOMAIN]['post_test'].update(data)
with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.post(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'post_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
assert (aioclient_mock.mock_calls[0][2] == 'test')
|
'Call a rest command with get.'
| def test_rest_command_get(self, aioclient_mock):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.get(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'get_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with delete.'
| def test_rest_command_delete(self, aioclient_mock):
| with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.delete(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'delete_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
|
'Call a rest command with post.'
| def test_rest_command_post(self, aioclient_mock):
| data = {'payload': 'data'}
self.config[rc.DOMAIN]['post_test'].update(data)
with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.post(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'post_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
assert (aioclient_mock.mock_calls[0][2] == 'data')
|
'Call a rest command with put.'
| def test_rest_command_put(self, aioclient_mock):
| data = {'payload': 'data'}
self.config[rc.DOMAIN]['put_test'].update(data)
with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.put(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'put_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
assert (aioclient_mock.mock_calls[0][2] == 'data')
|
'Call a rest command with a content type.'
| def test_rest_command_content_type(self, aioclient_mock):
| data = {'payload': 'item', 'content_type': 'text/plain'}
self.config[rc.DOMAIN]['post_test'].update(data)
with assert_setup_component(4):
setup_component(self.hass, rc.DOMAIN, self.config)
aioclient_mock.post(self.url, content='success')
self.hass.services.call(rc.DOMAIN, 'post_test', {})
self.hass.block_till_done()
assert (len(aioclient_mock.mock_calls) == 1)
assert (aioclient_mock.mock_calls[0][2] == 'item')
|
'Initialize the fake Chrome Cast.'
| def __init__(self, host, port):
| self.host = host
self.port = port
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
|
'Stop everything that was started.'
| def tearDown(self):
| self.hass.stop()
|
'Test filtering of duplicates.'
| @patch('homeassistant.components.media_player.cast.CastDevice')
@patch('pychromecast.get_chromecasts')
def test_filter_duplicates(self, mock_get_chromecasts, mock_device):
| mock_get_chromecasts.return_value = [FakeChromeCast('some_host', cast.DEFAULT_PORT)]
cast.setup_platform(self.hass, {'host': 'some_host'}, (lambda _: _))
assert mock_device.called
mock_device.reset_mock()
assert (not mock_device.called)
cast.setup_platform(self.hass, {}, (lambda _: _), {'host': 'some_host', 'port': cast.DEFAULT_PORT})
assert (not mock_device.called)
|
'Test falling back to creating Chromecast when not discovered.'
| @patch('homeassistant.components.media_player.cast.CastDevice')
@patch('pychromecast.get_chromecasts')
@patch('pychromecast.Chromecast')
def test_fallback_cast(self, mock_chromecast, mock_get_chromecasts, mock_device):
| mock_get_chromecasts.return_value = [FakeChromeCast('some_host', cast.DEFAULT_PORT)]
cast.setup_platform(self.hass, {'host': 'some_other_host'}, (lambda _: _))
assert mock_chromecast.called
assert mock_device.called
|
'Test not creating Cast Group when not discovered.'
| @patch('homeassistant.components.media_player.cast.CastDevice')
@patch('pychromecast.get_chromecasts')
@patch('pychromecast.Chromecast')
def test_fallback_cast_group(self, mock_chromecast, mock_get_chromecasts, mock_device):
| mock_get_chromecasts.return_value = [FakeChromeCast('some_host', cast.DEFAULT_PORT)]
cast.setup_platform(self.hass, {}, (lambda _: _), {'host': 'some_other_host', 'port': 43546})
assert (not mock_chromecast.called)
assert (not mock_device.called)
|
'Create a new service.'
| def __init__(self, master, slaves):
| self.data = {'master': master, 'slaves': slaves}
|
'Init the class.'
| def __init__(self):
| self._config = MockConfig
|
'Init class.'
| def __init__(self):
| self._name = 'name'
|
'Init the class.'
| def __init__(self, id):
| self._id = id
self._name = 'preset'
|
'Init class.'
| def __init__(self):
| self._actual = 12
|
'Init the class.'
| def __init__(self):
| self._actual = 12
self._muted = True
|
'Init the class.'
| def __init__(self):
| self._source = 'STANDBY'
|
'Init the class.'
| def __init__(self):
| self._source = ''
self._play_status = 'PLAY_STATE'
self._image = 'image.url'
self._artist = 'artist'
self._track = 'track'
self._album = 'album'
self._duration = 1
self._station_name = None
|
'Init the class.'
| def __init__(self):
| self._source = ''
self._play_status = 'PLAY_STATE'
self._image = 'image.url'
self._artist = None
self._track = None
self._album = None
self._duration = None
self._station_name = 'station'
|
'Init the class.'
| def __init__(self):
| self._source = ''
self._play_status = 'PLAY_STATE'
self._image = 'image.url'
self._artist = None
self._track = None
self._album = None
self._duration = None
self._station_name = None
|
'Init the class.'
| def __init__(self):
| self._source = ''
self._play_status = 'PAUSE_STATE'
|
'Setup things to be run when tests are started.'
| def setUp(self):
| self.hass = get_test_home_assistant()
logging.disable(logging.CRITICAL)
|
'Stop everything that was started.'
| def tearDown(self):
| logging.disable(logging.NOTSET)
self.hass.stop()
|
'Test setup OK with custom config.'
| @mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
def test_ensure_setup_config(self, mocked_sountouch_device):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(len(all_devices), 1)
self.assertEqual(all_devices[0].name, 'soundtouch')
self.assertEqual(all_devices[0].config['port'], 8090)
self.assertEqual(mocked_sountouch_device.call_count, 1)
|
'Test setup with discovery.'
| @mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
def test_ensure_setup_discovery(self, mocked_sountouch_device):
| new_device = {'port': '8090', 'host': '192.168.1.1', 'properties': {}, 'hostname': 'hostname.local'}
soundtouch.setup_platform(self.hass, None, mock.MagicMock(), new_device)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(len(all_devices), 1)
self.assertEqual(all_devices[0].config['port'], 8090)
self.assertEqual(all_devices[0].config['host'], '192.168.1.1')
self.assertEqual(mocked_sountouch_device.call_count, 1)
|
'Test setup OK if device already exists.'
| @mock.patch('libsoundtouch.soundtouch_device', side_effect=None)
def test_ensure_setup_discovery_no_duplicate(self, mocked_sountouch_device):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 1)
new_device = {'port': '8090', 'host': '192.168.1.1', 'properties': {}, 'hostname': 'hostname.local'}
soundtouch.setup_platform(self.hass, None, mock.MagicMock(), new_device)
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 2)
existing_device = {'port': '8090', 'host': '192.168.0.1', 'properties': {}, 'hostname': 'hostname.local'}
soundtouch.setup_platform(self.hass, None, mock.MagicMock(), existing_device)
self.assertEqual(mocked_sountouch_device.call_count, 2)
self.assertEqual(len(self.hass.data[soundtouch.DATA_SOUNDTOUCH]), 2)
|
'Test update device state.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_update(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
self.hass.data[soundtouch.DATA_SOUNDTOUCH][0].update()
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 2)
|
'Test playing media info.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status', side_effect=MockStatusPlaying)
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_playing_media(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].state, STATE_PLAYING)
self.assertEqual(all_devices[0].media_image_url, 'image.url')
self.assertEqual(all_devices[0].media_title, 'artist - track')
self.assertEqual(all_devices[0].media_track, 'track')
self.assertEqual(all_devices[0].media_artist, 'artist')
self.assertEqual(all_devices[0].media_album_name, 'album')
self.assertEqual(all_devices[0].media_duration, 1)
|
'Test playing media info.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status', side_effect=MockStatusUnknown)
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_playing_unknown_media(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].media_title, None)
|
'Test playing radio info.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status', side_effect=MockStatusPlayingRadio)
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_playing_radio(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].state, STATE_PLAYING)
self.assertEqual(all_devices[0].media_image_url, 'image.url')
self.assertEqual(all_devices[0].media_title, 'station')
self.assertEqual(all_devices[0].media_track, None)
self.assertEqual(all_devices[0].media_artist, None)
self.assertEqual(all_devices[0].media_album_name, None)
self.assertEqual(all_devices[0].media_duration, None)
|
'Test volume level.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume', side_effect=MockVolume)
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_get_volume_level(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].volume_level, 0.12)
|
'Test state device is off.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status', side_effect=MockStatusStandby)
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_get_state_off(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].state, STATE_OFF)
|
'Test state device is paused.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status', side_effect=MockStatusPause)
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_get_state_pause(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].state, STATE_PAUSED)
|
'Test device volume is muted.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume', side_effect=MockVolumeMuted)
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_is_muted(self, mocked_sountouch_device, mocked_status, mocked_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].is_volume_muted, True)
|
'Test supported media commands.'
| @mock.patch('libsoundtouch.soundtouch_device')
def test_media_commands(self, mocked_sountouch_device):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(all_devices[0].supported_features, 17853)
|
'Test device is turned off.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.power_off')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_should_turn_off(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_power_off):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].turn_off()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 1)
self.assertEqual(mocked_power_off.call_count, 1)
|
'Test device is turned on.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.power_on')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_should_turn_on(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_power_on):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].turn_on()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 1)
self.assertEqual(mocked_power_on.call_count, 1)
|
'Test volume up.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume_up')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_volume_up(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_volume_up):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].volume_up()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 2)
self.assertEqual(mocked_volume_up.call_count, 1)
|
'Test volume down.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.volume_down')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_volume_down(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_volume_down):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].volume_down()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 2)
self.assertEqual(mocked_volume_down.call_count, 1)
|
'Test set volume level.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.set_volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_set_volume_level(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_set_volume):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].set_volume_level(0.17)
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 2)
mocked_set_volume.assert_called_with(17)
|
'Test mute volume.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.mute')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_mute(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_mute):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].mute_volume(None)
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 2)
self.assertEqual(mocked_mute.call_count, 1)
|
'Test play command.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.play')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_play(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_play):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].media_play()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 1)
self.assertEqual(mocked_play.call_count, 1)
|
'Test pause command.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.pause')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_pause(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_pause):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].media_pause()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 1)
self.assertEqual(mocked_pause.call_count, 1)
|
'Test play/pause.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.play_pause')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_play_pause_play(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_play_pause):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].media_play_pause()
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 1)
self.assertEqual(mocked_play_pause.call_count, 1)
|
'Test next/previous track.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.previous_track')
@mock.patch('libsoundtouch.device.SoundTouchDevice.next_track')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_next_previous_track(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_next_track, mocked_previous_track):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices[0].media_next_track()
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_next_track.call_count, 1)
all_devices[0].media_previous_track()
self.assertEqual(mocked_status.call_count, 3)
self.assertEqual(mocked_previous_track.call_count, 1)
|
'Test play preset 1.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.select_preset')
@mock.patch('libsoundtouch.device.SoundTouchDevice.presets', side_effect=_mocked_presets)
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_play_media(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_presets, mocked_select_preset):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices[0].play_media('PLAYLIST', 1)
self.assertEqual(mocked_presets.call_count, 1)
self.assertEqual(mocked_select_preset.call_count, 1)
all_devices[0].play_media('PLAYLIST', 2)
self.assertEqual(mocked_presets.call_count, 2)
self.assertEqual(mocked_select_preset.call_count, 1)
|
'Test play preset 1.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.play_url')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_play_media_url(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_play_url):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(mocked_status.call_count, 1)
self.assertEqual(mocked_volume.call_count, 1)
all_devices[0].play_media('MUSIC', 'http://fqdn/file.mp3')
mocked_play_url.assert_called_with('http://fqdn/file.mp3')
|
'Test play everywhere.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.create_zone')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_play_everywhere(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_create_zone):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].entity_id = 'media_player.entity_1'
all_devices[1].entity_id = 'media_player.entity_2'
self.assertEqual(mocked_sountouch_device.call_count, 2)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 2)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_PLAY_EVERYWHERE, {'master': 'media_player.entity_1'}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_PLAY_EVERYWHERE, {'master': 'media_player.entity_X'}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
all_devices.pop(1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_PLAY_EVERYWHERE, {'master': 'media_player.entity_1'}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
|
'Test creating a zone.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.create_zone')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_create_zone(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_create_zone):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].entity_id = 'media_player.entity_1'
all_devices[1].entity_id = 'media_player.entity_2'
self.assertEqual(mocked_sountouch_device.call_count, 2)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 2)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_CREATE_ZONE, {'master': 'media_player.entity_1', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_CREATE_ZONE, {'master': 'media_player.entity_X', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_CREATE_ZONE, {'master': 'media_player.entity_X', 'slaves': []}, True)
self.assertEqual(mocked_create_zone.call_count, 1)
|
'Test adding a slave to an existing zone.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.remove_zone_slave')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_remove_zone_slave(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_remove_zone_slave):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].entity_id = 'media_player.entity_1'
all_devices[1].entity_id = 'media_player.entity_2'
self.assertEqual(mocked_sountouch_device.call_count, 2)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 2)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_REMOVE_ZONE_SLAVE, {'master': 'media_player.entity_1', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_REMOVE_ZONE_SLAVE, {'master': 'media_player.entity_X', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_REMOVE_ZONE_SLAVE, {'master': 'media_player.entity_1', 'slaves': []}, True)
self.assertEqual(mocked_remove_zone_slave.call_count, 1)
|
'Test removing a slave from a zone.'
| @mock.patch('libsoundtouch.device.SoundTouchDevice.add_zone_slave')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
@mock.patch('libsoundtouch.device.SoundTouchDevice.status')
@mock.patch('libsoundtouch.soundtouch_device', side_effect=_mock_soundtouch_device)
def test_add_zone_slave(self, mocked_sountouch_device, mocked_status, mocked_volume, mocked_add_zone_slave):
| soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
soundtouch.setup_platform(self.hass, default_component(), mock.MagicMock())
all_devices = self.hass.data[soundtouch.DATA_SOUNDTOUCH]
all_devices[0].entity_id = 'media_player.entity_1'
all_devices[1].entity_id = 'media_player.entity_2'
self.assertEqual(mocked_sountouch_device.call_count, 2)
self.assertEqual(mocked_status.call_count, 2)
self.assertEqual(mocked_volume.call_count, 2)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_ADD_ZONE_SLAVE, {'master': 'media_player.entity_1', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_add_zone_slave.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_ADD_ZONE_SLAVE, {'master': 'media_player.entity_X', 'slaves': ['media_player.entity_2']}, True)
self.assertEqual(mocked_add_zone_slave.call_count, 1)
self.hass.services.call(soundtouch.DOMAIN, soundtouch.SERVICE_ADD_ZONE_SLAVE, {'master': 'media_player.entity_1', 'slaves': ['media_player.entity_X']}, True)
self.assertEqual(mocked_add_zone_slave.call_count, 1)
|
'Fake the discovery feature.'
| def _discover_features(self):
| self._desc_xml = ET.fromstring(sample_content('desc.xml'))
|
'A fake input for the reciever.'
| @property
def input(self):
| return self._fake_input
|
'Set the input for the fake receiver.'
| @input.setter
def input(self, input_name):
| assert (input_name in self.inputs())
self._fake_input = input_name
|
'All inputs of the the fake receiver.'
| def inputs(self):
| return {'AUDIO1': None, 'AUDIO2': None, 'AV1': None, 'AV2': None, 'AV3': None, 'AV4': None, 'AV5': None, 'AV6': None, 'AirPlay': 'AirPlay', 'HDMI1': None, 'HDMI2': None, 'HDMI3': None, 'HDMI4': None, 'HDMI5': None, 'NET RADIO': 'NET_RADIO', 'Pandora': 'Pandora', 'Rhapsody': 'Rhapsody', 'SERVER': 'SERVER', 'SiriusXM': 'SiriusXM', 'Spotify': 'Spotify', 'TUNER': 'Tuner', 'USB': 'USB', 'V-AUX': None, 'iPod (USB)': 'iPod_USB'}
|
'Setup things to be run when tests are started.'
| def setUp(self):
| super(TestYamaha, self).setUp()
self.rec = FakeYamaha('http://10.0.0.0:80/YamahaRemoteControl/ctrl')
|
'Test the playback.'
| def test_get_playback_support(self):
| rec = self.rec
support = rec.get_playback_support()
self.assertFalse(support.play)
self.assertFalse(support.pause)
self.assertFalse(support.stop)
self.assertFalse(support.skip_f)
self.assertFalse(support.skip_r)
rec.input = 'NET RADIO'
support = rec.get_playback_support()
self.assertTrue(support.play)
self.assertFalse(support.pause)
self.assertTrue(support.stop)
self.assertFalse(support.skip_f)
self.assertFalse(support.skip_r)
|
'Initialize the media player.'
| def __init__(self, hass, name):
| 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
self._supported_features = 0
self._source = None
self._tracks = 12
self._media_image_url = None
self._shuffle = False
self.service_calls = {'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)}
|
'Return the name of player.'
| @property
def name(self):
| return self._name
|
'Return the state of the player.'
| @property
def state(self):
| return self._state
|
'The volume level of player.'
| @property
def volume_level(self):
| return self._volume_level
|
'Return true if the media player is muted.'
| @property
def is_volume_muted(self):
| return self._is_volume_muted
|
'Flag media player features that are supported.'
| @property
def supported_features(self):
| return self._supported_features
|
'Image url of current playing media.'
| @property
def media_image_url(self):
| return self._media_image_url
|
'Return true if the media player is shuffling.'
| @property
def shuffle(self):
| return self._shuffle
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.