def test_supported_media_commands_children_and_cmds(self):
        """ test supported media commands with children and attrs """
        config = self.config_children_and_attr
        universal.validate_config(config)
        config["commands"]["turn_on"] = "test"
        config["commands"]["turn_off"] = "test"
        config["commands"]["volume_up"] = "test"
        config["commands"]["volume_down"] = "test"
        config["commands"]["volume_mute"] = "test"

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
        ump.update()

        self.mock_mp_1._supported_media_commands = universal.SUPPORT_VOLUME_SET
        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()

        check_flags = (
            universal.SUPPORT_TURN_ON
            | universal.SUPPORT_TURN_OFF
            | universal.SUPPORT_VOLUME_STEP
            | universal.SUPPORT_VOLUME_MUTE
        )

        self.assertEqual(check_flags, ump.supported_media_commands)
    def test_active_child_state(self):
        """Test active child state property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(None, ump._child_state)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_2.entity_id,
                         ump._child_state.entity_id)
    def test_supported_features_children_and_cmds(self):
        """Test supported media commands with children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)
        config['commands']['turn_on'] = 'test'
        config['commands']['turn_off'] = 'test'
        config['commands']['volume_up'] = 'test'
        config['commands']['volume_down'] = 'test'
        config['commands']['volume_mute'] = 'test'
        config['commands']['volume_set'] = 'test'
        config['commands']['select_source'] = 'test'
        config['commands']['shuffle_set'] = 'test'

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        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

        self.assertEqual(check_flags, ump.supported_features)
    def test_active_child_state(self):
        """Test active child state property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertEqual(None, ump._child_state)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_1.entity_id, ump._child_state.entity_id)

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_1.entity_id, ump._child_state.entity_id)

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_2.entity_id, ump._child_state.entity_id)
    def test_active_child_state(self):
        """ test active child state property """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(None, ump._child_state)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(self.mock_mp_2.entity_id,
                         ump._child_state.entity_id)
    def test_supported_features_children_and_cmds(self):
        """Test supported media commands with children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)
        config['commands']['turn_on'] = 'test'
        config['commands']['turn_off'] = 'test'
        config['commands']['volume_up'] = 'test'
        config['commands']['volume_down'] = 'test'
        config['commands']['volume_mute'] = 'test'
        config['commands']['volume_set'] = 'test'
        config['commands']['select_source'] = 'test'
        config['commands']['shuffle_set'] = 'test'

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        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

        self.assertEqual(check_flags, ump.supported_features)
    def test_supported_media_commands_children_and_cmds(self):
        """Test supported media commands with children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)
        config['commands']['turn_on'] = 'test'
        config['commands']['turn_off'] = 'test'
        config['commands']['volume_up'] = 'test'
        config['commands']['volume_down'] = 'test'
        config['commands']['volume_mute'] = 'test'
        config['commands']['volume_set'] = 'test'
        config['commands']['select_source'] = 'test'

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()

        check_flags = universal.SUPPORT_TURN_ON | universal.SUPPORT_TURN_OFF \
            | universal.SUPPORT_VOLUME_STEP | universal.SUPPORT_VOLUME_MUTE \
            | universal.SUPPORT_SELECT_SOURCE

        self.assertEqual(check_flags, ump.supported_media_commands)
    def test_active_child_state(self):
        """Test active child state property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertEqual(None, ump._child_state)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_1.entity_id,
                         ump._child_state.entity_id)

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(self.mock_mp_2.entity_id,
                         ump._child_state.entity_id)
    def test_service_call_to_child(self):
        """Test service calls that should be routed to a child."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_off']))

        ump.turn_on()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_on']))

        ump.mute_volume(True)
        self.assertEqual(1, len(self.mock_mp_2.service_calls['mute_volume']))

        ump.set_volume_level(0.5)
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['set_volume_level']))

        ump.media_play()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_play']))

        ump.media_pause()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_pause']))

        ump.media_previous_track()
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['media_previous_track']))

        ump.media_next_track()
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['media_next_track']))

        ump.media_seek(100)
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_seek']))

        ump.play_media('movie', 'batman')
        self.assertEqual(1, len(self.mock_mp_2.service_calls['play_media']))

        ump.volume_up()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_up']))

        ump.volume_down()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_down']))

        ump.media_play_pause()
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['media_play_pause']))

        ump.select_source('dvd')
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['select_source']))
    def test_master_state(self):
        """Test master state property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(None, ump.master_state)
    def test_name(self):
        """ test name property """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(config['name'], ump.name)
    def test_name(self):
        """Test name property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(config['name'], ump.name)
    def test_polling(self):
        """Test should_poll property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(False, ump.should_poll)
    def test_master_state(self):
        """ test master state property """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(None, ump.master_state)
