Skip to content

Commit af55b42

Browse files
committed
esphome 2022.10
1 parent 90b2999 commit af55b42

File tree

13 files changed

+814
-803
lines changed

13 files changed

+814
-803
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__pycache__
2+
_static
3+
node_modules
4+
esphome-webserver/captive-portal/package-lock.json

components/captive_portal/captive_index.h

+122-119
Large diffs are not rendered by default.

components/esp8266/gpio.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
from dataclasses import dataclass
3-
from typing import List
43

54
from esphome.const import (
65
CONF_ID,
@@ -200,7 +199,7 @@ async def esp8266_pin_to_code(config):
200199
@coroutine_with_priority(-999.0)
201200
async def add_pin_initial_states_array():
202201
# Add includes at the very end, so that they override everything
203-
initial_states: List[PinInitialState] = CORE.data[KEY_ESP8266][
202+
initial_states: list[PinInitialState] = CORE.data[KEY_ESP8266][
204203
KEY_PIN_INITIAL_STATES
205204
]
206205
initial_modes_s = ", ".join(str(x.mode) for x in initial_states)

components/esp8266/preferences.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,6 @@ class ESP8266Preferences : public ESPPreferences {
188188

189189
if (in_flash) {
190190

191-
// looking for type 2729014980 and length 2 to erase all flash. Length 2 just to make it less likely to occur accidentally.
192-
if ( (type==2729014980) && (length==2) && (current_flash_offset!=0)) {
193-
auto *pref = new ESP8266PreferenceBackend(); // NOLINT(cppcoreguidelines-owning-memory)
194-
ESP_LOGD("KAUF Preferences", " !!!! ERASING FLASH THROUGH ADDR %d !!!!", current_flash_offset - 1);
195-
pref->offset = 0;
196-
pref->type = type;
197-
pref->length_words = current_flash_offset - 1;
198-
pref->in_flash = true;
199-
uint8_t fake_data = 0;
200-
pref->save(&fake_data,(current_flash_offset-1)*4);
201-
return {};
202-
}
203-
204191
uint32_t start;
205192
uint32_t end;
206193

components/select/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from typing import List
21
import esphome.codegen as cg
32
import esphome.config_validation as cv
43
from esphome import automation
@@ -63,7 +62,7 @@
6362
)
6463

6564

66-
async def setup_select_core_(var, config, *, options: List[str]):
65+
async def setup_select_core_(var, config, *, options: list[str]):
6766
await setup_entity(var, config)
6867

6968
cg.add(var.traits.set_options(options))
@@ -88,14 +87,14 @@ async def setup_select_core_(var, config, *, options: List[str]):
8887
cg.add(var.set_global_addr(ga))
8988

9089

91-
async def register_select(var, config, *, options: List[str]):
90+
async def register_select(var, config, *, options: list[str]):
9291
if not CORE.has_id(config[CONF_ID]):
9392
var = cg.Pvariable(config[CONF_ID], var)
9493
cg.add(cg.App.register_select(var))
9594
await setup_select_core_(var, config, options=options)
9695

9796

98-
async def new_select(config, *, options: List[str]):
97+
async def new_select(config, *, options: list[str]):
9998
var = cg.new_Pvariable(config[CONF_ID])
10099
await register_select(var, config, options=options)
101100
return var

components/web_server/server_index.h

+626-629
Large diffs are not rendered by default.

components/web_server/web_server.cpp

+20-25
Original file line numberDiff line numberDiff line change
@@ -1204,9 +1204,7 @@ void WebServer::reset_flash(AsyncWebServerRequest *request) {
12041204

12051205
ESP_LOGD("kauf web server", "erasing flash");
12061206

1207-
// using hash of 2729014980 and length 2 erases all used flash.
1208-
ESPPreferenceObject pref;
1209-
pref = global_preferences->make_preference(2,2729014980,true);
1207+
global_preferences->reset();
12101208

12111209
AsyncResponseStream *stream = request->beginResponseStream("text/html");
12121210
stream->addHeader("Access-Control-Allow-Origin", "*");
@@ -1228,37 +1226,34 @@ void WebServer::clear_wifi(AsyncWebServerRequest *request) {
12281226
stream->addHeader("Access-Control-Allow-Origin", "*");
12291227
stream->print(F("<!DOCTYPE html><html><head><meta charset=UTF-8><link rel=icon href=data:></head><body>"));
12301228

1231-
// if there is no soft ssid, provide message nothing to clear
1232-
if ( strcmp(wifi::global_wifi_component->soft_ssid.c_str(),"") == 0 ) {
1233-
stream->print(F("This utility currently only clears Wi-Fi credentials that were configured using the captive portal after "));
1234-
stream->print(F("the firmware was compiled. Since this device has no such Wi-Fi credentials, nothing has been cleared. "));
1235-
stream->print(F("<br /><br />This device will continue to try to connect to the hard-coded Wi-Fi network with SSID <b>"));
1236-
stream->print(wifi::global_wifi_component->hard_ssid.c_str());
1237-
stream->print(F("</b>.<br /><br />"));
1238-
stream->print(F("</body></html>"));
1239-
request->send(stream);
1240-
} else {
1241-
wifi::global_wifi_component->clear_stored_creds();
1242-
stream->print(F("The Wi-Fi credentials with SSID <b>"));
1243-
stream->print(wifi::global_wifi_component->soft_ssid.c_str());
1244-
stream->print(F("</b>, which were configured via the captive portal, are being cleared. "));
1245-
stream->print(F("<br /><br />This device will continue to try to connect to the hard-coded Wi-Fi network with SSID <b>"));
1246-
stream->print(wifi::global_wifi_component->hard_ssid.c_str());
1247-
stream->print(F("</b>.<br /><br />"));
1248-
1249-
stream->print(F("This device is now restarting itself automatically."));
1229+
if ( wifi::global_wifi_component->has_ap() ) {
1230+
1231+
// store default credentials in flash, overwrites both soft and hard-coded credentials to ensure that Wi-Fi AP comes up.
1232+
stream->print(F("The following Wi-Fi credentials are being saved into flash memory:<br>"));
1233+
stream->print(F("SSID: <b>initial_ap</b><br>"));
1234+
stream->print(F("Password: <b>asdfasdfasdfasdf</b><br><br>"));
1235+
1236+
stream->print(F("This will overwrite any previous credentials that were stored in flash memory via the captive portal. "));
1237+
stream->print(F("This will also take precedence over any credentials that were hard-coded in yaml. "));
1238+
stream->print(F("This device will now reboot and put up it's Wi-Fi AP to allow setting of new credentials. However, if a network with the above credentials exists, this device will connect to that network instead of putting up its Wi-Fi AP."));
12501239
stream->print(F("</body></html>"));
12511240
request->send(stream);
12521241

1242+
wifi::global_wifi_component->save_wifi_sta("initial_ap","asdfasdfasdfasdf");
1243+
12531244
this->set_timeout(100, []() { App.safe_reboot(); });
1245+
1246+
}
1247+
1248+
else {
1249+
stream->print(F("This function is only available for devices that have the Wi-Fi AP enabled."));
1250+
stream->print(F("</body></html>"));
1251+
request->send(stream);
12541252
}
12551253

12561254
return;
12571255
}
12581256

1259-
1260-
1261-
12621257
} // namespace web_server
12631258
} // namespace esphome
12641259

components/web_server_base/web_server_base.h

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class WebServerBase : public Component {
8181
return;
8282
}
8383
this->server_ = std::make_shared<AsyncWebServer>(this->port_);
84+
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
8485
this->server_->begin();
8586

8687
for (auto *handler : this->handlers_)

components/wifi/__init__.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ def manual_ip(config):
335335
)
336336

337337

338-
def wifi_network(config, static_ip):
339-
ap = cg.variable(config[CONF_ID], WiFiAP())
338+
def wifi_network(config, ap, static_ip):
340339
if CONF_SSID in config:
341340
cg.add(ap.set_ssid(config[CONF_SSID]))
342341
if CONF_PASSWORD in config:
@@ -363,14 +362,21 @@ async def to_code(config):
363362
var = cg.new_Pvariable(config[CONF_ID])
364363
cg.add(var.set_use_address(config[CONF_USE_ADDRESS]))
365364

366-
for network in config.get(CONF_NETWORKS, []):
365+
def add_sta(ap, network):
367366
ip_config = network.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP))
368-
cg.add(var.add_sta(wifi_network(network, ip_config)))
367+
cg.add(var.add_sta(wifi_network(network, ap, ip_config)))
368+
369+
for network in config.get(CONF_NETWORKS, []):
370+
cg.with_local_variable(network[CONF_ID], WiFiAP(), add_sta, network)
369371

