mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Allow passing dictionaries to async_register_entity_service (#26370)
This commit is contained in:
parent
df9703d814
commit
0cffd61481
@ -128,9 +128,12 @@ LIGHT_TURN_ON_SCHEMA = ENTITY_SERVICE_SCHEMA.extend(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
LIGHT_TURN_OFF_SCHEMA = ENTITY_SERVICE_SCHEMA.extend(
|
|
||||||
{ATTR_TRANSITION: VALID_TRANSITION, ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG])}
|
LIGHT_TURN_OFF_SCHEMA = {
|
||||||
)
|
ATTR_TRANSITION: VALID_TRANSITION,
|
||||||
|
ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LIGHT_TOGGLE_SCHEMA = LIGHT_TURN_ON_SCHEMA
|
LIGHT_TOGGLE_SCHEMA = LIGHT_TURN_ON_SCHEMA
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ from homeassistant.helpers.entity import ToggleEntity
|
|||||||
from homeassistant.helpers.config_validation import ( # noqa
|
from homeassistant.helpers.config_validation import ( # noqa
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
PLATFORM_SCHEMA_BASE,
|
PLATFORM_SCHEMA_BASE,
|
||||||
ENTITY_SERVICE_SCHEMA,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
@ -68,17 +67,9 @@ async def async_setup(hass, config):
|
|||||||
)
|
)
|
||||||
await component.async_setup(config)
|
await component.async_setup(config)
|
||||||
|
|
||||||
component.async_register_entity_service(
|
component.async_register_entity_service(SERVICE_TURN_OFF, {}, "async_turn_off")
|
||||||
SERVICE_TURN_OFF, ENTITY_SERVICE_SCHEMA, "async_turn_off"
|
component.async_register_entity_service(SERVICE_TURN_ON, {}, "async_turn_on")
|
||||||
)
|
component.async_register_entity_service(SERVICE_TOGGLE, {}, "async_toggle")
|
||||||
|
|
||||||
component.async_register_entity_service(
|
|
||||||
SERVICE_TURN_ON, ENTITY_SERVICE_SCHEMA, "async_turn_on"
|
|
||||||
)
|
|
||||||
|
|
||||||
component.async_register_entity_service(
|
|
||||||
SERVICE_TOGGLE, ENTITY_SERVICE_SCHEMA, "async_toggle"
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import config_per_platform, discovery
|
from homeassistant.helpers import config_per_platform, discovery
|
||||||
|
from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
|
||||||
from homeassistant.helpers.service import async_extract_entity_ids
|
from homeassistant.helpers.service import async_extract_entity_ids
|
||||||
from homeassistant.loader import bind_hass, async_get_integration
|
from homeassistant.loader import bind_hass, async_get_integration
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
@ -202,6 +203,8 @@ class EntityComponent:
|
|||||||
@callback
|
@callback
|
||||||
def async_register_entity_service(self, name, schema, func, required_features=None):
|
def async_register_entity_service(self, name, schema, func, required_features=None):
|
||||||
"""Register an entity service."""
|
"""Register an entity service."""
|
||||||
|
if isinstance(schema, dict):
|
||||||
|
schema = ENTITY_SERVICE_SCHEMA.extend(schema)
|
||||||
|
|
||||||
async def handle_service(call):
|
async def handle_service(call):
|
||||||
"""Handle the service."""
|
"""Handle the service."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user