1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Cache the job type for entity service calls (#112793)

This commit is contained in:
J. Nick Koston
2024-03-08 22:49:08 -10:00
committed by GitHub
parent 19e54debba
commit b7d9f26cee
4 changed files with 53 additions and 4 deletions

View File

@@ -23,7 +23,13 @@ from homeassistant.const import (
STATE_UNAVAILABLE,
STATE_UNKNOWN,
)
from homeassistant.core import Context, HomeAssistant, HomeAssistantError
from homeassistant.core import (
Context,
HassJobType,
HomeAssistant,
HomeAssistantError,
callback,
)
from homeassistant.helpers import device_registry as dr, entity, entity_registry as er
from homeassistant.helpers.entity_component import async_update_entity
from homeassistant.helpers.typing import UNDEFINED, UndefinedType
@@ -2559,3 +2565,26 @@ async def test_reset_right_after_remove_entity_registry(
assert len(ent.remove_calls) == 1
assert hass.states.get("test.test") is None
async def test_get_hassjob_type(hass: HomeAssistant) -> None:
"""Test get_hassjob_type."""
class AsyncEntity(entity.Entity):
"""Test entity."""
def update(self):
"""Test update Executor."""
async def async_update(self):
"""Test update Coroutinefunction."""
@callback
def update_callback(self):
"""Test update Callback."""
ent_1 = AsyncEntity()
assert ent_1.get_hassjob_type("update") is HassJobType.Executor
assert ent_1.get_hassjob_type("async_update") is HassJobType.Coroutinefunction
assert ent_1.get_hassjob_type("update_callback") is HassJobType.Callback