Skip to content

Commit

Permalink
Removed dump_ran_
Browse files Browse the repository at this point in the history
Cleaned up validation
Removed App.feed_wdt() from process_nextion_commands_
  • Loading branch information
SenexCrenshaw committed Jul 10, 2021
1 parent f6a87eb commit 4cf7151
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
2 changes: 0 additions & 2 deletions esphome/components/nextion/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +91,6 @@ def NextionName(value):
)


@coroutine
async def setup_component_core_(var, config, arg):

if CONF_VARIABLE_NAME in config:
Expand Down
8 changes: 2 additions & 6 deletions esphome/components/nextion/nextion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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_();
}

Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion esphome/components/nextion/nextion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 19 additions & 5 deletions esphome/components/nextion/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 4cf7151

Please sign in to comment.