mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
[remote_base] Dedupe dumpers after registry validation
This commit is contained in:
@@ -281,22 +281,16 @@ TRIGGER_REGISTRY = SimpleRegistry()
|
||||
DUMPER_REGISTRY = Registry()
|
||||
|
||||
|
||||
def _dumper_key(item: Any) -> Any:
|
||||
"""Registry key of a dump entry in either its string or its mapping form."""
|
||||
if isinstance(item, dict) and len(item) == 1:
|
||||
return next(iter(item))
|
||||
return item
|
||||
|
||||
|
||||
def validate_dumpers(value):
|
||||
if isinstance(value, str) and value.lower() == "all":
|
||||
return validate_dumpers(list(DUMPER_REGISTRY.keys()))
|
||||
if isinstance(value, list):
|
||||
# a dumper listed twice would register twice; the receiver holds one secondary dumper
|
||||
keys = [_dumper_key(item) for item in value]
|
||||
if all(isinstance(key, str) for key in keys):
|
||||
value = list(dict(zip(keys, value, strict=True)).values())
|
||||
return cv.validate_registry("dumper", DUMPER_REGISTRY)(value)
|
||||
entries = cv.validate_registry("dumper", DUMPER_REGISTRY)(value)
|
||||
# a dumper listed twice would register twice; the receiver holds one secondary dumper
|
||||
return list(
|
||||
{
|
||||
next(k for k in entry if k in DUMPER_REGISTRY): entry for entry in entries
|
||||
}.values()
|
||||
)
|
||||
|
||||
|
||||
def validate_triggers(base_schema):
|
||||
|
||||
@@ -68,7 +68,7 @@ class RCSwitchBase {
|
||||
uint32_t inverted_{}; // bool widened so every field is a word: the table is read from flash
|
||||
};
|
||||
|
||||
// Constant-initialized and kept in flash on every platform; all fields are 32-bit so ESP8266 can read it in place
|
||||
// Constant-initialized and kept in flash on every platform
|
||||
inline constexpr RCSwitchBase RC_SWITCH_PROTOCOLS[] PROGMEM = {
|
||||
{0, 0, 0, 0, 0, 0, false},
|
||||
{350, 10850, 350, 1050, 1050, 350, false},
|
||||
|
||||
@@ -54,21 +54,14 @@ def test_only_used_protocol_sources_are_compiled(
|
||||
|
||||
|
||||
def test_every_registry_name_maps_to_a_protocol_source() -> None:
|
||||
sources = {
|
||||
path.name for path in Path(remote_base.__file__).parent.glob("*_protocol.cpp")
|
||||
}
|
||||
"""A registry name must resolve to a source file or request_protocol rejects it."""
|
||||
names = (
|
||||
set(remote_base.BINARY_SENSOR_REGISTRY)
|
||||
| set(remote_base.DUMPER_REGISTRY)
|
||||
| {key.removeprefix("on_") for key in remote_base.TRIGGER_REGISTRY}
|
||||
)
|
||||
for name in names:
|
||||
stem = (
|
||||
remote_base.protocol_define(name)
|
||||
.removeprefix("USE_REMOTE_PROTOCOL_")
|
||||
.lower()
|
||||
)
|
||||
assert f"{stem}_protocol.cpp" in sources, name
|
||||
assert remote_base._protocol_stem(name) in remote_base._PROTOCOL_STEMS, name
|
||||
|
||||
|
||||
def test_request_protocol_rejects_unknown_names() -> None:
|
||||
|
||||
Reference in New Issue
Block a user