mirror of
https://github.com/esphome/esphome.git
synced 2025-11-03 16:41:50 +00:00
Compare commits
4 Commits
action_cha
...
copilot/fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9476a4b1ce | ||
|
|
8d2078275d | ||
|
|
12db82e03a | ||
|
|
331d98830a |
@@ -210,6 +210,13 @@ void WiFiComponent::loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WiFiComponent::on_safe_shutdown() {
|
||||||
|
if (this->has_sta()) {
|
||||||
|
ESP_LOGD(TAG, "Disconnecting from WiFi...");
|
||||||
|
this->wifi_disconnect_();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
WiFiComponent::WiFiComponent() { global_wifi_component = this; }
|
WiFiComponent::WiFiComponent() { global_wifi_component = this; }
|
||||||
|
|
||||||
bool WiFiComponent::has_ap() const { return this->has_ap_; }
|
bool WiFiComponent::has_ap() const { return this->has_ap_; }
|
||||||
|
|||||||
@@ -263,6 +263,9 @@ class WiFiComponent : public Component {
|
|||||||
/// Reconnect WiFi if required.
|
/// Reconnect WiFi if required.
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
|
/// Safely shutdown WiFi before deep sleep
|
||||||
|
void on_safe_shutdown() override;
|
||||||
|
|
||||||
bool has_sta() const;
|
bool has_sta() const;
|
||||||
bool has_ap() const;
|
bool has_ap() const;
|
||||||
|
|
||||||
|
|||||||
@@ -42,3 +42,18 @@ def test_deep_sleep_run_duration_dictionary(generate_main):
|
|||||||
" .gpio_cause = 30000,\n"
|
" .gpio_cause = 30000,\n"
|
||||||
"});"
|
"});"
|
||||||
) in main_cpp
|
) in main_cpp
|
||||||
|
|
||||||
|
|
||||||
|
def test_deep_sleep_with_wifi_esp8266(generate_main):
|
||||||
|
"""
|
||||||
|
When deep sleep is configured with WiFi on ESP8266, WiFi component should be included.
|
||||||
|
"""
|
||||||
|
main_cpp = generate_main("tests/component_tests/deep_sleep/test_deep_sleep_esp8266_wifi.yaml")
|
||||||
|
|
||||||
|
# Verify WiFi component is registered
|
||||||
|
assert "wifi = new wifi::WiFiComponent();" in main_cpp
|
||||||
|
assert "App.register_component(wifi);" in main_cpp
|
||||||
|
|
||||||
|
# Verify deep sleep component is registered
|
||||||
|
assert "deep_sleep_1 = new deep_sleep::DeepSleepComponent();" in main_cpp
|
||||||
|
assert "App.register_component(deep_sleep_1);" in main_cpp
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
esphome:
|
||||||
|
name: test_esp8266_wifi_deep_sleep
|
||||||
|
|
||||||
|
esp8266:
|
||||||
|
board: esp12e
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: "test"
|
||||||
|
password: "testtest"
|
||||||
|
|
||||||
|
api:
|
||||||
|
actions:
|
||||||
|
- action: goto_sleep
|
||||||
|
variables:
|
||||||
|
duration_ms: int
|
||||||
|
then:
|
||||||
|
- deep_sleep.enter:
|
||||||
|
id: deep_sleep_1
|
||||||
|
sleep_duration: !lambda 'return duration_ms;'
|
||||||
|
|
||||||
|
deep_sleep:
|
||||||
|
id: deep_sleep_1
|
||||||
|
run_duration: 10s
|
||||||
Reference in New Issue
Block a user