mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 02:02:51 +00:00
[wifi] Add DHCP lease cache (#17767)
Co-authored-by: J. Nick Koston <nick@home-assistant.io> Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
co-authored by
J. Nick Koston
J. Nick Koston
parent
3f21ddf6ff
commit
19eeab0385
@@ -0,0 +1,41 @@
|
||||
"""Tests for the lease_cache storage validation."""
|
||||
|
||||
import pytest
|
||||
|
||||
from esphome import config_validation as cv
|
||||
from esphome.components.esp32 import KEY_VARIANT
|
||||
from esphome.components.esp32.const import VARIANT_ESP32, VARIANT_ESP32C2
|
||||
from esphome.components.wifi import CONFIG_SCHEMA
|
||||
from esphome.const import PlatformFramework
|
||||
from tests.component_tests.types import SetCoreConfigCallable
|
||||
|
||||
|
||||
def _validate(lease_cache: dict) -> dict:
|
||||
return CONFIG_SCHEMA(
|
||||
{
|
||||
"ssid": "net",
|
||||
"password": "secret12",
|
||||
"use_address": "test.local",
|
||||
"lease_cache": lease_cache,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def test_storage_defaults_to_rtc(set_core_config: SetCoreConfigCallable) -> None:
|
||||
set_core_config(
|
||||
PlatformFramework.ESP32_IDF, platform_data={KEY_VARIANT: VARIANT_ESP32}
|
||||
)
|
||||
config = _validate({"max_age": "12h"})
|
||||
assert config["lease_cache"]["storage"] == "rtc"
|
||||
|
||||
|
||||
def test_no_rtc_variant_requires_flash(set_core_config: SetCoreConfigCallable) -> None:
|
||||
"""A variant without RTC memory must say storage: flash; the error points at that key."""
|
||||
set_core_config(
|
||||
PlatformFramework.ESP32_IDF, platform_data={KEY_VARIANT: VARIANT_ESP32C2}
|
||||
)
|
||||
with pytest.raises(cv.Invalid, match="no RTC memory") as exc:
|
||||
_validate({"max_age": "12h"})
|
||||
assert exc.value.path == ["lease_cache", "storage"]
|
||||
config = _validate({"storage": "flash"})
|
||||
assert config["lease_cache"]["storage"] == "flash"
|
||||
Reference in New Issue
Block a user