mirror of
https://github.com/esphome/esphome.git
synced 2025-11-15 14:25:45 +00:00
Compare commits
36 Commits
2021.12.0b
...
2021.12.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db3b955b0f | ||
|
|
5516f65971 | ||
|
|
9471df0a1b | ||
|
|
6d39f64be7 | ||
|
|
b89d0a9a73 | ||
|
|
4bb779d9a5 | ||
|
|
386a5b6362 | ||
|
|
e32a999cd0 | ||
|
|
bfbc6a4bad | ||
|
|
8c9e0e552d | ||
|
|
8aaf9fd83f | ||
|
|
08057720b8 | ||
|
|
bfaa648837 | ||
|
|
d504daef91 | ||
|
|
b8d3ef2f49 | ||
|
|
3bf6320030 | ||
|
|
708b928c73 | ||
|
|
649366ff44 | ||
|
|
e5c9e87fad | ||
|
|
f3d9d707b6 | ||
|
|
090e10730c | ||
|
|
fbc84861c7 | ||
|
|
e763469af8 | ||
|
|
3c0c514e44 | ||
|
|
ed5e2dd332 | ||
|
|
09b7c6f550 | ||
|
|
df315a1f51 | ||
|
|
7ee4bb621c | ||
|
|
24874f4c3c | ||
|
|
c128880033 | ||
|
|
a66e94a0b0 | ||
|
|
56870ed4a8 | ||
|
|
3ac720df47 | ||
|
|
1bc757ad06 | ||
|
|
f72abc6f3d | ||
|
|
5ac88de985 |
@@ -91,7 +91,7 @@ void ADCSensor::dump_config() {
|
||||
float ADCSensor::get_setup_priority() const { return setup_priority::DATA; }
|
||||
void ADCSensor::update() {
|
||||
float value_v = this->sample();
|
||||
ESP_LOGD(TAG, "'%s': Got voltage=%.4fV", this->get_name().c_str(), value_v);
|
||||
ESP_LOGV(TAG, "'%s': Got voltage=%.4fV", this->get_name().c_str(), value_v);
|
||||
this->publish_state(value_v);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,12 +29,11 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
}
|
||||
)
|
||||
|
||||
WIFI_MESSAGE = """
|
||||
WIFI_CONFIG = """
|
||||
|
||||
# Do not forget to add your own wifi configuration before installing this configuration
|
||||
# wifi:
|
||||
# ssid: !secret wifi_ssid
|
||||
# password: !secret wifi_password
|
||||
wifi:
|
||||
ssid: !secret wifi_ssid
|
||||
password: !secret wifi_password
|
||||
"""
|
||||
|
||||
|
||||
@@ -55,6 +54,6 @@ def import_config(path: str, name: str, project_name: str, import_url: str) -> N
|
||||
"esphome": {"name_add_mac_suffix": False},
|
||||
}
|
||||
p.write_text(
|
||||
dump(config) + WIFI_MESSAGE,
|
||||
dump(config) + WIFI_CONFIG,
|
||||
encoding="utf8",
|
||||
)
|
||||
|
||||
@@ -42,11 +42,11 @@ void arch_init() {
|
||||
// Idle task watchdog is disabled on ESP-IDF
|
||||
#elif defined(USE_ARDUINO)
|
||||
enableLoopWDT();
|
||||
// Disable idle task watchdog on the core we're using (Arduino pins the process to a core)
|
||||
#if CONFIG_ARDUINO_RUNNING_CORE == 0
|
||||
// Disable idle task watchdog on the core we're using (Arduino pins the task to a core)
|
||||
#if defined(CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU0) && CONFIG_ARDUINO_RUNNING_CORE == 0
|
||||
disableCore0WDT();
|
||||
#endif
|
||||
#if CONFIG_ARDUINO_RUNNING_CORE == 1
|
||||
#if defined(CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1) && CONFIG_ARDUINO_RUNNING_CORE == 1
|
||||
disableCore1WDT();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -184,7 +184,9 @@ void EthernetComponent::start_connect_() {
|
||||
}
|
||||
|
||||
err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH);
|
||||
ESPHL_ERROR_CHECK(err, "DHCPC stop error");
|
||||
if (err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) {
|
||||
ESPHL_ERROR_CHECK(err, "DHCPC stop error");
|
||||
}
|
||||
err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &info);
|
||||
ESPHL_ERROR_CHECK(err, "DHCPC set IP info error");
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ void MCP23X17Base::pin_mode(uint8_t pin, gpio::Flags flags) {
|
||||
uint8_t gppu = pin < 8 ? mcp23x17_base::MCP23X17_GPPUA : mcp23x17_base::MCP23X17_GPPUB;
|
||||
if (flags == gpio::FLAG_INPUT) {
|
||||
this->update_reg(pin, true, iodir);
|
||||
this->update_reg(pin, false, gppu);
|
||||
} else if (flags == (gpio::FLAG_INPUT | gpio::FLAG_PULLUP)) {
|
||||
this->update_reg(pin, true, iodir);
|
||||
this->update_reg(pin, true, gppu);
|
||||
|
||||
@@ -10,5 +10,6 @@ CONF_REGISTER_COUNT = "register_count"
|
||||
CONF_REGISTER_TYPE = "register_type"
|
||||
CONF_RESPONSE_SIZE = "response_size"
|
||||
CONF_SKIP_UPDATES = "skip_updates"
|
||||
CONF_USE_WRITE_MULTIPLE = "use_write_multiple"
|
||||
CONF_VALUE_TYPE = "value_type"
|
||||
CONF_WRITE_LAMBDA = "write_lambda"
|
||||
|
||||
@@ -25,6 +25,7 @@ from ..const import (
|
||||
CONF_FORCE_NEW_RANGE,
|
||||
CONF_MODBUS_CONTROLLER_ID,
|
||||
CONF_SKIP_UPDATES,
|
||||
CONF_USE_WRITE_MULTIPLE,
|
||||
CONF_VALUE_TYPE,
|
||||
CONF_WRITE_LAMBDA,
|
||||
)
|
||||
@@ -69,6 +70,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.Optional(CONF_MIN_VALUE, default=-16777215.0): cv.float_,
|
||||
cv.Optional(CONF_STEP, default=1): cv.positive_float,
|
||||
cv.Optional(CONF_MULTIPLY, default=1.0): cv.float_,
|
||||
cv.Optional(CONF_USE_WRITE_MULTIPLE, default=False): cv.boolean,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s")),
|
||||
@@ -105,6 +107,7 @@ async def to_code(config):
|
||||
cg.add(var.set_parent(parent))
|
||||
cg.add(parent.add_sensor_item(var))
|
||||
await add_modbus_base_properties(var, config, ModbusNumber)
|
||||
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
|
||||
if CONF_WRITE_LAMBDA in config:
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_WRITE_LAMBDA],
|
||||
|
||||
@@ -27,6 +27,7 @@ void ModbusNumber::parse_and_publish(const std::vector<uint8_t> &data) {
|
||||
|
||||
void ModbusNumber::control(float value) {
|
||||
std::vector<uint16_t> data;
|
||||
float write_value = value;
|
||||
// Is there are lambda configured?
|
||||
if (this->write_transform_func_.has_value()) {
|
||||
// data is passed by reference
|
||||
@@ -35,28 +36,32 @@ void ModbusNumber::control(float value) {
|
||||
auto val = (*this->write_transform_func_)(this, value, data);
|
||||
if (val.has_value()) {
|
||||
ESP_LOGV(TAG, "Value overwritten by lambda");
|
||||
value = val.value();
|
||||
write_value = val.value();
|
||||
} else {
|
||||
ESP_LOGV(TAG, "Communication handled by lambda - exiting control");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
value = multiply_by_ * value;
|
||||
write_value = multiply_by_ * write_value;
|
||||
}
|
||||
|
||||
// lambda didn't set payload
|
||||
if (data.empty()) {
|
||||
data = float_to_payload(value, this->sensor_value_type);
|
||||
data = float_to_payload(write_value, this->sensor_value_type);
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG,
|
||||
"Updating register: connected Sensor=%s start address=0x%X register count=%d new value=%.02f (val=%.02f)",
|
||||
this->get_name().c_str(), this->start_address, this->register_count, value, value);
|
||||
this->get_name().c_str(), this->start_address, this->register_count, write_value, write_value);
|
||||
|
||||
// Create and send the write command
|
||||
auto write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
|
||||
this->register_count, data);
|
||||
|
||||
ModbusCommandItem write_cmd;
|
||||
if (this->register_count == 1 && !this->use_write_multiple_) {
|
||||
write_cmd = ModbusCommandItem::create_write_single_command(parent_, this->start_address + this->offset, data[0]);
|
||||
} else {
|
||||
write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
|
||||
this->register_count, data);
|
||||
}
|
||||
// publish new value
|
||||
write_cmd.on_data_func = [this, write_cmd, value](ModbusRegisterType register_type, uint16_t start_address,
|
||||
const std::vector<uint8_t> &data) {
|
||||
|
||||
@@ -35,6 +35,7 @@ class ModbusNumber : public number::Number, public Component, public SensorItem
|
||||
using write_transform_func_t = std::function<optional<float>(ModbusNumber *, float, std::vector<uint16_t> &)>;
|
||||
void set_template(transform_func_t &&f) { this->transform_func_ = f; }
|
||||
void set_write_template(write_transform_func_t &&f) { this->write_transform_func_ = f; }
|
||||
void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
|
||||
|
||||
protected:
|
||||
void control(float value) override;
|
||||
@@ -42,6 +43,7 @@ class ModbusNumber : public number::Number, public Component, public SensorItem
|
||||
optional<write_transform_func_t> write_transform_func_;
|
||||
ModbusController *parent_;
|
||||
float multiply_by_{1.0};
|
||||
bool use_write_multiple_{false};
|
||||
};
|
||||
|
||||
} // namespace modbus_controller
|
||||
|
||||
@@ -18,6 +18,7 @@ from .. import (
|
||||
|
||||
from ..const import (
|
||||
CONF_MODBUS_CONTROLLER_ID,
|
||||
CONF_USE_WRITE_MULTIPLE,
|
||||
CONF_VALUE_TYPE,
|
||||
CONF_WRITE_LAMBDA,
|
||||
)
|
||||
@@ -36,6 +37,7 @@ CONFIG_SCHEMA = cv.All(
|
||||
cv.GenerateID(): cv.declare_id(ModbusOutput),
|
||||
cv.Optional(CONF_WRITE_LAMBDA): cv.returning_lambda,
|
||||
cv.Optional(CONF_MULTIPLY, default=1.0): cv.float_,
|
||||
cv.Optional(CONF_USE_WRITE_MULTIPLE, default=False): cv.boolean,
|
||||
}
|
||||
),
|
||||
validate_modbus_register,
|
||||
@@ -54,6 +56,7 @@ async def to_code(config):
|
||||
await output.register_output(var, config)
|
||||
cg.add(var.set_write_multiply(config[CONF_MULTIPLY]))
|
||||
parent = await cg.get_variable(config[CONF_MODBUS_CONTROLLER_ID])
|
||||
cg.add(var.set_use_write_mutiple(config[CONF_USE_WRITE_MULTIPLE]))
|
||||
cg.add(var.set_parent(parent))
|
||||
if CONF_WRITE_LAMBDA in config:
|
||||
template_ = await cg.process_lambda(
|
||||
|
||||
@@ -40,8 +40,14 @@ void ModbusOutput::write_state(float value) {
|
||||
this->start_address, this->register_count, value, original_value);
|
||||
|
||||
// Create and send the write command
|
||||
auto write_cmd =
|
||||
ModbusCommandItem::create_write_multiple_command(parent_, this->start_address, this->register_count, data);
|
||||
// Create and send the write command
|
||||
ModbusCommandItem write_cmd;
|
||||
if (this->register_count == 1 && !this->use_write_multiple_) {
|
||||
write_cmd = ModbusCommandItem::create_write_single_command(parent_, this->start_address + this->offset, data[0]);
|
||||
} else {
|
||||
write_cmd = ModbusCommandItem::create_write_multiple_command(parent_, this->start_address + this->offset,
|
||||
this->register_count, data);
|
||||
}
|
||||
parent_->queue_command(write_cmd);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ class ModbusOutput : public output::FloatOutput, public Component, public Sensor
|
||||
|
||||
using write_transform_func_t = std::function<optional<float>(ModbusOutput *, float, std::vector<uint16_t> &)>;
|
||||
void set_write_template(write_transform_func_t &&f) { this->write_transform_func_ = f; }
|
||||
void set_use_write_mutiple(bool use_write_multiple) { this->use_write_multiple_ = use_write_multiple; }
|
||||
|
||||
protected:
|
||||
void write_state(float value) override;
|
||||
@@ -40,6 +41,7 @@ class ModbusOutput : public output::FloatOutput, public Component, public Sensor
|
||||
|
||||
ModbusController *parent_;
|
||||
float multiply_by_{1.0};
|
||||
bool use_write_multiple_;
|
||||
};
|
||||
|
||||
} // namespace modbus_controller
|
||||
|
||||
@@ -18,10 +18,10 @@ from ..const import (
|
||||
CONF_FORCE_NEW_RANGE,
|
||||
CONF_MODBUS_CONTROLLER_ID,
|
||||
CONF_REGISTER_TYPE,
|
||||
CONF_USE_WRITE_MULTIPLE,
|
||||
CONF_WRITE_LAMBDA,
|
||||
)
|
||||
|
||||
CONF_USE_WRITE_MULTIPLE = "use_write_multiple"
|
||||
DEPENDENCIES = ["modbus_controller"]
|
||||
CODEOWNERS = ["@martgras"]
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ MQTTButtonComponent::MQTTButtonComponent(button::Button *button) : MQTTComponent
|
||||
|
||||
void MQTTButtonComponent::setup() {
|
||||
this->subscribe(this->get_command_topic_(), [this](const std::string &topic, const std::string &payload) {
|
||||
if (payload == "press") {
|
||||
if (payload == "PRESS") {
|
||||
this->button_->press();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "'%s': Received unknown status payload: %s", this->friendly_name().c_str(), payload.c_str());
|
||||
@@ -31,6 +31,7 @@ void MQTTButtonComponent::dump_config() {
|
||||
}
|
||||
|
||||
void MQTTButtonComponent::send_discovery(JsonObject &root, mqtt::SendDiscoveryConfig &config) {
|
||||
config.state_topic = false;
|
||||
if (!this->button_->get_device_class().empty())
|
||||
root[MQTT_DEVICE_CLASS] = this->button_->get_device_class();
|
||||
}
|
||||
|
||||
@@ -372,6 +372,7 @@ bool OTAComponent::readall_(uint8_t *buf, size_t len) {
|
||||
ssize_t read = this->client_->read(buf + at, len - at);
|
||||
if (read == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
App.feed_wdt();
|
||||
delay(1);
|
||||
continue;
|
||||
}
|
||||
@@ -383,6 +384,7 @@ bool OTAComponent::readall_(uint8_t *buf, size_t len) {
|
||||
} else {
|
||||
at += read;
|
||||
}
|
||||
App.feed_wdt();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
@@ -401,6 +403,7 @@ bool OTAComponent::writeall_(const uint8_t *buf, size_t len) {
|
||||
ssize_t written = this->client_->write(buf + at, len - at);
|
||||
if (written == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
App.feed_wdt();
|
||||
delay(1);
|
||||
continue;
|
||||
}
|
||||
@@ -409,6 +412,7 @@ bool OTAComponent::writeall_(const uint8_t *buf, size_t len) {
|
||||
} else {
|
||||
at += written;
|
||||
}
|
||||
App.feed_wdt();
|
||||
delay(1);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -32,14 +32,11 @@ void SPS30Component::setup() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t raw_firmware_version[4];
|
||||
if (!this->read_data_(raw_firmware_version, 4)) {
|
||||
if (!this->read_data_(&raw_firmware_version_, 1)) {
|
||||
this->error_code_ = FIRMWARE_VERSION_READ_FAILED;
|
||||
this->mark_failed();
|
||||
return;
|
||||
}
|
||||
ESP_LOGD(TAG, " Firmware version v%0d.%02d", (raw_firmware_version[0] >> 8),
|
||||
uint16_t(raw_firmware_version[0] & 0xFF));
|
||||
/// Serial number identification
|
||||
if (!this->write_command_(SPS30_CMD_GET_SERIAL_NUMBER)) {
|
||||
this->error_code_ = SERIAL_NUMBER_REQUEST_FAILED;
|
||||
@@ -59,6 +56,8 @@ void SPS30Component::setup() {
|
||||
this->serial_number_[i * 2 + 1] = uint16_t(uint16_t(raw_serial_number[i] & 0xFF));
|
||||
}
|
||||
ESP_LOGD(TAG, " Serial Number: '%s'", this->serial_number_);
|
||||
this->status_clear_warning();
|
||||
this->skipped_data_read_cycles_ = 0;
|
||||
this->start_continuous_measurement_();
|
||||
});
|
||||
}
|
||||
@@ -93,10 +92,17 @@ void SPS30Component::dump_config() {
|
||||
}
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
ESP_LOGCONFIG(TAG, " Serial Number: '%s'", this->serial_number_);
|
||||
LOG_SENSOR(" ", "PM1.0", this->pm_1_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM2.5", this->pm_2_5_sensor_);
|
||||
LOG_SENSOR(" ", "PM4", this->pm_4_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM10", this->pm_10_0_sensor_);
|
||||
ESP_LOGCONFIG(TAG, " Firmware version v%0d.%0d", (raw_firmware_version_ >> 8),
|
||||
uint16_t(raw_firmware_version_ & 0xFF));
|
||||
LOG_SENSOR(" ", "PM1.0 Weight Concentration", this->pm_1_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM2.5 Weight Concentration", this->pm_2_5_sensor_);
|
||||
LOG_SENSOR(" ", "PM4 Weight Concentration", this->pm_4_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM10 Weight Concentration", this->pm_10_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM1.0 Number Concentration", this->pmc_1_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM2.5 Number Concentration", this->pmc_2_5_sensor_);
|
||||
LOG_SENSOR(" ", "PM4 Number Concentration", this->pmc_4_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM10 Number Concentration", this->pmc_10_0_sensor_);
|
||||
LOG_SENSOR(" ", "PM typical size", this->pm_size_sensor_);
|
||||
}
|
||||
|
||||
void SPS30Component::update() {
|
||||
@@ -123,8 +129,8 @@ void SPS30Component::update() {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t raw_read_status[1];
|
||||
if (!this->read_data_(raw_read_status, 1) || raw_read_status[0] == 0x00) {
|
||||
uint16_t raw_read_status;
|
||||
if (!this->read_data_(&raw_read_status, 1) || raw_read_status == 0x00) {
|
||||
ESP_LOGD(TAG, "Sensor measurement not ready yet.");
|
||||
this->skipped_data_read_cycles_++;
|
||||
/// The following logic is required to address the cases when a sensor is quickly replaced before it's marked
|
||||
|
||||
@@ -33,6 +33,7 @@ class SPS30Component : public PollingComponent, public i2c::I2CDevice {
|
||||
bool read_data_(uint16_t *data, uint8_t len);
|
||||
uint8_t sht_crc_(uint8_t data1, uint8_t data2);
|
||||
char serial_number_[17] = {0}; /// Terminating NULL character
|
||||
uint16_t raw_firmware_version_;
|
||||
bool start_continuous_measurement_();
|
||||
uint8_t skipped_data_read_cycles_ = 0;
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ void TextSensor::add_on_raw_state_callback(std::function<void(std::string)> call
|
||||
std::string TextSensor::get_state() const { return this->state; }
|
||||
std::string TextSensor::get_raw_state() const { return this->raw_state; }
|
||||
void TextSensor::internal_send_state_to_frontend(const std::string &state) {
|
||||
this->state = this->raw_state;
|
||||
this->state = state;
|
||||
this->has_state_ = true;
|
||||
ESP_LOGD(TAG, "'%s': Sending state '%s'", this->name_.c_str(), state.c_str());
|
||||
this->callback_.call(state);
|
||||
|
||||
@@ -431,7 +431,8 @@ async def to_code(config):
|
||||
|
||||
heat_cool_mode_available = CONF_HEAT_ACTION in config and CONF_COOL_ACTION in config
|
||||
two_points_available = CONF_HEAT_ACTION in config and (
|
||||
CONF_COOL_ACTION in config or CONF_FAN_ONLY_ACTION in config
|
||||
CONF_COOL_ACTION in config
|
||||
or (config[CONF_FAN_ONLY_COOLING] and CONF_FAN_ONLY_ACTION in config)
|
||||
)
|
||||
|
||||
sens = await cg.get_variable(config[CONF_SENSOR])
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "tlc59208f_output.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/hal.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tlc59208f {
|
||||
|
||||
@@ -390,8 +390,6 @@ void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlM
|
||||
#ifdef USE_BUTTON
|
||||
void WebServer::handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match) {
|
||||
for (button::Button *obj : App.get_buttons()) {
|
||||
if (obj->is_internal())
|
||||
continue;
|
||||
if (obj->get_object_id() != match.id)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Constants used by esphome."""
|
||||
|
||||
__version__ = "2021.12.0b2"
|
||||
__version__ = "2021.12.2"
|
||||
|
||||
ALLOWED_NAME_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789-_"
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ void Application::setup() {
|
||||
|
||||
component->call();
|
||||
this->scheduler.process_to_add();
|
||||
this->feed_wdt();
|
||||
if (component->can_proceed())
|
||||
continue;
|
||||
|
||||
@@ -46,14 +47,15 @@ void Application::setup() {
|
||||
do {
|
||||
uint32_t new_app_state = STATUS_LED_WARNING;
|
||||
this->scheduler.call();
|
||||
this->feed_wdt();
|
||||
for (uint32_t j = 0; j <= i; j++) {
|
||||
this->components_[j]->call();
|
||||
new_app_state |= this->components_[j]->get_component_state();
|
||||
this->app_state_ |= new_app_state;
|
||||
this->feed_wdt();
|
||||
}
|
||||
this->app_state_ = new_app_state;
|
||||
yield();
|
||||
this->feed_wdt();
|
||||
} while (!component->can_proceed());
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ void Application::loop() {
|
||||
uint32_t new_app_state = 0;
|
||||
|
||||
this->scheduler.call();
|
||||
this->feed_wdt();
|
||||
for (Component *component : this->looping_components_) {
|
||||
{
|
||||
WarnIfComponentBlockingGuard guard{component};
|
||||
|
||||
@@ -27,7 +27,7 @@ import tornado.process
|
||||
import tornado.web
|
||||
import tornado.websocket
|
||||
|
||||
from esphome import const, platformio_api, util
|
||||
from esphome import const, platformio_api, util, yaml_util
|
||||
from esphome.helpers import mkdir_p, get_bool_env, run_system_command
|
||||
from esphome.storage_json import (
|
||||
EsphomeStorageJSON,
|
||||
@@ -836,6 +836,28 @@ class LogoutHandler(BaseHandler):
|
||||
self.redirect("./login")
|
||||
|
||||
|
||||
class SecretKeysRequestHandler(BaseHandler):
|
||||
@authenticated
|
||||
def get(self):
|
||||
|
||||
filename = None
|
||||
|
||||
for secret_filename in const.SECRETS_FILES:
|
||||
relative_filename = settings.rel_path(secret_filename)
|
||||
if os.path.isfile(relative_filename):
|
||||
filename = relative_filename
|
||||
break
|
||||
|
||||
if filename is None:
|
||||
self.send_error(404)
|
||||
return
|
||||
|
||||
secret_keys = list(yaml_util.load_yaml(filename, clear_secrets=False))
|
||||
|
||||
self.set_header("content-type", "application/json")
|
||||
self.write(json.dumps(secret_keys))
|
||||
|
||||
|
||||
def get_base_frontend_path():
|
||||
if ENV_DEV not in os.environ:
|
||||
import esphome_dashboard
|
||||
@@ -939,6 +961,7 @@ def make_app(debug=get_bool_env(ENV_DEV)):
|
||||
(f"{rel}static/(.*)", StaticFileHandler, {"path": get_static_path()}),
|
||||
(f"{rel}devices", ListDevicesHandler),
|
||||
(f"{rel}import", ImportRequestHandler),
|
||||
(f"{rel}secret_keys", SecretKeysRequestHandler),
|
||||
],
|
||||
**app_settings,
|
||||
)
|
||||
|
||||
@@ -45,9 +45,9 @@ OTA_BIG = r""" ____ _______
|
||||
|
||||
BASE_CONFIG = """esphome:
|
||||
name: {name}
|
||||
platform: {platform}
|
||||
board: {board}
|
||||
"""
|
||||
|
||||
LOGGER_API_CONFIG = """
|
||||
# Enable logging
|
||||
logger:
|
||||
|
||||
@@ -55,6 +55,18 @@ logger:
|
||||
api:
|
||||
"""
|
||||
|
||||
ESP8266_CONFIG = """
|
||||
esp8266:
|
||||
board: {board}
|
||||
"""
|
||||
|
||||
ESP32_CONFIG = """
|
||||
esp32:
|
||||
board: {board}
|
||||
framework:
|
||||
type: arduino
|
||||
"""
|
||||
|
||||
|
||||
def sanitize_double_quotes(value):
|
||||
return value.replace("\\", "\\\\").replace('"', '\\"')
|
||||
@@ -71,6 +83,14 @@ def wizard_file(**kwargs):
|
||||
|
||||
config = BASE_CONFIG.format(**kwargs)
|
||||
|
||||
config += (
|
||||
ESP8266_CONFIG.format(**kwargs)
|
||||
if kwargs["platform"] == "ESP8266"
|
||||
else ESP32_CONFIG.format(**kwargs)
|
||||
)
|
||||
|
||||
config += LOGGER_API_CONFIG
|
||||
|
||||
# Configure API
|
||||
if "password" in kwargs:
|
||||
config += f" password: \"{kwargs['password']}\"\n"
|
||||
@@ -86,12 +106,11 @@ def wizard_file(**kwargs):
|
||||
config += "\n\nwifi:\n"
|
||||
|
||||
if "ssid" in kwargs:
|
||||
# pylint: disable=consider-using-f-string
|
||||
config += """ ssid: "{ssid}"
|
||||
password: "{psk}"
|
||||
""".format(
|
||||
**kwargs
|
||||
)
|
||||
if kwargs["ssid"].startswith("!secret"):
|
||||
template = " ssid: {ssid}\n password: {psk}\n"
|
||||
else:
|
||||
template = """ ssid: "{ssid}"\n password: "{psk}"\n"""
|
||||
config += template.format(**kwargs)
|
||||
else:
|
||||
config += """ # ssid: "My SSID"
|
||||
# password: "mypassword"
|
||||
|
||||
@@ -329,9 +329,10 @@ ESPHomeLoader.add_constructor("!lambda", ESPHomeLoader.construct_lambda)
|
||||
ESPHomeLoader.add_constructor("!force", ESPHomeLoader.construct_force)
|
||||
|
||||
|
||||
def load_yaml(fname):
|
||||
_SECRET_VALUES.clear()
|
||||
_SECRET_CACHE.clear()
|
||||
def load_yaml(fname, clear_secrets=True):
|
||||
if clear_secrets:
|
||||
_SECRET_VALUES.clear()
|
||||
_SECRET_CACHE.clear()
|
||||
return _load_yaml_internal(fname)
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ pyserial==3.5
|
||||
platformio==5.2.2 # When updating platformio, also update Dockerfile
|
||||
esptool==3.2
|
||||
click==8.0.3
|
||||
esphome-dashboard==20211201.0
|
||||
esphome-dashboard==20211211.0
|
||||
aioesphomeapi==10.6.0
|
||||
zeroconf==0.36.13
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def default_config():
|
||||
return {
|
||||
"name": "test-name",
|
||||
"platform": "test_platform",
|
||||
"board": "test_board",
|
||||
"board": "esp01_1m",
|
||||
"ssid": "test_ssid",
|
||||
"psk": "test_psk",
|
||||
"password": "",
|
||||
@@ -105,6 +105,7 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||
If the platform is not explicitly set, use "ESP8266" if the board is one of the ESP8266 boards
|
||||
"""
|
||||
# Given
|
||||
del default_config["platform"]
|
||||
monkeypatch.setattr(wz, "write_file", MagicMock())
|
||||
|
||||
# When
|
||||
@@ -112,7 +113,7 @@ def test_wizard_write_sets_platform(default_config, tmp_path, monkeypatch):
|
||||
|
||||
# Then
|
||||
generated_config = wz.write_file.call_args.args[1]
|
||||
assert f"platform: {default_config['platform']}" in generated_config
|
||||
assert "esp8266:" in generated_config
|
||||
|
||||
|
||||
def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||
@@ -132,7 +133,7 @@ def test_wizard_write_defaults_platform_from_board_esp8266(
|
||||
|
||||
# Then
|
||||
generated_config = wz.write_file.call_args.args[1]
|
||||
assert "platform: ESP8266" in generated_config
|
||||
assert "esp8266:" in generated_config
|
||||
|
||||
|
||||
def test_wizard_write_defaults_platform_from_board_esp32(
|
||||
@@ -152,7 +153,7 @@ def test_wizard_write_defaults_platform_from_board_esp32(
|
||||
|
||||
# Then
|
||||
generated_config = wz.write_file.call_args.args[1]
|
||||
assert "platform: ESP32" in generated_config
|
||||
assert "esp32:" in generated_config
|
||||
|
||||
|
||||
def test_safe_print_step_prints_step_number_and_description(monkeypatch):
|
||||
|
||||
Reference in New Issue
Block a user