Exemple #15
0
    def test_service_call_to_child(self):
        """Test service calls that should be routed to a child."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_off']))

        ump.turn_on()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['turn_on']))

        ump.mute_volume(True)
        self.assertEqual(1, len(self.mock_mp_2.service_calls['mute_volume']))

        ump.set_volume_level(0.5)
        self.assertEqual(1,
                         len(self.mock_mp_2.service_calls['set_volume_level']))

        ump.media_play()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_play']))

        ump.media_pause()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_pause']))

        ump.media_previous_track()
        self.assertEqual(
            1, len(self.mock_mp_2.service_calls['media_previous_track']))

        ump.media_next_track()
        self.assertEqual(1,
                         len(self.mock_mp_2.service_calls['media_next_track']))

        ump.media_seek(100)
        self.assertEqual(1, len(self.mock_mp_2.service_calls['media_seek']))

        ump.play_media('movie', 'batman')
        self.assertEqual(1, len(self.mock_mp_2.service_calls['play_media']))

        ump.volume_up()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_up']))

        ump.volume_down()
        self.assertEqual(1, len(self.mock_mp_2.service_calls['volume_down']))

        ump.media_play_pause()
        self.assertEqual(1,
                         len(self.mock_mp_2.service_calls['media_play_pause']))

        ump.select_source('dvd')
        self.assertEqual(1, len(self.mock_mp_2.service_calls['select_source']))
    def test_master_state_with_bad_attrs(self):
        """Test master state property."""
        config = self.config_children_and_attr
        config['attributes']['state'] = 'bad.entity_id'
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(STATE_OFF, ump.master_state)
    def test_master_state_with_bad_attrs(self):
        """ test master state property """
        config = self.config_children_and_attr
        config['attributes']['state'] = 'bad.entity_id'
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(STATE_OFF, ump.master_state)
    def test_master_state_with_attrs(self):
        """Test master state property."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual(STATE_OFF, ump.master_state)
        self.hass.states.set(self.mock_state_switch_id, STATE_ON)
        self.assertEqual(STATE_ON, ump.master_state)
    def test_source_children_and_attr(self):
        """Test source property w/ children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual('dvd', ump.source)

        self.hass.states.set(self.mock_source_id, 'htpc')
        self.assertEqual('htpc', ump.source)
    def test_volume_level_children_and_attr(self):
        """Test volume level property w/ children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual('0', ump.volume_level)

        self.hass.states.set(self.mock_volume_id, 100)
        self.assertEqual('100', ump.volume_level)
    def test_is_volume_muted_children_and_attr(self):
        """ test is volume muted property w/ children and attrs """
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertFalse(ump.is_volume_muted)

        self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
        self.assertTrue(ump.is_volume_muted)
    def test_source_children_and_attr(self):
        """Test source property w/ children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual('dvd', ump.source)

        self.hass.states.set(self.mock_source_id, 'htpc')
        self.assertEqual('htpc', ump.source)
    def test_volume_level_children_and_attr(self):
        """Test volume level property w/ children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertEqual('0', ump.volume_level)

        self.hass.states.set(self.mock_volume_id, 100)
        self.assertEqual('100', ump.volume_level)
    def test_is_volume_muted_children_and_attr(self):
        """Test is volume muted property w/ children and attrs."""
        config = self.config_children_and_attr
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)

        self.assertFalse(ump.is_volume_muted)

        self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
        self.assertTrue(ump.is_volume_muted)
    def test_check_config_bad_children(self):
        """ Check config with bad children entry """
        config_no_children = {"name": "test", "platform": "universal"}
        config_bad_children = {"name": "test", "children": {}, "platform": "universal"}

        response = universal.validate_config(config_no_children)
        self.assertTrue(response)
        self.assertEqual([], config_no_children["children"])

        response = universal.validate_config(config_bad_children)
        self.assertTrue(response)
        self.assertEqual([], config_bad_children["children"])
    def test_check_config_bad_children(self):
        """ Check config with bad children entry """
        config_no_children = {'name': 'test', 'platform': 'universal'}
        config_bad_children = {'name': 'test', 'children': {},
                               'platform': 'universal'}

        response = universal.validate_config(config_no_children)
        self.assertTrue(response)
        self.assertEqual([], config_no_children['children'])

        response = universal.validate_config(config_bad_children)
        self.assertTrue(response)
        self.assertEqual([], config_bad_children['children'])
    def test_config_bad_children(self):
        """Check config with bad children entry."""
        config_no_children = {'name': 'test', 'platform': 'universal'}
        config_bad_children = {'name': 'test', 'children': {},
                               'platform': 'universal'}

        response = universal.validate_config(config_no_children)
        self.assertTrue(response)
        self.assertEqual([], config_no_children['children'])

        response = universal.validate_config(config_bad_children)
        self.assertTrue(response)
        self.assertEqual([], config_bad_children['children'])
    def test_state_children_only(self):
        """Test media player state with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertTrue(ump.state, STATE_OFF)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(STATE_PLAYING, ump.state)
Exemple #29
0
    def test_service_call_to_child(self):
        """ test a service call that should be routed to a child """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(self.mock_mp_2.turn_off_service_calls))
    def test_state_children_only(self):
        """Test media player state with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertTrue(ump.state, STATE_OFF)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(STATE_PLAYING, ump.state)
    def test_state_children_only(self):
        """ test media player state with only children """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertTrue(ump.state, STATE_OFF)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(STATE_PLAYING, ump.state)
    def test_service_call_to_child(self):
        """ test a service call that should be routed to a child """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(self.mock_mp_2.turn_off_service_calls))
