mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Add PN532 On Tag Trigger (#189)
* Add PN532 On Tag Trigger
* Lint
* Fix 😶
* Fix
This commit is contained in:
parent
75628b96a1
commit
81bc400340
3 changed files with 20 additions and 4 deletions
|
@ -1,21 +1,26 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml import pins, automation
|
||||
from esphomeyaml.components import binary_sensor
|
||||
from esphomeyaml.components.spi import SPIComponent
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_SPI_ID, CONF_UPDATE_INTERVAL
|
||||
from esphomeyaml.helpers import App, Pvariable, get_variable, gpio_output_pin_expression
|
||||
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_SPI_ID, CONF_UPDATE_INTERVAL, \
|
||||
CONF_ON_TAG, CONF_TRIGGER_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, get_variable, gpio_output_pin_expression, std_string
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
PN532Component = binary_sensor.binary_sensor_ns.PN532Component
|
||||
PN532Trigger = binary_sensor.binary_sensor_ns.PN532Trigger
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(PN532Component),
|
||||
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
||||
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_UPDATE_INTERVAL): cv.update_interval,
|
||||
vol.Optional(CONF_ON_TAG): vol.All(cv.ensure_list, [automation.validate_automation({
|
||||
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_variable_id(PN532Trigger),
|
||||
})]),
|
||||
})])
|
||||
|
||||
|
||||
|
@ -28,7 +33,11 @@ def to_code(config):
|
|||
for cs in gpio_output_pin_expression(conf[CONF_CS_PIN]):
|
||||
yield
|
||||
rhs = App.make_pn532_component(spi, cs, conf.get(CONF_UPDATE_INTERVAL))
|
||||
Pvariable(conf[CONF_ID], rhs)
|
||||
pn532 = Pvariable(conf[CONF_ID], rhs)
|
||||
|
||||
for conf_ in conf.get(CONF_ON_TAG, []):
|
||||
trigger = Pvariable(conf_[CONF_TRIGGER_ID], pn532.make_trigger())
|
||||
automation.build_automation(trigger, std_string, conf_)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_PN532'
|
||||
|
|
|
@ -341,6 +341,7 @@ CONF_DAYS_OF_WEEK = 'days_of_week'
|
|||
CONF_CRON = 'cron'
|
||||
CONF_POWER_SAVE_MODE = 'power_save_mode'
|
||||
CONF_POWER_ON_VALUE = 'power_on_value'
|
||||
CONF_ON_TAG = 'on_tag'
|
||||
|
||||
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
|
||||
ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'
|
||||
|
|
|
@ -878,6 +878,12 @@ status_led:
|
|||
pn532:
|
||||
cs_pin: GPIO23
|
||||
update_interval: 1s
|
||||
on_tag:
|
||||
- lambda: |-
|
||||
ESP_LOGD("main", "Found tag %s", x.c_str());
|
||||
- mqtt.publish:
|
||||
topic: the/topic
|
||||
payload: !lambda 'return x;'
|
||||
|
||||
rdm6300:
|
||||
|
||||
|
|
Loading…
Reference in a new issue