mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Adds new homeassistant.tag_scanned action (#1281)
This commit is contained in:
parent
e7bd93b4b0
commit
703e9673c2
2 changed files with 22 additions and 1 deletions
|
@ -3,7 +3,8 @@ import esphome.config_validation as cv
|
|||
from esphome import automation
|
||||
from esphome.automation import Condition
|
||||
from esphome.const import CONF_DATA, CONF_DATA_TEMPLATE, CONF_ID, CONF_PASSWORD, CONF_PORT, \
|
||||
CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID, CONF_EVENT
|
||||
CONF_REBOOT_TIMEOUT, CONF_SERVICE, CONF_VARIABLES, CONF_SERVICES, CONF_TRIGGER_ID, CONF_EVENT, \
|
||||
CONF_TAG
|
||||
from esphome.core import coroutine_with_priority
|
||||
|
||||
DEPENDENCIES = ['network']
|
||||
|
@ -137,6 +138,23 @@ def homeassistant_event_to_code(config, action_id, template_arg, args):
|
|||
yield var
|
||||
|
||||
|
||||
HOMEASSISTANT_TAG_SCANNED_ACTION_SCHEMA = cv.maybe_simple_value({
|
||||
cv.GenerateID(): cv.use_id(APIServer),
|
||||
cv.Required(CONF_TAG): cv.templatable(cv.string_strict),
|
||||
}, key=CONF_TAG)
|
||||
|
||||
|
||||
@automation.register_action('homeassistant.tag_scanned', HomeAssistantServiceCallAction,
|
||||
HOMEASSISTANT_TAG_SCANNED_ACTION_SCHEMA)
|
||||
def homeassistant_tag_scanned_to_code(config, action_id, template_arg, args):
|
||||
serv = yield cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, serv, True)
|
||||
cg.add(var.set_service('esphome.tag_scanned'))
|
||||
templ = yield cg.templatable(config[CONF_TAG], args, cg.std_string)
|
||||
cg.add(var.add_data('tag_id', templ))
|
||||
yield var
|
||||
|
||||
|
||||
@automation.register_condition('api.connected', APIConnectedCondition, {})
|
||||
def api_connected_to_code(config, condition_id, template_arg, args):
|
||||
yield cg.new_Pvariable(condition_id, template_arg)
|
||||
|
|
|
@ -280,6 +280,9 @@ text_sensor:
|
|||
service: light.turn_on
|
||||
data:
|
||||
entity_id: light.my_light
|
||||
- homeassistant.tag_scanned:
|
||||
tag: 1234-abcd
|
||||
- homeassistant.tag_scanned: 1234-abcd
|
||||
- platform: template
|
||||
name: "Template Text Sensor"
|
||||
lambda: |-
|
||||
|
|
Loading…
Reference in a new issue