Exemple #33
0
    def test_supported_features_children_only(self):
        """Test supported media commands with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertEqual(0, ump.supported_features)

        self.mock_mp_1._supported_features = 512
        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(512, ump.supported_features)
    def test_config_bad_key(self):
        """Check config with bad key."""
        config = {'name': 'test', 'asdf': 5, 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertFalse('asdf' in config)
    def test_config_bad_attributes(self):
        """Check config with bad attributes."""
        config = {'name': 'test', 'attributes': [], 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertEqual({}, config['attributes'])
    def test_config_bad_commands(self):
        """Check config with bad commands entry."""
        config = {'name': 'test', 'commands': [], 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertEqual({}, config['commands'])
    def test_supported_media_commands_children_only(self):
        """Test supported media commands with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(0, ump.supported_media_commands)

        self.mock_mp_1._supported_media_commands = 512
        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(512, ump.supported_media_commands)
    def test_check_config_bad_attributes(self):
        """ Check config with bad attributes """
        config = {'name': 'test', 'attributes': [], 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertEqual({}, config['attributes'])
    def test_supported_features_children_only(self):
        """Test supported media commands with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertEqual(0, ump.supported_features)

        self.mock_mp_1._supported_features = 512
        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(512, ump.supported_features)
    def test_check_config_bad_commands(self):
        """ Check config with bad commands entry """
        config = {'name': 'test', 'commands': [], 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertEqual({}, config['commands'])
    def test_check_config_bad_key(self):
        """ check config with bad key """
        config = {"name": "test", "asdf": 5, "platform": "universal"}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertFalse("asdf" in config)
    def test_supported_media_commands_children_only(self):
        """ test supported media commands with only children """
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(0, ump.supported_media_commands)

        self.mock_mp_1._supported_media_commands = 512
        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(512, ump.supported_media_commands)
    def test_check_config_bad_attributes(self):
        """ Check config with bad attributes """
        config = {"name": "test", "attributes": [], "platform": "universal"}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertEqual({}, config["attributes"])
    def test_state_children_only(self):
        """Test media player state with only children."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.assertTrue(ump.state, STATE_OFF)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(STATE_PLAYING, ump.state)
    def test_check_config_bad_key(self):
        """ check config with bad key """
        config = {'name': 'test', 'asdf': 5, 'platform': 'universal'}

        response = universal.validate_config(config)
        self.assertTrue(response)
        self.assertFalse('asdf' in config)
    def test_service_call_to_command(self):
        config = self.config_children_only
        config["commands"] = {"turn_off": {"service": "test.turn_off", "data": {}}}
        universal.validate_config(config)

        service = mock_service(self.hass, "test", "turn_off")

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config["name"])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(service))
    def test_service_call_no_active_child(self):
        """Test a service call to children with no active child."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.update_ha_state()
        self.mock_mp_2._state = STATE_OFF
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(0, len(self.mock_mp_1.service_calls['turn_off']))
        self.assertEqual(0, len(self.mock_mp_2.service_calls['turn_off']))
    def test_service_call_to_command(self):
        config = self.config_children_only
        config['commands'] = \
            {'turn_off': {'service': 'test.turn_off', 'data': {}}}
        universal.validate_config(config)

        service = mock_service(self.hass, 'test', 'turn_off')

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(service))
Exemple #49
0
    def test_service_call_no_active_child(self):
        """Test a service call to children with no active child."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.update_ha_state()
        self.mock_mp_2._state = STATE_OFF
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(0, len(self.mock_mp_1.service_calls['turn_off']))
        self.assertEqual(0, len(self.mock_mp_2.service_calls['turn_off']))
