mirror of
https://github.com/home-assistant/core.git
synced 2026-09-26 09:23:17 -04:00
Remove deprecated hass arg from service methods (#182760)
This commit is contained in:
@@ -59,7 +59,6 @@ from . import (
|
||||
target as target_helpers,
|
||||
template,
|
||||
)
|
||||
from .deprecation import deprecated_hass_argument
|
||||
from .selector import TargetSelector
|
||||
from .typing import ConfigType, TemplateVarsType, VolDictType, VolSchemaType
|
||||
|
||||
@@ -348,7 +347,6 @@ def async_prepare_call_from_config(
|
||||
}
|
||||
|
||||
|
||||
@deprecated_hass_argument(breaks_in_ha_version="2026.10")
|
||||
def extract_entity_ids(
|
||||
service_call: ServiceCall, expand_group: bool = True
|
||||
) -> set[str]:
|
||||
@@ -361,7 +359,6 @@ def extract_entity_ids(
|
||||
).result()
|
||||
|
||||
|
||||
@deprecated_hass_argument(breaks_in_ha_version="2026.10")
|
||||
async def async_extract_entities[_EntityT: Entity](
|
||||
entities: Iterable[_EntityT],
|
||||
service_call: ServiceCall,
|
||||
@@ -400,7 +397,6 @@ async def async_extract_entities[_EntityT: Entity](
|
||||
return found
|
||||
|
||||
|
||||
@deprecated_hass_argument(breaks_in_ha_version="2026.10")
|
||||
async def async_extract_entity_ids(
|
||||
service_call: ServiceCall, expand_group: bool = True
|
||||
) -> set[str]:
|
||||
@@ -415,7 +411,6 @@ async def async_extract_entity_ids(
|
||||
return referenced.referenced | referenced.indirectly_referenced
|
||||
|
||||
|
||||
@deprecated_hass_argument(breaks_in_ha_version="2026.10")
|
||||
async def async_extract_config_entry_ids(
|
||||
service_call: ServiceCall, expand_group: bool = True
|
||||
) -> set[str]:
|
||||
@@ -1025,7 +1020,6 @@ def async_register_admin_service(
|
||||
)
|
||||
|
||||
|
||||
@deprecated_hass_argument(breaks_in_ha_version="2026.10")
|
||||
@callback
|
||||
def verify_domain_control(
|
||||
domain: str,
|
||||
|
||||
@@ -724,21 +724,20 @@ async def test_extract_entity_ids(hass: HomeAssistant) -> None:
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {ATTR_ENTITY_ID: "light.Bowl"})
|
||||
|
||||
assert {"light.bowl"} == await service.async_extract_entity_ids(hass, call)
|
||||
assert {"light.bowl"} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {ATTR_ENTITY_ID: "group.test"})
|
||||
|
||||
assert {"light.ceiling", "light.kitchen"} == await service.async_extract_entity_ids(
|
||||
hass, call
|
||||
call
|
||||
)
|
||||
|
||||
assert {"group.test"} == await service.async_extract_entity_ids(
|
||||
hass, call, expand_group=False
|
||||
call, expand_group=False
|
||||
)
|
||||
|
||||
assert (
|
||||
await service.async_extract_entity_ids(
|
||||
hass,
|
||||
ServiceCall(hass, "light", "turn_on", {ATTR_ENTITY_ID: ENTITY_MATCH_NONE}),
|
||||
)
|
||||
== set()
|
||||
@@ -753,14 +752,14 @@ async def test_extract_entity_ids_from_area(
|
||||
|
||||
assert {
|
||||
"light.in_own_area",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"area_id": "test-area"})
|
||||
|
||||
assert {
|
||||
"light.in_area",
|
||||
"light.assigned_to_area",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(
|
||||
hass, "light", "turn_on", {"area_id": ["test-area", "diff-area"]}
|
||||
@@ -770,11 +769,11 @@ async def test_extract_entity_ids_from_area(
|
||||
"light.in_area",
|
||||
"light.diff_area",
|
||||
"light.assigned_to_area",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
assert (
|
||||
await service.async_extract_entity_ids(
|
||||
hass, ServiceCall(hass, "light", "turn_on", {"area_id": ENTITY_MATCH_NONE})
|
||||
ServiceCall(hass, "light", "turn_on", {"area_id": ENTITY_MATCH_NONE})
|
||||
)
|
||||
== set()
|
||||
)
|
||||
@@ -785,13 +784,13 @@ async def test_extract_entity_ids_from_devices(
|
||||
) -> None:
|
||||
"""Test extract_entity_ids method with devices."""
|
||||
assert await service.async_extract_entity_ids(
|
||||
hass, ServiceCall(hass, "light", "turn_on", {"device_id": "device-no-area-id"})
|
||||
ServiceCall(hass, "light", "turn_on", {"device_id": "device-no-area-id"})
|
||||
) == {
|
||||
"light.no_area",
|
||||
}
|
||||
|
||||
assert await service.async_extract_entity_ids(
|
||||
hass, ServiceCall(hass, "light", "turn_on", {"device_id": "device-area-a-id"})
|
||||
ServiceCall(hass, "light", "turn_on", {"device_id": "device-area-a-id"})
|
||||
) == {
|
||||
"light.in_area_a",
|
||||
"light.in_area_b",
|
||||
@@ -799,7 +798,6 @@ async def test_extract_entity_ids_from_devices(
|
||||
|
||||
assert (
|
||||
await service.async_extract_entity_ids(
|
||||
hass,
|
||||
ServiceCall(hass, "light", "turn_on", {"device_id": "non-existing-id"}),
|
||||
)
|
||||
== set()
|
||||
@@ -814,7 +812,7 @@ async def test_extract_entity_ids_from_floor(hass: HomeAssistant) -> None:
|
||||
assert {
|
||||
"light.in_area",
|
||||
"light.assigned_to_area",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(
|
||||
hass, "light", "turn_on", {"floor_id": ["test-floor", "floor-a"]}
|
||||
@@ -824,11 +822,11 @@ async def test_extract_entity_ids_from_floor(hass: HomeAssistant) -> None:
|
||||
"light.in_area",
|
||||
"light.assigned_to_area",
|
||||
"light.in_area_a",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
assert (
|
||||
await service.async_extract_entity_ids(
|
||||
hass, ServiceCall(hass, "light", "turn_on", {"floor_id": ENTITY_MATCH_NONE})
|
||||
ServiceCall(hass, "light", "turn_on", {"floor_id": ENTITY_MATCH_NONE})
|
||||
)
|
||||
== set()
|
||||
)
|
||||
@@ -843,7 +841,7 @@ async def test_extract_entity_ids_from_labels(hass: HomeAssistant) -> None:
|
||||
"light.with_my_label",
|
||||
"light.config_with_my_label",
|
||||
"light.diag_with_my_label",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": "label1"})
|
||||
|
||||
@@ -852,24 +850,24 @@ async def test_extract_entity_ids_from_labels(hass: HomeAssistant) -> None:
|
||||
"light.with_label1_from_device_diff_area",
|
||||
"light.with_labels_from_device",
|
||||
"light.with_label1_and_label2_from_device",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": ["label2"]})
|
||||
|
||||
assert {
|
||||
"light.with_labels_from_device",
|
||||
"light.with_label1_and_label2_from_device",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": ["label_area"]})
|
||||
|
||||
assert {
|
||||
"light.with_labels_from_device",
|
||||
} == await service.async_extract_entity_ids(hass, call)
|
||||
} == await service.async_extract_entity_ids(call)
|
||||
|
||||
assert (
|
||||
await service.async_extract_entity_ids(
|
||||
hass, ServiceCall(hass, "light", "turn_on", {"label_id": ENTITY_MATCH_NONE})
|
||||
ServiceCall(hass, "light", "turn_on", {"label_id": ENTITY_MATCH_NONE})
|
||||
)
|
||||
== set()
|
||||
)
|
||||
@@ -2086,25 +2084,21 @@ async def test_register_admin_service_return_response(
|
||||
assert result == {"test-reply": "test-value1"}
|
||||
|
||||
|
||||
_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE = (
|
||||
"The deprecated argument hass was passed to verify_domain_control. It will be"
|
||||
" removed in HA Core 2026.10. Use verify_domain_control without hass argument"
|
||||
" instead"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
# Check that with or without hass behaves the same
|
||||
("decorator", "in_caplog"),
|
||||
[
|
||||
(service.verify_domain_control, True), # old pass-through
|
||||
(lambda _, domain: service.verify_domain_control(domain), False), # new
|
||||
(
|
||||
lambda domain: service.verify_domain_control(domain), # pylint: disable=unnecessary-lambda
|
||||
False,
|
||||
), # new
|
||||
],
|
||||
)
|
||||
async def test_domain_control_not_async(
|
||||
hass: HomeAssistant,
|
||||
mock_entities,
|
||||
decorator: Callable[[HomeAssistant, str], Any],
|
||||
decorator: Callable[[str], Any],
|
||||
in_caplog: bool,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
@@ -2116,9 +2110,7 @@ async def test_domain_control_not_async(
|
||||
calls.append(call)
|
||||
|
||||
with pytest.raises(exceptions.HomeAssistantError):
|
||||
decorator(hass, "test_domain")(mock_service_log)
|
||||
|
||||
assert (_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE in caplog.text) == in_caplog
|
||||
decorator("test_domain")(mock_service_log)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -2126,7 +2118,10 @@ async def test_domain_control_not_async(
|
||||
("decorator", "in_caplog"),
|
||||
[
|
||||
(service.verify_domain_control, True), # old pass-through
|
||||
(lambda _, domain: service.verify_domain_control(domain), False), # new
|
||||
(
|
||||
lambda domain: service.verify_domain_control(domain), # pylint: disable=unnecessary-lambda
|
||||
False,
|
||||
), # new
|
||||
],
|
||||
)
|
||||
async def test_domain_control_unknown(
|
||||
@@ -2147,7 +2142,7 @@ async def test_domain_control_unknown(
|
||||
"homeassistant.helpers.entity_registry.async_get",
|
||||
return_value=Mock(entities=mock_entities),
|
||||
):
|
||||
protected_mock_service = decorator(hass, "test_domain")(mock_service_log)
|
||||
protected_mock_service = decorator("test_domain")(mock_service_log)
|
||||
|
||||
hass.services.async_register(
|
||||
"test_domain", "test_service", protected_mock_service, schema=None
|
||||
@@ -2163,21 +2158,22 @@ async def test_domain_control_unknown(
|
||||
)
|
||||
assert len(calls) == 0
|
||||
|
||||
assert (_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE in caplog.text) == in_caplog
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
# Check that with or without hass behaves the same
|
||||
("decorator", "in_caplog"),
|
||||
[
|
||||
(service.verify_domain_control, True), # old pass-through
|
||||
(lambda _, domain: service.verify_domain_control(domain), False), # new
|
||||
(
|
||||
lambda domain: service.verify_domain_control(domain), # pylint: disable=unnecessary-lambda
|
||||
False,
|
||||
), # new
|
||||
],
|
||||
)
|
||||
async def test_domain_control_unauthorized(
|
||||
hass: HomeAssistant,
|
||||
hass_read_only_user: MockUser,
|
||||
decorator: Callable[[HomeAssistant, str], Any],
|
||||
decorator: Callable[[str], Any],
|
||||
in_caplog: bool,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
@@ -2199,7 +2195,7 @@ async def test_domain_control_unauthorized(
|
||||
"""Define a protected service."""
|
||||
calls.append(call)
|
||||
|
||||
protected_mock_service = decorator(hass, "test_domain")(mock_service_log)
|
||||
protected_mock_service = decorator("test_domain")(mock_service_log)
|
||||
|
||||
hass.services.async_register(
|
||||
"test_domain", "test_service", protected_mock_service, schema=None
|
||||
@@ -2216,21 +2212,22 @@ async def test_domain_control_unauthorized(
|
||||
|
||||
assert len(calls) == 0
|
||||
|
||||
assert (_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE in caplog.text) == in_caplog
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
# Check that with or without hass behaves the same
|
||||
("decorator", "in_caplog"),
|
||||
[
|
||||
(service.verify_domain_control, True), # old pass-through
|
||||
(lambda _, domain: service.verify_domain_control(domain), False), # new
|
||||
(
|
||||
lambda domain: service.verify_domain_control(domain), # pylint: disable=unnecessary-lambda
|
||||
False,
|
||||
), # new
|
||||
],
|
||||
)
|
||||
async def test_domain_control_admin(
|
||||
hass: HomeAssistant,
|
||||
hass_admin_user: MockUser,
|
||||
decorator: Callable[[HomeAssistant, str], Any],
|
||||
decorator: Callable[[str], Any],
|
||||
in_caplog: bool,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
@@ -2252,7 +2249,7 @@ async def test_domain_control_admin(
|
||||
"""Define a protected service."""
|
||||
calls.append(call)
|
||||
|
||||
protected_mock_service = decorator(hass, "test_domain")(mock_service_log)
|
||||
protected_mock_service = decorator("test_domain")(mock_service_log)
|
||||
|
||||
hass.services.async_register(
|
||||
"test_domain", "test_service", protected_mock_service, schema=None
|
||||
@@ -2268,20 +2265,21 @@ async def test_domain_control_admin(
|
||||
|
||||
assert len(calls) == 1
|
||||
|
||||
assert (_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE in caplog.text) == in_caplog
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
# Check that with or without hass behaves the same
|
||||
("decorator", "in_caplog"),
|
||||
[
|
||||
(service.verify_domain_control, True), # old pass-through
|
||||
(lambda _, domain: service.verify_domain_control(domain), False), # new
|
||||
(
|
||||
lambda domain: service.verify_domain_control(domain), # pylint: disable=unnecessary-lambda
|
||||
False,
|
||||
), # new
|
||||
],
|
||||
)
|
||||
async def test_domain_control_no_user(
|
||||
hass: HomeAssistant,
|
||||
decorator: Callable[[HomeAssistant, str], Any],
|
||||
decorator: Callable[[str], Any],
|
||||
in_caplog: bool,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
@@ -2303,7 +2301,7 @@ async def test_domain_control_no_user(
|
||||
"""Define a protected service."""
|
||||
calls.append(call)
|
||||
|
||||
protected_mock_service = decorator(hass, "test_domain")(mock_service_log)
|
||||
protected_mock_service = decorator("test_domain")(mock_service_log)
|
||||
|
||||
hass.services.async_register(
|
||||
"test_domain", "test_service", protected_mock_service, schema=None
|
||||
@@ -2319,8 +2317,6 @@ async def test_domain_control_no_user(
|
||||
|
||||
assert len(calls) == 1
|
||||
|
||||
assert (_DEPRECATED_VERIFY_DOMAIN_CONTROL_MESSAGE in caplog.text) == in_caplog
|
||||
|
||||
|
||||
async def test_extract_from_service_available_device(hass: HomeAssistant) -> None:
|
||||
"""Test the extraction of entity from service and device is available."""
|
||||
@@ -2335,7 +2331,7 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
|
||||
|
||||
assert [
|
||||
ent.entity_id
|
||||
for ent in (await service.async_extract_entities(hass, entities, call_1))
|
||||
for ent in (await service.async_extract_entities(entities, call_1))
|
||||
] == ["test_domain.test_1", "test_domain.test_3"]
|
||||
|
||||
call_2 = ServiceCall(
|
||||
@@ -2347,12 +2343,11 @@ async def test_extract_from_service_available_device(hass: HomeAssistant) -> Non
|
||||
|
||||
assert [
|
||||
ent.entity_id
|
||||
for ent in (await service.async_extract_entities(hass, entities, call_2))
|
||||
for ent in (await service.async_extract_entities(entities, call_2))
|
||||
] == ["test_domain.test_3"]
|
||||
|
||||
assert (
|
||||
await service.async_extract_entities(
|
||||
hass,
|
||||
entities,
|
||||
ServiceCall(
|
||||
hass,
|
||||
@@ -2374,8 +2369,7 @@ async def test_extract_from_service_empty_if_no_entity_id(hass: HomeAssistant) -
|
||||
call = ServiceCall(hass, "test", "service")
|
||||
|
||||
assert [
|
||||
ent.entity_id
|
||||
for ent in (await service.async_extract_entities(hass, entities, call))
|
||||
ent.entity_id for ent in (await service.async_extract_entities(entities, call))
|
||||
] == []
|
||||
|
||||
|
||||
@@ -2396,8 +2390,7 @@ async def test_extract_from_service_filter_out_non_existing_entities(
|
||||
)
|
||||
|
||||
assert [
|
||||
ent.entity_id
|
||||
for ent in (await service.async_extract_entities(hass, entities, call))
|
||||
ent.entity_id for ent in (await service.async_extract_entities(entities, call))
|
||||
] == ["test_domain.test_2"]
|
||||
|
||||
|
||||
@@ -2412,14 +2405,14 @@ async def test_extract_from_service_area_id(
|
||||
]
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"area_id": "test-area"})
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 1
|
||||
assert extracted[0].entity_id == "light.in_area"
|
||||
|
||||
call = ServiceCall(
|
||||
hass, "light", "turn_on", {"area_id": ["test-area", "diff-area"]}
|
||||
)
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 2
|
||||
assert sorted(ent.entity_id for ent in extracted) == [
|
||||
"light.diff_area",
|
||||
@@ -2432,7 +2425,7 @@ async def test_extract_from_service_area_id(
|
||||
"turn_on",
|
||||
{"area_id": ["test-area", "diff-area"], "device_id": "device-no-area-id"},
|
||||
)
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 3
|
||||
assert sorted(ent.entity_id for ent in extracted) == [
|
||||
"light.diff_area",
|
||||
@@ -2453,17 +2446,17 @@ async def test_extract_from_service_label_id(hass: HomeAssistant) -> None:
|
||||
]
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": "label_area"})
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 1
|
||||
assert extracted[0].entity_id == "light.with_labels_from_device"
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": "my-label"})
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 1
|
||||
assert extracted[0].entity_id == "light.with_my_label"
|
||||
|
||||
call = ServiceCall(hass, "light", "turn_on", {"label_id": ["my-label", "label1"]})
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 2
|
||||
assert sorted(ent.entity_id for ent in extracted) == [
|
||||
"light.with_labels_from_device",
|
||||
@@ -2476,7 +2469,7 @@ async def test_extract_from_service_label_id(hass: HomeAssistant) -> None:
|
||||
"turn_on",
|
||||
{"label_id": ["my-label", "label1"], "device_id": "device-no-labels"},
|
||||
)
|
||||
extracted = await service.async_extract_entities(hass, entities, call)
|
||||
extracted = await service.async_extract_entities(entities, call)
|
||||
assert len(extracted) == 3
|
||||
assert sorted(ent.entity_id for ent in extracted) == [
|
||||
"light.no_labels",
|
||||
@@ -2547,7 +2540,7 @@ async def test_async_extract_entities_warn_referenced(
|
||||
"label_id": "non-existent-label",
|
||||
},
|
||||
)
|
||||
extracted = await service.async_extract_entities(hass, {}, call)
|
||||
extracted = await service.async_extract_entities({}, call)
|
||||
assert len(extracted) == 0
|
||||
assert (
|
||||
"Referenced floors non-existent-floor, areas non-existent-area, "
|
||||
@@ -2580,7 +2573,7 @@ async def test_async_extract_config_entry_ids(hass: HomeAssistant) -> None:
|
||||
},
|
||||
)
|
||||
|
||||
assert await service.async_extract_config_entry_ids(hass, call) == {"abc"}
|
||||
assert await service.async_extract_config_entry_ids(call) == {"abc"}
|
||||
|
||||
|
||||
async def test_reload_service_helper(hass: HomeAssistant) -> None:
|
||||
|
||||
Reference in New Issue
Block a user