parent
27908af61e
commit
07c7081ade
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
import asyncio
|
||||
from collections.abc import Awaitable, Callable, Iterable
|
||||
from contextvars import ContextVar
|
||||
import dataclasses
|
||||
from functools import partial, wraps
|
||||
import logging
|
||||
|
@ -64,15 +63,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
SERVICE_DESCRIPTION_CACHE = "service_description_cache"
|
||||
|
||||
|
||||
_current_entity: ContextVar[str | None] = ContextVar("current_entity", default=None)
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_current_entity() -> str | None:
|
||||
"""Get the current entity on which the service is called."""
|
||||
return _current_entity.get()
|
||||
|
||||
|
||||
class ServiceParams(TypedDict):
|
||||
"""Type for service call parameters."""
|
||||
|
||||
|
@ -716,7 +706,6 @@ async def _handle_entity_call(
|
|||
) -> None:
|
||||
"""Handle calling service method."""
|
||||
entity.async_set_context(context)
|
||||
_current_entity.set(entity.entity_id)
|
||||
|
||||
if isinstance(func, str):
|
||||
result = hass.async_run_job(partial(getattr(entity, func), **data)) # type: ignore[arg-type]
|
||||
|
|
|
@ -19,12 +19,12 @@ from homeassistant.const import (
|
|||
STATE_ON,
|
||||
)
|
||||
from homeassistant.helpers import (
|
||||
config_validation as cv,
|
||||
device_registry as dev_reg,
|
||||
entity_registry as ent_reg,
|
||||
service,
|
||||
template,
|
||||
)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
@ -1206,17 +1206,3 @@ async def test_async_extract_config_entry_ids(hass):
|
|||
)
|
||||
|
||||
assert await service.async_extract_config_entry_ids(hass, call) == {"abc"}
|
||||
|
||||
|
||||
async def test_current_entity_context(hass, mock_entities):
|
||||
"""Test we set the current entity context var."""
|
||||
|
||||
async def mock_service(entity, call):
|
||||
assert entity.entity_id == service.async_get_current_entity()
|
||||
|
||||
await service.entity_service_call(
|
||||
hass,
|
||||
[Mock(entities=mock_entities)],
|
||||
mock_service,
|
||||
ha.ServiceCall("test_domain", "test_service", {"entity_id": "light.kitchen"}),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue