mirror of
https://github.com/esphome/esphome.git
synced 2026-09-18 10:38:38 +00:00
[bk72xx_ble] Keep wifi power save off while BLE is compiled in (#19317)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
esphome:
|
||||
name: bk-power-save
|
||||
|
||||
bk72xx:
|
||||
board: cb2s
|
||||
|
||||
wifi:
|
||||
ssid: test
|
||||
password: testtest
|
||||
power_save_mode: high
|
||||
|
||||
bk72xx_ble:
|
||||
@@ -0,0 +1,20 @@
|
||||
"""bk72xx_ble keeps WiFi power save off: the Beken SDK's MCU sleep does not
|
||||
wake up once the station is stopped while the BLE controller runs."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
def test_power_save_mode_is_not_applied_with_ble(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
main_cpp = generate_main(component_config_path("test_power_save.yaml"))
|
||||
|
||||
assert "bk72xx_ble::BK72xxBLE" in main_cpp
|
||||
assert "set_power_save_mode(" not in main_cpp
|
||||
assert "power_save_mode HIGH is not applied" in caplog.text
|
||||
assert "issues/18592" in caplog.text
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Tests for wifi.force_power_save_off(), the hook platforms use to keep the
|
||||
station out of power save."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome.components import wifi
|
||||
from esphome.core import CORE, EsphomeError
|
||||
|
||||
|
||||
def test_reasons_accumulate_without_duplicates() -> None:
|
||||
"""Every caller's reason is kept once; a repeated reason is not duplicated."""
|
||||
wifi.force_power_save_off("first")
|
||||
wifi.force_power_save_off("first")
|
||||
wifi.force_power_save_off("second")
|
||||
|
||||
assert CORE.data[wifi.POWER_SAVE_OFF_REASONS_KEY] == ["first", "second"]
|
||||
|
||||
|
||||
def test_forced_off_skips_the_setter_and_warns(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""With a reason recorded, power_save_mode is reported and not applied."""
|
||||
wifi.force_power_save_off("the platform cannot sleep")
|
||||
|
||||
main_cpp = generate_main(component_config_path("custom.yaml"))
|
||||
|
||||
assert "set_power_save_mode(" not in main_cpp
|
||||
assert (
|
||||
"power_save_mode LIGHT is not applied: the platform cannot sleep" in caplog.text
|
||||
)
|
||||
|
||||
|
||||
def test_call_after_wifi_codegen_raises(
|
||||
generate_main: Callable[[str | Path], str],
|
||||
component_config_path: Callable[[str], Path],
|
||||
) -> None:
|
||||
"""Once wifi has generated its code the hook cannot take effect any more."""
|
||||
generate_main(component_config_path("custom.yaml"))
|
||||
|
||||
with pytest.raises(EsphomeError, match="before wifi generates its code"):
|
||||
wifi.force_power_save_off("too late")
|
||||
@@ -0,0 +1,9 @@
|
||||
# A wifi power_save_mode other than NONE is forced off with a warning while
|
||||
# bk72xx_ble is configured (esphome#18592); this config must still validate.
|
||||
packages:
|
||||
bk72xx_ble: !include common.yaml
|
||||
|
||||
wifi:
|
||||
ssid: MySSID
|
||||
password: password1
|
||||
power_save_mode: high
|
||||
Reference in New Issue
Block a user