2018-12-18 19:31:43 +01:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from esphomeyaml import automation
|
|
|
|
import esphomeyaml.config_validation as cv
|
2019-01-02 16:49:26 +01:00
|
|
|
from esphomeyaml.const import CONF_ID, CONF_INTERVAL
|
2018-12-18 19:31:43 +01:00
|
|
|
from esphomeyaml.cpp_generator import Pvariable
|
|
|
|
from esphomeyaml.cpp_helpers import setup_component
|
|
|
|
from esphomeyaml.cpp_types import App, NoArg, PollingComponent, Trigger, esphomelib_ns
|
|
|
|
|
|
|
|
IntervalTrigger = esphomelib_ns.class_('IntervalTrigger', Trigger.template(NoArg), PollingComponent)
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = automation.validate_automation(vol.Schema({
|
2019-01-09 15:18:54 +01:00
|
|
|
cv.GenerateID(): cv.declare_variable_id(IntervalTrigger),
|
2019-01-02 16:49:26 +01:00
|
|
|
vol.Required(CONF_INTERVAL): cv.positive_time_period_milliseconds,
|
2018-12-18 19:31:43 +01:00
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema))
|
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
|
|
|
for conf in config:
|
2019-01-09 15:18:54 +01:00
|
|
|
rhs = App.register_component(IntervalTrigger.new(conf[CONF_INTERVAL]))
|
2018-12-18 19:31:43 +01:00
|
|
|
trigger = Pvariable(conf[CONF_ID], rhs)
|
|
|
|
setup_component(trigger, conf)
|
|
|
|
|
|
|
|
automation.build_automation(trigger, NoArg, conf)
|