Exemple #50
0
    def test_service_call_to_command(self):
        config = self.config_children_only
        config['commands'] = \
            {'turn_off': {'service': 'test.turn_off', 'data': {}}}
        universal.validate_config(config)

        service = mock_service(self.hass, 'test', 'turn_off')

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.mock_mp_2._state = STATE_PLAYING
        self.mock_mp_2.update_ha_state()
        ump.update()

        ump.turn_off()
        self.assertEqual(1, len(service))
    def test_config_children_and_attr(self):
        """Check config with children and attributes."""
        config_start = copy(self.config_children_and_attr)
        del config_start['platform']
        config_start['commands'] = {}

        response = universal.validate_config(self.config_children_and_attr)

        self.assertTrue(response)
        self.assertEqual(config_start, self.config_children_and_attr)
    def test_check_config_children_and_attr(self):
        """ Check config with children and attributes """
        config_start = copy(self.config_children_and_attr)
        del config_start['platform']
        config_start['commands'] = {}

        response = universal.validate_config(self.config_children_and_attr)

        self.assertTrue(response)
        self.assertEqual(config_start, self.config_children_and_attr)
    def test_media_image_url(self):
        """Test media_image_url property."""
        TEST_URL = "test_url"
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(None, ump.media_image_url)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1._media_image_url = TEST_URL
        self.mock_mp_1.update_ha_state()
        ump.update()
        # 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.
        self.assertEqual(self.mock_mp_1.entity_picture, ump.entity_picture)
    def test_service_call_no_active_child(self):
        """Test a service call to children with no active child."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        self.mock_mp_1._state = STATE_OFF
        self.mock_mp_1.schedule_update_ha_state()
        self.mock_mp_2._state = STATE_OFF
        self.mock_mp_2.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()

        run_coroutine_threadsafe(ump.async_turn_off(), self.hass.loop).result()
        self.assertEqual(0, len(self.mock_mp_1.service_calls['turn_off']))
        self.assertEqual(0, len(self.mock_mp_2.service_calls['turn_off']))
    def test_is_volume_muted_children_only(self):
        """Test is volume muted property w/ children only."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertFalse(ump.is_volume_muted)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertFalse(ump.is_volume_muted)

        self.mock_mp_1._is_volume_muted = True
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertTrue(ump.is_volume_muted)
Exemple #56
0
    def test_check_config_children_only(self):
        """ Check config with only children """
        config_start = copy(self.config_children_only)
        del config_start['platform']
        config_start['commands'] = {}
        config_start['attributes'] = {}

        response = universal.validate_config(self.config_children_only)

        self.assertTrue(response)
        self.assertEqual(config_start, self.config_children_only)
    def test_volume_level(self):
        """Test volume level property."""
        config = self.config_children_only
        universal.validate_config(config)

        ump = universal.UniversalMediaPlayer(self.hass, **config)
        ump.entity_id = media_player.ENTITY_ID_FORMAT.format(config['name'])
        ump.update()

        self.assertEqual(None, ump.volume_level)

        self.mock_mp_1._state = STATE_PLAYING
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(0, ump.volume_level)

        self.mock_mp_1._volume_level = 1
        self.mock_mp_1.update_ha_state()
        ump.update()
        self.assertEqual(1, ump.volume_level)