mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Service validation for input_slider component.
This commit is contained in:
parent
8b40346db3
commit
620d7a92f0
@ -6,7 +6,10 @@ at https://home-assistant.io/components/input_slider/
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import ATTR_ENTITY_ID
|
from homeassistant.const import ATTR_ENTITY_ID
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.entity_component import EntityComponent
|
from homeassistant.helpers.entity_component import EntityComponent
|
||||||
from homeassistant.util import slugify
|
from homeassistant.util import slugify
|
||||||
@ -29,6 +32,11 @@ ATTR_STEP = 'step'
|
|||||||
|
|
||||||
SERVICE_SELECT_VALUE = 'select_value'
|
SERVICE_SELECT_VALUE = 'select_value'
|
||||||
|
|
||||||
|
SERVICE_SELECT_VALUE_SCHEMA = vol.Schema({
|
||||||
|
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
|
||||||
|
vol.Required(ATTR_VALUE): vol.Coerce(int),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def select_value(hass, entity_id, value):
|
def select_value(hass, entity_id, value):
|
||||||
"""Set input_slider to value."""
|
"""Set input_slider to value."""
|
||||||
@ -81,10 +89,11 @@ def setup(hass, config):
|
|||||||
target_inputs = component.extract_from_service(call)
|
target_inputs = component.extract_from_service(call)
|
||||||
|
|
||||||
for input_slider in target_inputs:
|
for input_slider in target_inputs:
|
||||||
input_slider.select_value(call.data.get(ATTR_VALUE))
|
input_slider.select_value(call.data[ATTR_VALUE])
|
||||||
|
|
||||||
hass.services.register(DOMAIN, SERVICE_SELECT_VALUE,
|
hass.services.register(DOMAIN, SERVICE_SELECT_VALUE,
|
||||||
select_value_service)
|
select_value_service,
|
||||||
|
schema=SERVICE_SELECT_VALUE_SCHEMA)
|
||||||
|
|
||||||
component.add_entities(entities)
|
component.add_entities(entities)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user