Check for supported features in media_player services (#22878)

* Add check for supported features

* Move logic to service helper

* Fix hacked in test for seek

* Test for service required features
This commit is contained in:
Andrew Sayre 2019-04-10 11:44:58 -05:00 committed by Paulus Schoutsen
parent fc7a187dd6
commit 7624d0e79f
6 changed files with 84 additions and 79 deletions

View file

@ -37,11 +37,13 @@ def mock_entities():
entity_id='light.kitchen',
available=True,
should_poll=False,
supported_features=1,
)
living_room = Mock(
entity_id='light.living_room',
available=True,
should_poll=False,
supported_features=0,
)
entities = OrderedDict()
entities[kitchen.entity_id] = kitchen
@ -269,6 +271,19 @@ def test_async_get_all_descriptions(hass):
assert 'fields' in descriptions[logger.DOMAIN]['set_level']
async def test_call_with_required_features(hass, mock_entities):
"""Test service calls invoked only if entity has required feautres."""
test_service_mock = Mock(return_value=mock_coro())
await service.entity_service_call(hass, [
Mock(entities=mock_entities)
], test_service_mock, ha.ServiceCall('test_domain', 'test_service', {
'entity_id': 'all'
}), required_features=1)
assert len(mock_entities) == 2
# Called once because only one of the entities had the required features
assert test_service_mock.call_count == 1
async def test_call_context_user_not_exist(hass):
"""Check we don't allow deleted users to do things."""
with pytest.raises(exceptions.UnknownUser) as err: