mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Fix lock services not removing entity fields (#88805)
This commit is contained in:
parent
0f01866508
commit
bea81d3f63
@ -33,6 +33,7 @@ from homeassistant.helpers.config_validation import ( # noqa: F401
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
|
from homeassistant.helpers.service import remove_entity_service_fields
|
||||||
from homeassistant.helpers.typing import ConfigType, StateType
|
from homeassistant.helpers.typing import ConfigType, StateType
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -92,7 +93,7 @@ async def _async_lock(entity: LockEntity, service_call: ServiceCall) -> None:
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Code '{code}' for locking {entity.entity_id} doesn't match pattern {entity.code_format}"
|
f"Code '{code}' for locking {entity.entity_id} doesn't match pattern {entity.code_format}"
|
||||||
)
|
)
|
||||||
await entity.async_lock(**service_call.data)
|
await entity.async_lock(**remove_entity_service_fields(service_call))
|
||||||
|
|
||||||
|
|
||||||
async def _async_unlock(entity: LockEntity, service_call: ServiceCall) -> None:
|
async def _async_unlock(entity: LockEntity, service_call: ServiceCall) -> None:
|
||||||
@ -102,7 +103,7 @@ async def _async_unlock(entity: LockEntity, service_call: ServiceCall) -> None:
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Code '{code}' for unlocking {entity.entity_id} doesn't match pattern {entity.code_format}"
|
f"Code '{code}' for unlocking {entity.entity_id} doesn't match pattern {entity.code_format}"
|
||||||
)
|
)
|
||||||
await entity.async_unlock(**service_call.data)
|
await entity.async_unlock(**remove_entity_service_fields(service_call))
|
||||||
|
|
||||||
|
|
||||||
async def _async_open(entity: LockEntity, service_call: ServiceCall) -> None:
|
async def _async_open(entity: LockEntity, service_call: ServiceCall) -> None:
|
||||||
@ -112,7 +113,7 @@ async def _async_open(entity: LockEntity, service_call: ServiceCall) -> None:
|
|||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Code '{code}' for opening {entity.entity_id} doesn't match pattern {entity.code_format}"
|
f"Code '{code}' for opening {entity.entity_id} doesn't match pattern {entity.code_format}"
|
||||||
)
|
)
|
||||||
await entity.async_open(**service_call.data)
|
await entity.async_open(**remove_entity_service_fields(service_call))
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
@ -513,6 +513,16 @@ async def async_get_all_descriptions(
|
|||||||
return descriptions
|
return descriptions
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def remove_entity_service_fields(call: ServiceCall) -> dict[Any, Any]:
|
||||||
|
"""Remove entity service fields."""
|
||||||
|
return {
|
||||||
|
key: val
|
||||||
|
for key, val in call.data.items()
|
||||||
|
if key not in cv.ENTITY_SERVICE_FIELDS
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@bind_hass
|
@bind_hass
|
||||||
def async_set_service_schema(
|
def async_set_service_schema(
|
||||||
@ -567,11 +577,7 @@ async def entity_service_call( # noqa: C901
|
|||||||
|
|
||||||
# If the service function is a string, we'll pass it the service call data
|
# If the service function is a string, we'll pass it the service call data
|
||||||
if isinstance(func, str):
|
if isinstance(func, str):
|
||||||
data: dict | ServiceCall = {
|
data: dict | ServiceCall = remove_entity_service_fields(call)
|
||||||
key: val
|
|
||||||
for key, val in call.data.items()
|
|
||||||
if key not in cv.ENTITY_SERVICE_FIELDS
|
|
||||||
}
|
|
||||||
# If the service function is not a string, we pass the service call
|
# If the service function is not a string, we pass the service call
|
||||||
else:
|
else:
|
||||||
data = call
|
data = call
|
||||||
|
Loading…
x
Reference in New Issue
Block a user