[remote_base] Reject unknown protocol names and log a dropped secondary dumper

This commit is contained in:
J. Nick Koston
2026-09-11 04:38:10 -05:00
parent 12795852ca
commit 4ca50d86bc
3 changed files with 23 additions and 12 deletions
+9 -5
View File
@@ -136,15 +136,19 @@ def protocol_define(name: str) -> str:
return f"USE_REMOTE_PROTOCOL_{_protocol_stem(name).upper()}"
def request_protocol(name: str) -> None:
"""Keep a protocol's source file in the build; components using it from C++ must call this."""
cg.add_define(protocol_define(name))
_PROTOCOL_STEMS = sorted(
path.name.removesuffix("_protocol.cpp")
for path in Path(__file__).parent.glob("*_protocol.cpp")
)
def request_protocol(name: str) -> None:
"""Keep a protocol's source file in the build; components using it from C++ must call this."""
if _protocol_stem(name) not in _PROTOCOL_STEMS:
raise ValueError(f"Unknown remote protocol {name!r}")
cg.add_define(protocol_define(name))
# Only the protocol sources a configuration uses are compiled
FILTER_SOURCE_FILES = filter_source_files_from_defines(
{f"{stem}_protocol.cpp": protocol_define(stem) for stem in _PROTOCOL_STEMS}
@@ -114,15 +114,16 @@ void RemoteReceiverBase::register_listener(RemoteReceiverListener *listener) {
#ifdef REMOTE_BASE_DUMPER_COUNT
void RemoteReceiverBase::register_dumper(RemoteReceiverDumperBase *dumper) {
if (dumper->is_secondary()) {
this->secondary_dumper_ = dumper;
if (this->secondary_dumper_ == nullptr) {
this->secondary_dumper_ = dumper;
return;
}
} else if (this->dumpers_.size() < REMOTE_BASE_DUMPER_COUNT) {
this->dumpers_.push_back(dumper);
return;
}
if (this->dumpers_.size() == REMOTE_BASE_DUMPER_COUNT) {
ESP_LOGE(TAG, "No %s slot: register it from to_code() with remote_base.add_%s", LOG_STR_LITERAL("dumper"),
LOG_STR_LITERAL("dumper"));
return;
}
this->dumpers_.push_back(dumper);
ESP_LOGE(TAG, "No %s slot: register it from to_code() with remote_base.add_%s", LOG_STR_LITERAL("dumper"),
LOG_STR_LITERAL("dumper"));
}
#endif
@@ -71,6 +71,12 @@ def test_every_registry_name_maps_to_a_protocol_source() -> None:
assert f"{stem}_protocol.cpp" in sources, name
def test_request_protocol_rejects_unknown_names() -> None:
"""A misspelled protocol would otherwise surface only as a link error."""
with pytest.raises(ValueError, match="toshiba"):
remote_base.request_protocol("toshiba")
def test_dump_list_is_deduplicated_across_forms() -> None:
dumpers = remote_base.validate_dumpers(["raw", {"raw": None}, "nec", "nec"])
assert [name for name, _ in dumpers] == ["raw", "nec"]