fix: address 8 preexisting bugs found during code audit#521
Open
rjullien wants to merge 1 commit into
Open
Conversation
1. Copy-paste in async_create_and_refresh_coordinators: 2nd block refreshed deco_coordinator instead of clients_coordinator during config flow validation. 2. async_reboot_deco: id = next(iter(ids)) if len == 1 else None then id[0] → TypeError when device has != 1 identifier. Uses generator to find the DOMAIN identifier directly. 3. Service closure captures last-loaded coordinator in multi-entry setups. Now dynamically resolves coordinator from hass.data by matching the device MAC. Guards against duplicate registration. 4. async_forward_entry_setups via async_create_task (racy): now properly awaited per HA recommendations. 5. Client coordinator returns None when decos == 0: subsequent access to .get() on None would crash. Returns self.data or empty dict. 6. snake_case_to_title_space(None) crash when nickname missing from API response: falls back to MAC address. 7. Type annotations: dict[str:Any] (slice syntax) → dict[str, Any], cast([str], ...) → cast(list[str], ...). 8. Cookie regex sysauth=[a-f0-9]+ too strict: firmware could return uppercase or other chars. Relaxed to [a-zA-Z0-9_.-]+. Also: manifest key order fixed for hassfest validation.
db8c421 to
aa97135
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Code audit found 8 bugs (some multi-entry only, some edge-case crashes). All fixes are minimal and targeted.
Bug Fixes
__init__.pyclients_coordinator._async_update_data()__init__.pyid[0]onNonewhen device has ≠ 1 identifier__init__.py__init__.pyasync_forward_entry_setupsviaasync_create_task(racy)awaitedcoordinator.pyNonewhen decos == 0self.dataor{}coordinator.pysnake_case_to_title_space(None)when nickname missingdict[str:Any](slice syntax) /cast([str], ...)dict[str, Any],cast(list[str], ...)api.py[a-f0-9]+too strict for some firmware[a-zA-Z0-9_.-]+Also
manifest.json: key order corrected for hassfest (domain,name, then alphabetical)Testing
Tested on real TP-Link Deco M4 mesh (4 nodes). No regressions observed.