Add new time.has_time condition (#1255)

This commit is contained in:
Ash McKenzie
2020-10-05 02:22:28 +11:00
committed by GitHub
parent 002861f13b
commit 5c86f332b2
3 changed files with 22 additions and 1 deletions
+11 -1
View File
@@ -10,10 +10,11 @@ import tzlocal
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import automation
from esphome.const import CONF_CRON, CONF_DAYS_OF_MONTH, CONF_DAYS_OF_WEEK, CONF_HOURS, \
from esphome.const import CONF_ID, CONF_CRON, CONF_DAYS_OF_MONTH, CONF_DAYS_OF_WEEK, CONF_HOURS, \
CONF_MINUTES, CONF_MONTHS, CONF_ON_TIME, CONF_SECONDS, CONF_TIMEZONE, CONF_TRIGGER_ID, \
CONF_AT, CONF_SECOND, CONF_HOUR, CONF_MINUTE
from esphome.core import coroutine, coroutine_with_priority
from esphome.automation import Condition
_LOGGER = logging.getLogger(__name__)
@@ -24,6 +25,7 @@ time_ns = cg.esphome_ns.namespace('time')
RealTimeClock = time_ns.class_('RealTimeClock', cg.Component)
CronTrigger = time_ns.class_('CronTrigger', automation.Trigger.template(), cg.Component)
ESPTime = time_ns.struct('ESPTime')
TimeHasTimeCondition = time_ns.class_('TimeHasTimeCondition', Condition)
def _tz_timedelta(td):
@@ -328,3 +330,11 @@ def register_time(time_var, config):
def to_code(config):
cg.add_define('USE_TIME')
cg.add_global(time_ns.using)
@automation.register_condition('time.has_time', TimeHasTimeCondition, cv.Schema({
cv.GenerateID(): cv.use_id(RealTimeClock),
}))
def time_has_time_to_code(config, condition_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
yield cg.new_Pvariable(condition_id, template_arg, paren)