Пример #1
0
    def test_active_child_state(self):
        """Test active child state property."""
        config = validate_config(self.config_children_only)

        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()

        assert ump._child_state is None

        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()
        assert 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()
        assert 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()
        assert self.mock_mp_2.entity_id == \
            ump._child_state.entity_id
Пример #2
0
    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_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)
Пример #4
0
    def test_name(self):
        """Test name property."""
        config = validate_config(self.config_children_only)

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

        assert config['name'] == ump.name
Пример #5
0
    def test_supported_features_children_and_cmds(self):
        """Test supported media commands with children and attrs."""
        config = copy(self.config_children_and_attr)
        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
        }
        config = 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_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

        assert check_flags == ump.supported_features
Пример #6
0
    def test_polling(self):
        """Test should_poll property."""
        config = validate_config(self.config_children_only)

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

        assert ump.should_poll is False
Пример #7
0
    def test_master_state(self):
        """Test master state property."""
        config = validate_config(self.config_children_only)

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

        assert ump.master_state is None
Пример #8
0
    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)
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
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']))
Пример #12
0
    def test_master_state_with_attrs(self):
        """Test master state property."""
        config = validate_config(self.config_children_and_attr)

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

        assert STATE_OFF == ump.master_state
        self.hass.states.set(self.mock_state_switch_id, STATE_ON)
        assert STATE_ON == ump.master_state
Пример #13
0
    def test_master_state_with_bad_attrs(self):
        """Test master state property."""
        config = copy(self.config_children_and_attr)
        config['attributes']['state'] = 'bad.entity_id'
        config = validate_config(config)

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

        assert STATE_OFF == ump.master_state
Пример #14
0
    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)
Пример #15
0
    def test_is_volume_muted_children_and_attr(self):
        """Test is volume muted property w/ children and attrs."""
        config = validate_config(self.config_children_and_attr)

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

        assert not ump.is_volume_muted

        self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
        assert ump.is_volume_muted
Пример #16
0
    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)
Пример #17
0
    def test_volume_level_children_and_attr(self):
        """Test volume level property w/ children and attrs."""
        config = validate_config(self.config_children_and_attr)

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

        assert '0' == ump.volume_level

        self.hass.states.set(self.mock_volume_id, 100)
        assert '100' == ump.volume_level
Пример #18
0
    def test_source_list_children_and_attr(self):
        """Test source list property w/ children and attrs."""
        config = validate_config(self.config_children_and_attr)

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

        assert "['dvd', 'htpc']" == ump.source_list

        self.hass.states.set(self.mock_source_list_id, ['dvd', 'htpc', 'game'])
        assert "['dvd', 'htpc', 'game']" == ump.source_list
Пример #19
0
    def test_source_children_and_attr(self):
        """Test source property w/ children and attrs."""
        config = validate_config(self.config_children_and_attr)

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

        assert 'dvd' == ump.source

        self.hass.states.set(self.mock_source_id, 'htpc')
        assert 'htpc' == ump.source
    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)
Пример #22
0
    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)
Пример #23
0
    def test_master_state_with_template(self):
        """Test the state_template option."""
        config = copy(self.config_children_and_attr)
        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
        config = validate_config(config)

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

        assert STATE_ON == ump.master_state
        self.hass.states.set('input_boolean.test', STATE_ON)
        assert STATE_OFF == ump.master_state
Пример #24
0
    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)
Пример #25
0
    def test_state_children_only(self):
        """Test media player state with only children."""
        config = validate_config(self.config_children_only)

        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()

        assert 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()
        assert STATE_PLAYING == ump.state
Пример #26
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))
Пример #27
0
    def test_supported_features_children_only(self):
        """Test supported media commands with only children."""
        config = validate_config(self.config_children_only)

        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.schedule_update_ha_state()
        self.hass.block_till_done()
        run_coroutine_threadsafe(ump.async_update(), self.hass.loop).result()
        self.assertEqual(512, ump.supported_features)
Пример #28
0
    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)
Пример #29
0
    def test_service_call_no_active_child(self):
        """Test a service call to children with no active child."""
        config = validate_config(self.config_children_and_attr)

        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()
        assert 0 == len(self.mock_mp_1.service_calls['turn_off'])
        assert 0 == len(self.mock_mp_2.service_calls['turn_off'])
Пример #30
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']))