Do not select all entities when omitting entity ID in service call (#29178)
* Do not select all entities when omitting entity ID * Address comments Matthew * Require either area_id or entity_id * Fix tests * Fix test
This commit is contained in:
parent
9587afc5ce
commit
02d9ed5e36
47 changed files with 538 additions and 626 deletions
|
@ -11,7 +11,7 @@ import pytest
|
|||
# To prevent circular import when running just this file
|
||||
import homeassistant.components # noqa: F401
|
||||
from homeassistant import core as ha, exceptions
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ENTITY_ID
|
||||
from homeassistant.const import STATE_ON, STATE_OFF, ATTR_ENTITY_ID, ENTITY_MATCH_ALL
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.auth.permissions import PolicyPermissions
|
||||
|
@ -334,7 +334,10 @@ async def test_call_context_target_all(hass, mock_service_platform_call, mock_en
|
|||
[Mock(entities=mock_entities)],
|
||||
Mock(),
|
||||
ha.ServiceCall(
|
||||
"test_domain", "test_service", context=ha.Context(user_id="mock-id")
|
||||
"test_domain",
|
||||
"test_service",
|
||||
data={"entity_id": ENTITY_MATCH_ALL},
|
||||
context=ha.Context(user_id="mock-id"),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -407,7 +410,9 @@ async def test_call_no_context_target_all(
|
|||
hass,
|
||||
[Mock(entities=mock_entities)],
|
||||
Mock(),
|
||||
ha.ServiceCall("test_domain", "test_service"),
|
||||
ha.ServiceCall(
|
||||
"test_domain", "test_service", data={"entity_id": ENTITY_MATCH_ALL}
|
||||
),
|
||||
)
|
||||
|
||||
assert len(mock_service_platform_call.mock_calls) == 1
|
||||
|
@ -458,9 +463,9 @@ async def test_call_with_match_all(
|
|||
|
||||
|
||||
async def test_call_with_omit_entity_id(
|
||||
hass, mock_service_platform_call, mock_entities, caplog
|
||||
hass, mock_service_platform_call, mock_entities
|
||||
):
|
||||
"""Check we only target allowed entities if targetting all."""
|
||||
"""Check service call if we do not pass an entity ID."""
|
||||
await service.entity_service_call(
|
||||
hass,
|
||||
[Mock(entities=mock_entities)],
|
||||
|
@ -470,13 +475,7 @@ async def test_call_with_omit_entity_id(
|
|||
|
||||
assert len(mock_service_platform_call.mock_calls) == 1
|
||||
entities = mock_service_platform_call.mock_calls[0][1][2]
|
||||
assert entities == [
|
||||
mock_entities["light.kitchen"],
|
||||
mock_entities["light.living_room"],
|
||||
]
|
||||
assert (
|
||||
"Not passing an entity ID to a service to target " "all entities is deprecated"
|
||||
) in caplog.text
|
||||
assert entities == []
|
||||
|
||||
|
||||
async def test_register_admin_service(hass, hass_read_only_user, hass_admin_user):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue