Formalize supported_features as entity property (#5794)

* Formalize supported_features as entity property

* Remove extra emulated_hue conditions

* Generate log message in executor
This commit is contained in:
Adam Mills authored and Paulus Schoutsen committed 2017-02-07 20:42:45 -08:00
1 parent 4fa4d7347f
commit ecfe8e0a9a
49 files changed
+193 -165

No files matched your search

@@ -301,7 +301,7 @@ def test_put_light_state_fan(hass_hue, hue_client):
blocking=True)
# Emulated hue converts 0-100% to 0-255.
level = 23
level = 43
brightness = round(level * 255 / 100)
fan_result = yield from perform_put_light_state(
+10 -10
View File
@@ -155,28 +155,28 @@ class TestDemoMediaPlayer(unittest.TestCase):
state = self.hass.states.get(entity_id)
assert 1 == state.attributes.get('media_track')
assert 0 == (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
mp.media_next_track(self.hass, entity_id)
self.hass.block_till_done()
state = self.hass.states.get(entity_id)
assert 2 == state.attributes.get('media_track')
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
mp.media_next_track(self.hass, entity_id)
self.hass.block_till_done()
state = self.hass.states.get(entity_id)
assert 3 == state.attributes.get('media_track')
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
mp.media_previous_track(self.hass, entity_id)
self.hass.block_till_done()
state = self.hass.states.get(entity_id)
assert 2 == state.attributes.get('media_track')
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
assert setup_component(
self.hass, mp.DOMAIN,
@@ -185,21 +185,21 @@ class TestDemoMediaPlayer(unittest.TestCase):
state = self.hass.states.get(ent_id)
assert 1 == state.attributes.get('media_episode')
assert 0 == (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
mp.media_next_track(self.hass, ent_id)
self.hass.block_till_done()
state = self.hass.states.get(ent_id)
assert 2 == state.attributes.get('media_episode')
assert 0 < (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
mp.media_previous_track(self.hass, ent_id)
self.hass.block_till_done()
state = self.hass.states.get(ent_id)
assert 1 == state.attributes.get('media_episode')
assert 0 == (mp.SUPPORT_PREVIOUS_TRACK &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
@patch('homeassistant.components.media_player.demo.DemoYoutubePlayer.'
'media_seek', autospec=True)
@@ -211,21 +211,21 @@ class TestDemoMediaPlayer(unittest.TestCase):
ent_id = 'media_player.living_room'
state = self.hass.states.get(ent_id)
assert 0 < (mp.SUPPORT_PLAY_MEDIA &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
assert state.attributes.get('media_content_id') is not None
mp.play_media(self.hass, None, 'some_id', ent_id)
self.hass.block_till_done()
state = self.hass.states.get(ent_id)
assert 0 < (mp.SUPPORT_PLAY_MEDIA &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
assert not 'some_id' == state.attributes.get('media_content_id')
mp.play_media(self.hass, 'youtube', 'some_id', ent_id)
self.hass.block_till_done()
state = self.hass.states.get(ent_id)
assert 0 < (mp.SUPPORT_PLAY_MEDIA &
state.attributes.get('supported_media_commands'))
state.attributes.get('supported_features'))
assert 'some_id' == state.attributes.get('media_content_id')
assert not mock_seek.called
@@ -318,7 +318,7 @@ class TestSoundtouchMediaPlayer(unittest.TestCase):
default_component(),
mock.MagicMock())
self.assertEqual(mocked_sountouch_device.call_count, 1)
self.assertEqual(soundtouch.DEVICES[0].supported_media_commands, 17853)
self.assertEqual(soundtouch.DEVICES[0].supported_features, 17853)
@mock.patch('libsoundtouch.device.SoundTouchDevice.power_off')
@mock.patch('libsoundtouch.device.SoundTouchDevice.volume')
+10 -10
View File
@@ -27,7 +27,7 @@ class MockMediaPlayer(media_player.MediaPlayerDevice):
self._volume_level = 0
self._is_volume_muted = False
self._media_title = None
self._supported_media_commands = 0
self._supported_features = 0
self._source = None
self._tracks = 12
self._media_image_url = None
@@ -91,9 +91,9 @@ class MockMediaPlayer(media_player.MediaPlayerDevice):
return self._is_volume_muted
@property
def supported_media_commands(self):
"""Supported media commands flag."""
return self._supported_media_commands
def supported_features(self):
"""Flag media player features that are supported."""
return self._supported_features
@property
def media_image_url(self):
@@ -502,7 +502,7 @@ class TestMediaPlayer(unittest.TestCase):
self.hass.states.set(self.mock_mute_switch_id, STATE_ON)
self.assertTrue(ump.is_volume_muted)
def test_supported_media_commands_children_only(self):
def test_supported_features_children_only(self):
"""Test supported media commands with only children."""
config = self.config_children_only
universal.validate_config(config)
@@ -511,15 +511,15 @@ class TestMediaPlayer(unittest.TestCase):
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_media_commands)
self.assertEqual(0, ump.supported_features)
self.mock_mp_1._supported_media_commands = 512
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_media_commands)
self.assertEqual(512, ump.supported_features)
def test_supported_media_commands_children_and_cmds(self):
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)
@@ -543,7 +543,7 @@ class TestMediaPlayer(unittest.TestCase):
| universal.SUPPORT_VOLUME_STEP | universal.SUPPORT_VOLUME_MUTE \
| universal.SUPPORT_SELECT_SOURCE
self.assertEqual(check_flags, ump.supported_media_commands)
self.assertEqual(check_flags, ump.supported_features)
def test_service_call_no_active_child(self):
"""Test a service call to children with no active child."""