From 6b3c7b08546bfcfa684c16edabc4f7a4e391667e Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Thu, 24 Oct 2019 21:24:57 +0200 Subject: [PATCH] Fix scheduler first execution (#798) * Fix scheduler first execution not immediately * Also update sensor filters --- esphome/components/sensor/__init__.py | 2 +- esphome/core/scheduler.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/sensor/__init__.py b/esphome/components/sensor/__init__.py index 11a6e5e173..605f72a103 100644 --- a/esphome/components/sensor/__init__.py +++ b/esphome/components/sensor/__init__.py @@ -259,7 +259,7 @@ def setup_sensor_core_(var, config): if CONF_ACCURACY_DECIMALS in config: cg.add(var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS])) cg.add(var.set_force_update(config[CONF_FORCE_UPDATE])) - if CONF_FILTERS in config: + if config.get(CONF_FILTERS): # must exist and not be empty filters = yield build_filters(config[CONF_FILTERS]) cg.add(var.set_filters(filters)) diff --git a/esphome/core/scheduler.cpp b/esphome/core/scheduler.cpp index 3df886cb5b..88054147f8 100644 --- a/esphome/core/scheduler.cpp +++ b/esphome/core/scheduler.cpp @@ -57,7 +57,7 @@ void HOT Scheduler::set_interval(Component *component, const std::string &name, item->name = name; item->type = SchedulerItem::INTERVAL; item->interval = interval; - item->last_execution = now - offset; + item->last_execution = now - offset - interval; item->last_execution_major = this->millis_major_; if (item->last_execution > now) item->last_execution_major--; @@ -106,7 +106,7 @@ void ICACHE_RAM_ATTR HOT Scheduler::call() { // Not reached timeout yet, done for this call break; uint8_t major = item->last_execution_major; - if (item->last_execution + item->interval < item->last_execution) + if (item->last_execution > now) major++; if (major != this->millis_major_) break;