370372
if CONF_AP in config:
371373
conf = config[CONF_AP]
372-
ip_config = conf.get(CONF_MANUAL_IP, config.get(CONF_MANUAL_IP))
373-
cg.add(var.set_ap(wifi_network(conf, ip_config)))
374+
ip_config = conf.get(CONF_MANUAL_IP)
375+
cg.with_local_variable(
376+
conf[CONF_ID],
377+
WiFiAP(),
378+
lambda ap: cg.add(var.set_ap(wifi_network(conf, ap, ip_config))),
379+
)
374380
cg.add(var.set_ap_timeout(conf[CONF_AP_TIMEOUT]))
375381

376382
cg.add(var.set_reboot_timeout(config[CONF_REBOOT_TIMEOUT]))

components/wifi/wifi_component.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ void WiFiComponent::loop() {
128128
this->wifi_loop_();
129129
const uint32_t now = millis();
130130

131+
// hard code an AP timeout of 15 seconds for all devices if Wi-Fi credentials are not configured.
132+
if ( (this->soft_ssid == "initial_ap") ||
133+
((this->hard_ssid == "initial_ap") && this->tried_loading_creds && !this->loaded_creds ) ) {
134+
this->set_ap_timeout(15000);
135+
}
136+
131137
if (this->has_sta()) {
132138
switch (this->state_) {
133139
case WIFI_COMPONENT_STATE_COOLDOWN: {

esphome-webserver/captive-portal/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ <h3>Wi-Fi Credentials:</h3>
2727
<br>
2828
<div style="display:flex">
2929
<p>Show password:</p>
30-
<p><input type="checkbox" onclick="togglepass()" style="width:auto"></p>
30+
<p><input type="checkbox" onclick="togglepass();document.getElementById('psk').focus()" style="width:auto"></p>
3131
</div>
3232
<hr>
3333
<br>

esphome-webserver/scripts/make_header.sh

100644100755
+8
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ cat <<EOT >> ./$1/$2
1616
} // namespace esphome
1717
EOT
1818
ls -l ./$1/$2
19+
20+
if [ "web_server" = "$3" ]; then
21+
cp ./_static/v2/server_index.h ../components/web_server/
22+
fi
23+
24+
if [ "captive_portal" = "$3" ]; then
25+
cp ./dist/captive_index.h ../../components/captive_portal/
26+
fi

esphome-webserver/v2/esp-app.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export default class EspApp extends LitElement {
7979
kauf_p_name() {
8080
if ( this.config.proj_n == "Kauf.PLF10")
8181
return "Plug";
82-
else if ( this.config.proj_n == "Kauf.RGBWW")
82+
else if ( this.config.proj_n == "Kauf.PLF12")
83+
return "Plug";
84+
else if ( this.config.proj_n == "Kauf.RGBWW")
8385
return "RGBWW Bulb";
8486
else if ( this.config.proj_n == "Kauf.RGBSw")
8587
return "RGB Switch";
@@ -90,6 +92,8 @@ export default class EspApp extends LitElement {
9092
kauf_p_url() {
9193
if ( this.config.proj_n == "Kauf.PLF10")
9294
return "plf10";
95+
else if ( this.config.proj_n == "Kauf.PLF12")
96+
return "plf12";
9397
else if ( this.config.proj_n == "Kauf.RGBWW")
9498
return "blf10";
9599
else if ( this.config.proj_n == "Kauf.RGBSw")
@@ -101,6 +105,8 @@ export default class EspApp extends LitElement {
101105
kauf_p_up() {
102106
if ( this.config.proj_n == "Kauf.PLF10")
103107
return html`<br><a href="https://github.com/KaufHA/PLF10/releases" target="_blank" rel="noopener noreferrer">Check for Updates</a>`;
108+
else if ( this.config.proj_n == "Kauf.PLF12")
109+
return html`<br><a href="https://github.com/KaufHA/PLF12/releases" target="_blank" rel="noopener noreferrer">Check for Updates</a>`;
104110
else if ( this.config.proj_n == "Kauf.RGBWW")
105111
return html`<br><a href="https://github.com/KaufHA/kauf-rgbww-bulbs/releases" target="_blank" rel="noopener noreferrer">Check for Updates</a>`;
106112
else if ( this.config.proj_n == "Kauf.RGBSw")
@@ -131,12 +137,12 @@ export default class EspApp extends LitElement {
131137

132138
factory_reset() {
133139
if ( this.config.proj_l == "f" )
134-
return html `<p><b> Important note for factory images, with version suffix (f)</b> - /reset will place the firmware into factory test mode. Factory test mode can typically be cleared easily by pressing a button on the device. For bulbs, factory test mode cannot be cleared and will cause the bulb to cycle through colors for 10 minutes with no way to stop the routine. <b>It is strongly recommended</b> to update the firmware with a bin.gz file downloaded from the "check for updates" link above, even if the version number is the same, in order to get rid of the factory test routine before trying to reset the flash memory using this method.</p>`
140+
return html `<p><b> For factory images, with version suffix (f)</b>, /reset will place the firmware into factory test mode. Factory test mode can typically be cleared easily by pressing a button on the device after a few seconds. For bulbs, factory test mode will automatically stop after 10 minutes or can be cleared through the web interface by pressing the "Stop Factory Routine" button once you get the bulb connected back to Wi-Fi. You may need to refresh the page to see this button.</p>`
135141
}
136142

137143
clear() {
138-
if ( this.config.soft_ssid != "" )
139-
return html `<p><a href="/clear" target="_blank">/clear</a> - Clears the software-configured Wi-Fi credentials. The device will reboot and try to connect to the hard-coded Wi-Fi credentials. If this firwmare has the AP enabled, and the hard-coded Wi-Fi credentials cannot be connected to, then this device will put up a Wi-Fi AP allowing new software-configured Wi-Fi credential to be entered.</p>`
144+
if ( this.config.has_ap )
145+
return html `<p><a href="/clear" target="_blank">/clear</a> - Writes new software-configured Wi-Fi credentials (SSID: initial_ap, password: asdfasdfasdfasdf). The device will reboot and try to connect to a network with those credentials. If those credentials cannot be connected to, then this device will put up a Wi-Fi AP allowing new software-configured Wi-Fi credential to be entered.</p>`
140146
}
141147
142148
render() {

0 commit comments

Comments
 (0)