aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorKaufHA <[email protected]>2021-12-14 15:21:15 -0700
committerGitHub <[email protected]>2021-12-14 15:21:15 -0700
commitbe984af8dacc0b80db3eea34e9bc0c61d582186d (patch)
treee048a0b2b97764437978f79fbb8e48e0c938676b
parent0c2e7e6f6a802f2f9e2fa0e349fb39a655c7a223 (diff)
downloadPLF10-be984af8dacc0b80db3eea34e9bc0c61d582186d.tar.gz
PLF10-be984af8dacc0b80db3eea34e9bc0c61d582186d.zip
v1.82 external components
-rw-r--r--components/captive_portal/captive_portal.cpp9
-rw-r--r--components/esp8266/boards.py58
-rw-r--r--components/esp8266/core.cpp3
-rw-r--r--components/esp8266/gpio.cpp2
-rw-r--r--components/esp8266/preferences.cpp4
-rw-r--r--components/web_server/__init__.py3
-rw-r--r--components/web_server/web_server.cpp172
-rw-r--r--components/web_server/web_server.h12
-rw-r--r--components/web_server_base/web_server_base.cpp6
-rw-r--r--components/wifi/__init__.py19
-rw-r--r--components/wifi/wifi_component_esp_idf.cpp12
11 files changed, 136 insertions, 164 deletions
diff --git a/components/captive_portal/captive_portal.cpp b/components/captive_portal/captive_portal.cpp
index 07a809f..fb1557b 100644
--- a/components/captive_portal/captive_portal.cpp
+++ b/components/captive_portal/captive_portal.cpp
@@ -93,14 +93,7 @@ void CaptivePortal::start() {
this->dns_server_->start(53, "*", (uint32_t) ip);
this->base_->get_server()->onNotFound([this](AsyncWebServerRequest *req) {
- bool not_found = false;
- if (!this->active_) {
- not_found = true;
- } else if (req->host().c_str() == wifi::global_wifi_component->wifi_soft_ap_ip().str()) {
- not_found = true;
- }
-
- if (not_found) {
+ if (!this->active_ || req->host().c_str() == wifi::global_wifi_component->wifi_soft_ap_ip().str()) {
req->send(404, "text/html", "File not found");
return;
}
diff --git a/components/esp8266/boards.py b/components/esp8266/boards.py
index c49aae4..410e934 100644
--- a/components/esp8266/boards.py
+++ b/components/esp8266/boards.py
@@ -206,61 +206,3 @@ ESP8266_BOARD_PINS = {
"wio_node": {"LED": 2, "GROVE": 15, "D0": 3, "D1": 5, "BUTTON": 0},
"xinabox_cw01": {"SDA": 2, "SCL": 14, "LED": 5, "LED_RED": 12, "LED_GREEN": 13},
}
-
-FLASH_SIZE_1_MB = 2 ** 20
-FLASH_SIZE_512_KB = FLASH_SIZE_1_MB // 2
-FLASH_SIZE_2_MB = 2 * FLASH_SIZE_1_MB
-FLASH_SIZE_4_MB = 4 * FLASH_SIZE_1_MB
-FLASH_SIZE_16_MB = 16 * FLASH_SIZE_1_MB
-
-ESP8266_FLASH_SIZES = {
- "d1": FLASH_SIZE_4_MB,
- "d1_mini": FLASH_SIZE_4_MB,
- "d1_mini_lite": FLASH_SIZE_1_MB,
- "d1_mini_pro": FLASH_SIZE_16_MB,
- "esp01": FLASH_SIZE_512_KB,
- "esp01_1m": FLASH_SIZE_1_MB,
- "esp07": FLASH_SIZE_4_MB,
- "esp12e": FLASH_SIZE_4_MB,
- "esp210": FLASH_SIZE_4_MB,
- "esp8285": FLASH_SIZE_1_MB,
- "esp_wroom_02": FLASH_SIZE_2_MB,
- "espduino": FLASH_SIZE_4_MB,
- "espectro": FLASH_SIZE_4_MB,
- "espino": FLASH_SIZE_4_MB,
- "espinotee": FLASH_SIZE_4_MB,
- "espmxdevkit": FLASH_SIZE_1_MB,
- "espresso_lite_v1": FLASH_SIZE_4_MB,
- "espresso_lite_v2": FLASH_SIZE_4_MB,
- "gen4iod": FLASH_SIZE_512_KB,
- "heltec_wifi_kit_8": FLASH_SIZE_4_MB,
- "huzzah": FLASH_SIZE_4_MB,
- "inventone": FLASH_SIZE_4_MB,
- "modwifi": FLASH_SIZE_2_MB,
- "nodemcu": FLASH_SIZE_4_MB,
- "nodemcuv2": FLASH_SIZE_4_MB,
- "oak": FLASH_SIZE_4_MB,
- "phoenix_v1": FLASH_SIZE_4_MB,
- "phoenix_v2": FLASH_SIZE_4_MB,
- "sonoff_basic": FLASH_SIZE_1_MB,
- "sonoff_s20": FLASH_SIZE_1_MB,
- "sonoff_sv": FLASH_SIZE_1_MB,
- "sonoff_th": FLASH_SIZE_1_MB,
- "sparkfunBlynk": FLASH_SIZE_4_MB,
- "thing": FLASH_SIZE_512_KB,
- "thingdev": FLASH_SIZE_512_KB,
- "wifi_slot": FLASH_SIZE_1_MB,
- "wifiduino": FLASH_SIZE_4_MB,
- "wifinfo": FLASH_SIZE_1_MB,
- "wio_link": FLASH_SIZE_4_MB,
- "wio_node": FLASH_SIZE_4_MB,
- "xinabox_cw01": FLASH_SIZE_4_MB,
-}
-
-ESP8266_LD_SCRIPTS = {
- FLASH_SIZE_512_KB: ("eagle.flash.512k0.ld", "eagle.flash.512k.ld"),
- FLASH_SIZE_1_MB: ("eagle.flash.1m0.ld", "eagle.flash.1m.ld"),
- FLASH_SIZE_2_MB: ("eagle.flash.2m.ld", "eagle.flash.2m.ld"),
- FLASH_SIZE_4_MB: ("eagle.flash.4m.ld", "eagle.flash.4m.ld"),
- FLASH_SIZE_16_MB: ("eagle.flash.16m.ld", "eagle.flash.16m14m.ld"),
-}
diff --git a/components/esp8266/core.cpp b/components/esp8266/core.cpp
index 51f3ca5..828d71a 100644
--- a/components/esp8266/core.cpp
+++ b/components/esp8266/core.cpp
@@ -20,6 +20,7 @@ void arch_restart() {
yield();
}
}
+void arch_init() {}
void IRAM_ATTR HOT arch_feed_wdt() {
ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance)
}
@@ -27,7 +28,7 @@ void IRAM_ATTR HOT arch_feed_wdt() {
uint8_t progmem_read_byte(const uint8_t *addr) {
return pgm_read_byte(addr); // NOLINT
}
-uint32_t arch_get_cpu_cycle_count() {
+uint32_t IRAM_ATTR HOT arch_get_cpu_cycle_count() {
return ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance)
}
uint32_t arch_get_cpu_freq_hz() { return F_CPU; }
diff --git a/components/esp8266/gpio.cpp b/components/esp8266/gpio.cpp
index 2660318..a24f217 100644
--- a/components/esp8266/gpio.cpp
+++ b/components/esp8266/gpio.cpp
@@ -9,7 +9,7 @@ namespace esp8266 {
static const char *const TAG = "esp8266";
static int IRAM_ATTR flags_to_mode(gpio::Flags flags, uint8_t pin) {
- if (flags == gpio::FLAG_INPUT) {
+ if (flags == gpio::FLAG_INPUT) { // NOLINT(bugprone-branch-clone)
return INPUT;
} else if (flags == gpio::FLAG_OUTPUT) {
return OUTPUT;
diff --git a/components/esp8266/preferences.cpp b/components/esp8266/preferences.cpp
index bc3ce69..e0a7415 100644
--- a/components/esp8266/preferences.cpp
+++ b/components/esp8266/preferences.cpp
@@ -55,7 +55,7 @@ static inline bool esp_rtc_user_mem_write(uint32_t index, uint32_t value) {
extern "C" uint32_t _SPIFFS_end; // NOLINT
-static const uint32_t get_esp8266_flash_sector() {
+static uint32_t get_esp8266_flash_sector() {
union {
uint32_t *ptr;
uint32_t uint;
@@ -63,7 +63,7 @@ static const uint32_t get_esp8266_flash_sector() {
data.ptr = &_SPIFFS_end;
return (data.uint - 0x40200000) / SPI_FLASH_SEC_SIZE;
}
-static const uint32_t get_esp8266_flash_address() { return get_esp8266_flash_sector() * SPI_FLASH_SEC_SIZE; }
+static uint32_t get_esp8266_flash_address() { return get_esp8266_flash_sector() * SPI_FLASH_SEC_SIZE; }
template<class It> uint32_t calculate_crc(It first, It last, uint32_t type) {
uint32_t crc = type;
diff --git a/components/web_server/__init__.py b/components/web_server/__init__.py
index dc652e0..d9ff84d 100644
--- a/components/web_server/__init__.py
+++ b/components/web_server/__init__.py
@@ -12,6 +12,7 @@ from esphome.const import (
CONF_AUTH,
CONF_USERNAME,
CONF_PASSWORD,
+ CONF_INCLUDE_INTERNAL,
CONF_OTA,
)
from esphome.core import CORE, coroutine_with_priority
@@ -42,6 +43,7 @@ CONFIG_SCHEMA = cv.Schema(
cv.GenerateID(CONF_WEB_SERVER_BASE_ID): cv.use_id(
web_server_base.WebServerBase
),
+ cv.Optional(CONF_INCLUDE_INTERNAL, default=False): cv.boolean,
cv.Optional(CONF_OTA, default=True): cv.boolean,
}
).extend(cv.COMPONENT_SCHEMA)
@@ -75,3 +77,4 @@ async def to_code(config):
path = CORE.relative_config_path(config[CONF_JS_INCLUDE])
with open(file=path, mode="r", encoding="utf-8") as myfile:
cg.add(var.set_js_include(myfile.read()))
+ cg.add(var.set_include_internal(config[CONF_INCLUDE_INTERNAL]))
diff --git a/components/web_server/web_server.cpp b/components/web_server/web_server.cpp
index 5ca402b..3fb6937 100644
--- a/components/web_server/web_server.cpp
+++ b/components/web_server/web_server.cpp
@@ -31,10 +31,10 @@ static const char *const TAG = "web_server";
void write_row(AsyncResponseStream *stream, EntityBase *obj, const std::string &klass, const std::string &action,
const std::function<void(AsyncResponseStream &stream, EntityBase *obj)> &action_func = nullptr) {
- if (obj->is_internal())
- return;
stream->print("<tr class=\"");
stream->print(klass.c_str());
+ if (obj->is_internal())
+ stream->print(" internal");
stream->print("\" id=\"");
stream->print(klass.c_str());
stream->print("-");
@@ -83,7 +83,7 @@ void WebServer::set_js_include(const char *js_include) { this->js_include_ = js_
void WebServer::setup() {
ESP_LOGCONFIG(TAG, "Setting up web server...");
- this->setup_controller();
+ this->setup_controller(this->include_internal_);
this->base_->init();
this->events_.onConnect([this](AsyncEventSourceClient *client) {
@@ -92,55 +92,55 @@ void WebServer::setup() {
#ifdef USE_SENSOR
for (auto *obj : App.get_sensors())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->sensor_json(obj, obj->state).c_str(), "state");
#endif
#ifdef USE_SWITCH
for (auto *obj : App.get_switches())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->switch_json(obj, obj->state).c_str(), "state");
#endif
#ifdef USE_BINARY_SENSOR
for (auto *obj : App.get_binary_sensors())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->binary_sensor_json(obj, obj->state).c_str(), "state");
#endif
#ifdef USE_FAN
for (auto *obj : App.get_fans())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->fan_json(obj).c_str(), "state");
#endif
#ifdef USE_LIGHT
for (auto *obj : App.get_lights())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->light_json(obj).c_str(), "state");
#endif
#ifdef USE_TEXT_SENSOR
for (auto *obj : App.get_text_sensors())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->text_sensor_json(obj, obj->state).c_str(), "state");
#endif
#ifdef USE_COVER
for (auto *obj : App.get_covers())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->cover_json(obj).c_str(), "state");
#endif
#ifdef USE_NUMBER
for (auto *obj : App.get_numbers())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->number_json(obj, obj->state).c_str(), "state");
#endif
#ifdef USE_SELECT
for (auto *obj : App.get_selects())
- if (!obj->is_internal())
+ if (this->include_internal_ || !obj->is_internal())
client->send(this->select_json(obj, obj->state).c_str(), "state");
#endif
});
@@ -183,87 +183,99 @@ void WebServer::handle_index_request(AsyncWebServerRequest *request) {
stream->print(F("</head><body><article class=\"markdown-body\"><h1>"));
stream->print(title.c_str());
- // KAUF edit
// output links to kaufha and esphome, list version numbers
stream->print(F("</h1>"));
- stream->print(F("<p>KAUF Plug by <a href=\"https://kaufha.com/blf10\" target=\"_blank\" rel=\"noopener noreferrer\">Kaufman Home Automation</a></p>"));
- stream->print(F("<p>Firmware made using <a href=\"https://esphome.io\" target=\"_blank\" rel=\"noopener noreferrer\">ESPHome</a></p>"));
- stream->print(F("<p>KAUF Plug firmware version 1.81, ESPHome version 2021.11.4</p>"));
+ stream->print(F("<p>KAUF Plug by <a href=\"https://kaufha.com/plf10\" target=\"_blank\" rel=\"noopener noreferrer\">Kaufman Home Automation</a></p>"));
+ stream->print(F("<p>Firmware version 1.82 made using <a href=\"https://esphome.io\" target=\"_blank\" rel=\"noopener noreferrer\">ESPHome</a> version 2021.12.0</p>"));
+ stream->print(F("<p><a href=\"https://github.com/KaufHA/PLF10/releases\" target=\"_blank\" rel=\"noopener noreferrer\">Check for Updates</a></p>"));
stream->print(F("<h2>States</h2><table id=\"states\"><thead><tr><th>Name<th>State<th>Actions<tbody>"));
- // KAUF edit end
// All content is controlled and created by user - so allowing all origins is fine here.
stream->addHeader("Access-Control-Allow-Origin", "*");
#ifdef USE_SENSOR
for (auto *obj : App.get_sensors())
- write_row(stream, obj, "sensor", "");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "sensor", "");
#endif
#ifdef USE_SWITCH
for (auto *obj : App.get_switches())
- write_row(stream, obj, "switch", "<button>Toggle</button>");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "switch", "<button>Toggle</button>");
+#endif
+
+#ifdef USE_BUTTON
+ for (auto *obj : App.get_buttons())
+ write_row(stream, obj, "button", "<button>Press</button>");
#endif
#ifdef USE_BINARY_SENSOR
for (auto *obj : App.get_binary_sensors())
- write_row(stream, obj, "binary_sensor", "");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "binary_sensor", "");
#endif
#ifdef USE_FAN
for (auto *obj : App.get_fans())
- write_row(stream, obj, "fan", "<button>Toggle</button>");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "fan", "<button>Toggle</button>");
#endif
#ifdef USE_LIGHT
for (auto *obj : App.get_lights())
- write_row(stream, obj, "light", "<button>Toggle</button>");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "light", "<button>Toggle</button>");
#endif
#ifdef USE_TEXT_SENSOR
for (auto *obj : App.get_text_sensors())
- write_row(stream, obj, "text_sensor", "");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "text_sensor", "");
#endif
#ifdef USE_COVER
for (auto *obj : App.get_covers())
- write_row(stream, obj, "cover", "<button>Open</button><button>Close</button>");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "cover", "<button>Open</button><button>Close</button>");
#endif
#ifdef USE_NUMBER
for (auto *obj : App.get_numbers())
- write_row(stream, obj, "number", "");
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "number", "");
#endif
#ifdef USE_SELECT
for (auto *obj : App.get_selects())
- write_row(stream, obj, "select", "", [](AsyncResponseStream &stream, EntityBase *obj) {
- select::Select *select = (select::Select *) obj;
- stream.print("<select>");
- stream.print("<option></option>");
- for (auto const &option : select->traits.get_options()) {
- stream.print("<option>");
- stream.print(option.c_str());
- stream.print("</option>");
- }
- stream.print("</select>");
- });
+ if (this->include_internal_ || !obj->is_internal())
+ write_row(stream, obj, "select", "", [](AsyncResponseStream &stream, EntityBase *obj) {
+ select::Select *select = (select::Select *) obj;
+ stream.print("<select>");
+ stream.print("<option></option>");
+ for (auto const &option : select->traits.get_options()) {
+ stream.print("<option>");
+ stream.print(option.c_str());
+ stream.print("</option>");
+ }
+ stream.print("</select>");
+ });
#endif
- // KAUF edit
- // warn not to load tasmota-minimal
stream->print(F("</tbody></table><p>See <a href=\"https://esphome.io/web-api/index.html\">ESPHome Web API</a> for "
- "REST API documentation.</p>"
- "<h2>OTA Update</h2>"
- "<br />**** DO NOT USE <b>TASMOTA-MINIMAL</b>.BIN or .BIN.GZ. **** Use tasmota.bin.gz."
- "<form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\"><input "
- "type=\"file\" name=\"update\"><input type=\"submit\" value=\"Update\"></form>"
- "<h2>Debug Log</h2><pre id=\"log\"></pre>"));
- // KAUF edit end
+ "REST API documentation.</p>"));
+ if (this->allow_ota_) {
+ stream->print(F("<h2>OTA Update</h2>"
+ "<br />**** DO NOT USE <b>TASMOTA-MINIMAL</b>.BIN or .BIN.GZ. **** Use tasmota.bin.gz."
+ "After the firmware is uploaded, a blank page will appear with the message <b>Update Successful!</b>. If anything strange or different happens, please remove power to the plug before trying to flash again. <br /><br /> "
+ "<form method=\"POST\" action=\"/update\" enctype=\"multipart/form-data\"><input "
+ "type=\"file\" name=\"update\"><input type=\"submit\" value=\"Update\"></form>"));
+ }
+ stream->print(F("<h2>Debug Log</h2><pre id=\"log\"></pre>"));
#ifdef WEBSERVER_JS_INCLUDE
if (this->js_include_ != nullptr) {
@@ -308,8 +320,6 @@ void WebServer::on_sensor_update(sensor::Sensor *obj, float state) {
}
void WebServer::handle_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (sensor::Sensor *obj : App.get_sensors()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
std::string data = this->sensor_json(obj, obj->state);
@@ -336,8 +346,6 @@ void WebServer::on_text_sensor_update(text_sensor::TextSensor *obj, const std::s
}
void WebServer::handle_text_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (text_sensor::TextSensor *obj : App.get_text_sensors()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
std::string data = this->text_sensor_json(obj, obj->state);
@@ -368,8 +376,6 @@ std::string WebServer::switch_json(switch_::Switch *obj, bool value) {
}
void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (switch_::Switch *obj : App.get_switches()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
@@ -394,10 +400,28 @@ void WebServer::handle_switch_request(AsyncWebServerRequest *request, const UrlM
}
#endif
+#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;
+
+ if (request->method() == HTTP_POST && match.method == "press") {
+ this->defer([obj]() { obj->press(); });
+ request->send(200);
+ } else {
+ request->send(404);
+ }
+ return;
+ }
+ request->send(404);
+}
+#endif
+
#ifdef USE_BINARY_SENSOR
void WebServer::on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state) {
- if (obj->is_internal())
- return;
this->events_.send(this->binary_sensor_json(obj, state).c_str(), "state");
}
std::string WebServer::binary_sensor_json(binary_sensor::BinarySensor *obj, bool value) {
@@ -409,8 +433,6 @@ std::string WebServer::binary_sensor_json(binary_sensor::BinarySensor *obj, bool
}
void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (binary_sensor::BinarySensor *obj : App.get_binary_sensors()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
std::string data = this->binary_sensor_json(obj, obj->state);
@@ -422,11 +444,7 @@ void WebServer::handle_binary_sensor_request(AsyncWebServerRequest *request, con
#endif
#ifdef USE_FAN
-void WebServer::on_fan_update(fan::FanState *obj) {
- if (obj->is_internal())
- return;
- this->events_.send(this->fan_json(obj).c_str(), "state");
-}
+void WebServer::on_fan_update(fan::FanState *obj) { this->events_.send(this->fan_json(obj).c_str(), "state"); }
std::string WebServer::fan_json(fan::FanState *obj) {
return json::build_json([obj](JsonObject &root) {
root["id"] = "fan-" + obj->get_object_id();
@@ -457,8 +475,6 @@ std::string WebServer::fan_json(fan::FanState *obj) {
}
void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (fan::FanState *obj : App.get_fans()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
@@ -519,15 +535,9 @@ void WebServer::handle_fan_request(AsyncWebServerRequest *request, const UrlMatc
#endif
#ifdef USE_LIGHT
-void WebServer::on_light_update(light::LightState *obj) {
- if (obj->is_internal())
- return;
- this->events_.send(this->light_json(obj).c_str(), "state");
-}
+void WebServer::on_light_update(light::LightState *obj) { this->events_.send(this->light_json(obj).c_str(), "state"); }
void WebServer::handle_light_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (light::LightState *obj : App.get_lights()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
@@ -594,15 +604,9 @@ std::string WebServer::light_json(light::LightState *obj) {
#endif
#ifdef USE_COVER
-void WebServer::on_cover_update(cover::Cover *obj) {
- if (obj->is_internal())
- return;
- this->events_.send(this->cover_json(obj).c_str(), "state");
-}
+void WebServer::on_cover_update(cover::Cover *obj) { this->events_.send(this->cover_json(obj).c_str(), "state"); }
void WebServer::handle_cover_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (cover::Cover *obj : App.get_covers()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
@@ -661,8 +665,6 @@ void WebServer::on_number_update(number::Number *obj, float state) {
}
void WebServer::handle_number_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (auto *obj : App.get_numbers()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
std::string data = this->number_json(obj, obj->state);
@@ -688,8 +690,6 @@ void WebServer::on_select_update(select::Select *obj, const std::string &state)
}
void WebServer::handle_select_request(AsyncWebServerRequest *request, const UrlMatch &match) {
for (auto *obj : App.get_selects()) {
- if (obj->is_internal())
- continue;
if (obj->get_object_id() != match.id)
continue;
@@ -753,6 +753,11 @@ bool WebServer::canHandle(AsyncWebServerRequest *request) {
return true;
#endif
+#ifdef USE_BUTTON
+ if (request->method() == HTTP_POST && match.domain == "button")
+ return true;
+#endif
+
#ifdef USE_BINARY_SENSOR
if (request->method() == HTTP_GET && match.domain == "binary_sensor")
return true;
@@ -825,6 +830,13 @@ void WebServer::handleRequest(AsyncWebServerRequest *request) {
}
#endif
+#ifdef USE_BUTTON
+ if (match.domain == "button") {
+ this->handle_button_request(request, match);
+ return;
+ }
+#endif
+
#ifdef USE_BINARY_SENSOR
if (match.domain == "binary_sensor") {
this->handle_binary_sensor_request(request, match);
diff --git a/components/web_server/web_server.h b/components/web_server/web_server.h
index cdfec51..8edb423 100644
--- a/components/web_server/web_server.h
+++ b/components/web_server/web_server.h
@@ -58,6 +58,12 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
*/
void set_js_include(const char *js_include);
+ /** Determine whether internal components should be displayed on the web server.
+ * Defaults to false.
+ *
+ * @param include_internal Whether internal components should be displayed.
+ */
+ void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
/** Set whether or not the webserver should expose the OTA form and handler.
*
* @param allow_ota.
@@ -106,6 +112,11 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
std::string switch_json(switch_::Switch *obj, bool value);
#endif
+#ifdef USE_BUTTON
+ /// Handle a button request under '/button/<id>/press'.
+ void handle_button_request(AsyncWebServerRequest *request, const UrlMatch &match);
+#endif
+
#ifdef USE_BINARY_SENSOR
void on_binary_sensor_update(binary_sensor::BinarySensor *obj, bool state) override;
@@ -188,6 +199,7 @@ class WebServer : public Controller, public Component, public AsyncWebHandler {
const char *css_include_{nullptr};
const char *js_url_{nullptr};
const char *js_include_{nullptr};
+ bool include_internal_{false};
bool allow_ota_{true};
};
diff --git a/components/web_server_base/web_server_base.cpp b/components/web_server_base/web_server_base.cpp
index 8b6330a..79ba285 100644
--- a/components/web_server_base/web_server_base.cpp
+++ b/components/web_server_base/web_server_base.cpp
@@ -5,10 +5,8 @@
#include "esphome/core/application.h"
#include <StreamString.h>
-// KAUF edit
// needed for string searching below
#include <string> // std::string
-// KAUF edit end
#ifdef USE_ESP32
#include <Update.h>
@@ -43,8 +41,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
uint8_t *data, size_t len, bool final) {
bool success;
-// KAUF edit
-// kill process if "minimal" is found in string
+ // kill process if "minimal" is found in string
std::string str = filename.c_str();
std::size_t found = str.find("minimal");
@@ -53,7 +50,6 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin
report_ota_error();
return;
}
-// KAUF edit end
if (index == 0) {
ESP_LOGI(TAG, "OTA Update Start: %s", filename.c_str());
diff --git a/components/wifi/__init__.py b/components/wifi/__init__.py
index 7a9319f..a24791b 100644
--- a/components/wifi/__init__.py
+++ b/components/wifi/__init__.py
@@ -221,10 +221,22 @@ def _validate(config):
raise cv.Invalid("Fast connect can only be used with one network!")
if CONF_USE_ADDRESS not in config:
+ use_address = CORE.name + config[CONF_DOMAIN]
if CONF_MANUAL_IP in config:
use_address = str(config[CONF_MANUAL_IP][CONF_STATIC_IP])
- else:
- use_address = CORE.name + config[CONF_DOMAIN]
+ elif CONF_NETWORKS in config:
+ ips = set(
+ str(net[CONF_MANUAL_IP][CONF_STATIC_IP])
+ for net in config[CONF_NETWORKS]
+ if CONF_MANUAL_IP in net
+ )
+ if len(ips) > 1:
+ raise cv.Invalid(
+ "Must specify use_address when using multiple static IP addresses."
+ )
+ if len(ips) == 1:
+ use_address = next(iter(ips))
+
config[CONF_USE_ADDRESS] = use_address
return config
@@ -334,7 +346,8 @@ async def to_code(config):
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
for network in config.get(CONF_NETWORKS, []):
- cg.add(var.add_sta(wifi_network(network, config.get(CONF_MANUAL_IP))))
+ ip_config = network.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP))
+ cg.add(var.add_sta(wifi_network(network, ip_config)))
if CONF_AP in config:
conf = config[CONF_AP]
diff --git a/components/wifi/wifi_component_esp_idf.cpp b/components/wifi/wifi_component_esp_idf.cpp
index 1d346c0..5a81fd0 100644
--- a/components/wifi/wifi_component_esp_idf.cpp
+++ b/components/wifi/wifi_component_esp_idf.cpp
@@ -67,9 +67,9 @@ void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, voi
memset(&event, 0, sizeof(IDFWiFiEvent));
event.event_base = event_base;
event.event_id = event_id;
- if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
+ if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { // NOLINT(bugprone-branch-clone)
// no data
- } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_STOP) {
+ } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_STOP) { // NOLINT(bugprone-branch-clone)
// no data
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_AUTHMODE_CHANGE) {
memcpy(&event.data.sta_authmode_change, event_data, sizeof(wifi_event_sta_authmode_change_t));
@@ -79,13 +79,13 @@ void event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, voi
memcpy(&event.data.sta_disconnected, event_data, sizeof(wifi_event_sta_disconnected_t));
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
memcpy(&event.data.ip_got_ip, event_data, sizeof(ip_event_got_ip_t));
- } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) {
+ } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_LOST_IP) { // NOLINT(bugprone-branch-clone)
// no data
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_SCAN_DONE) {
memcpy(&event.data.sta_scan_done, event_data, sizeof(wifi_event_sta_scan_done_t));
- } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_START) {
+ } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_START) { // NOLINT(bugprone-branch-clone)
// no data
- } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STOP) {
+ } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_STOP) { // NOLINT(bugprone-branch-clone)
// no data
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_AP_PROBEREQRECVED) {
memcpy(&event.data.ap_probe_req_rx, event_data, sizeof(wifi_event_ap_probe_req_rx_t));
@@ -430,7 +430,7 @@ bool WiFiComponent::wifi_sta_ip_config_(optional<ManualIP> manual_ip) {
info.netmask.addr = static_cast<uint32_t>(manual_ip->subnet);
err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_STA);
- if (err != ESP_OK) {
+ if (err != ESP_OK && err != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED) {
ESP_LOGV(TAG, "tcpip_adapter_dhcpc_stop failed: %s", esp_err_to_name(err));
return false;
}