From 81bc40034076ad0979d91a1cc211f0d5a797db77 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Wed, 17 Oct 2018 21:29:44 +0200 Subject: [PATCH] Add PN532 On Tag Trigger (#189) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add PN532 On Tag Trigger * Lint * Fix 😶 * Fix --- esphomeyaml/components/pn532.py | 17 +++++++++++++---- esphomeyaml/const.py | 1 + tests/test1.yaml | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/esphomeyaml/components/pn532.py b/esphomeyaml/components/pn532.py index 68dc52ab90..f59d08b161 100644 --- a/esphomeyaml/components/pn532.py +++ b/esphomeyaml/components/pn532.py @@ -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' diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index 23dc55cd2a..7ae8ffe243 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -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' diff --git a/tests/test1.yaml b/tests/test1.yaml index 27050e3892..6bf1a6cdfa 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -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: