Raise if referenced entity does not support service (#68394)

This commit is contained in:
Paulus Schoutsen
2022-03-20 16:01:58 -07:00
committed by GitHub
parent 0cbc29caca
commit 8bbbd1947d
10 changed files with 105 additions and 90 deletions

View File

@@ -552,6 +552,20 @@ async def test_call_with_required_features(hass, mock_entities):
actual = [call[0][0] for call in test_service_mock.call_args_list]
assert all(entity in actual for entity in expected)
# Test we raise if we target entity ID that does not support the service
test_service_mock.reset_mock()
with pytest.raises(exceptions.HomeAssistantError):
await service.entity_service_call(
hass,
[Mock(entities=mock_entities)],
test_service_mock,
ha.ServiceCall(
"test_domain", "test_service", {"entity_id": "light.living_room"}
),
required_features=[SUPPORT_A],
)
assert test_service_mock.call_count == 0
async def test_call_with_both_required_features(hass, mock_entities):
"""Test service calls invoked only if entity has both features."""