From 4cf7151fbe2d9356be85bfcc6db737e652d68d22 Mon Sep 17 00:00:00 2001 From: Senex Crenshaw Date: Sat, 10 Jul 2021 20:45:41 +0000 Subject: [PATCH] Removed dump_ran_ Cleaned up validation Removed App.feed_wdt() from process_nextion_commands_ --- esphome/components/nextion/base_component.py | 2 -- esphome/components/nextion/nextion.cpp | 8 ++----- esphome/components/nextion/nextion.h | 1 - esphome/components/nextion/sensor/__init__.py | 24 +++++++++++++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/esphome/components/nextion/base_component.py b/esphome/components/nextion/base_component.py index 61d0a12aeb71..3bf828aafa96 100644 --- a/esphome/components/nextion/base_component.py +++ b/esphome/components/nextion/base_component.py @@ -2,7 +2,6 @@ import esphome.config_validation as cv import esphome.codegen as cg from esphome.components import color -from esphome.core import coroutine from . import CONF_NEXTION_ID from . import Nextion @@ -92,7 +91,6 @@ def NextionName(value): ) -@coroutine async def setup_component_core_(var, config, arg): if CONF_VARIABLE_NAME in config: diff --git a/esphome/components/nextion/nextion.cpp b/esphome/components/nextion/nextion.cpp index 426c95d5eb39..9a5424917f85 100644 --- a/esphome/components/nextion/nextion.cpp +++ b/esphome/components/nextion/nextion.cpp @@ -114,10 +114,6 @@ void Nextion::reset_(bool reset_nextion) { } void Nextion::dump_config() { - if (!this->get_is_connected_() || this->dump_ran_) - return; - this->dump_ran_ = true; - ESP_LOGCONFIG(TAG, "Nextion:"); ESP_LOGCONFIG(TAG, " Device Model: %s", this->device_model_.c_str()); ESP_LOGCONFIG(TAG, " Firmware Version: %s", this->firmware_version_.c_str()); @@ -732,7 +728,7 @@ void Nextion::process_nextion_commands_() { // ESP_LOGN(TAG, "nextion_event_ deleting from 0 to %d", to_process_length + COMMAND_DELIMITER.length() + 1); this->command_data_.erase(0, to_process_length + COMMAND_DELIMITER.length() + 1); - App.feed_wdt(); + // App.feed_wdt(); Remove before master merge this->process_serial_(); } @@ -770,7 +766,7 @@ void Nextion::process_nextion_commands_() { } } ESP_LOGN(TAG, "Loop End"); - App.feed_wdt(); + // App.feed_wdt(); Remove before master merge this->process_serial_(); } // namespace nextion diff --git a/esphome/components/nextion/nextion.h b/esphome/components/nextion/nextion.h index 5666a8884a39..2389cc62350a 100644 --- a/esphome/components/nextion/nextion.h +++ b/esphome/components/nextion/nextion.h @@ -841,7 +841,6 @@ class Nextion : public NextionBase, public PollingComponent, public uart::UARTDe std::string command_data_; bool is_connected_ = false; - bool dump_ran_ = false; uint32_t startup_override_ms_ = 8000; uint32_t max_q_age_ms_ = 8000; uint32_t started_ms_ = 0; diff --git a/esphome/components/nextion/sensor/__init__.py b/esphome/components/nextion/sensor/__init__.py index dcd1889c7d29..f8a383e3ac6f 100644 --- a/esphome/components/nextion/sensor/__init__.py +++ b/esphome/components/nextion/sensor/__init__.py @@ -28,13 +28,30 @@ NextionSensor = nextion_ns.class_("NextionSensor", sensor.Sensor, cg.PollingComponent) + +def CheckWaveID(value): + value = cv.int_(value) + if value < 0 or value > 3: + raise cv.Invalid(f"Valid range for {CONF_WAVE_CHANNEL_ID} is 0-3") + return value + + +def _validate(config): + if CONF_WAVE_CHANNEL_ID in config and CONF_COMPONENT_ID not in config: + raise cv.Invalid( + f"{CONF_COMPONENT_ID} is required when {CONF_WAVE_CHANNEL_ID} is set" + ) + + return config + + CONFIG_SCHEMA = cv.All( sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 2, DEVICE_CLASS_EMPTY) .extend( { cv.GenerateID(): cv.declare_id(NextionSensor), cv.Optional(CONF_PRECISION, default=0): cv.int_range(min=0, max=8), - cv.Optional(CONF_WAVE_CHANNEL_ID): cv.int_range(min=0, max=3), + cv.Optional(CONF_WAVE_CHANNEL_ID): CheckWaveID, cv.Optional(CONF_COMPONENT_ID): cv.uint8_t, cv.Optional(CONF_WAVE_MAX_LENGTH, default=255): cv.int_range( min=1, max=1024 @@ -48,14 +65,11 @@ .extend(CONFIG_SENSOR_COMPONENT_SCHEMA) .extend(cv.polling_component_schema("never")), cv.has_exactly_one_key(CONF_COMPONENT_ID, CONF_COMPONENT_NAME, CONF_VARIABLE_NAME), + _validate, ) async def to_code(config): - if CONF_WAVE_CHANNEL_ID in config and CONF_COMPONENT_ID not in config: - raise cv.Invalid( - "{CONF_COMPONENT_ID} is required when {CONF_WAVE_CHANNEL_ID} is set" - ) hub = await cg.get_variable(config[CONF_NEXTION_ID]) var = cg.new_Pvariable(config[CONF_ID], hub)