Add Espex.update_adapters/2 for runtime adapter changes - #29
Merged
Merged
Conversation
Lets a host swap adapter modules (or disable a feature with nil) without restarting the Espex tree. Universal Proxy's Bluetooth toggle no longer needs to bounce its ESPHome subtree: update the adapters, then call disconnect_clients/1 so Home Assistant reconnects and reads the new DeviceInfo feature flags. ServerState.merge_adapters/2 validates the change against the known feature keys and rejects non-module values, applying nothing on error. Like update_device_config/2 the change is seen by the next accepted connection: each connection captures the adapter map, the entity and serial-instance lists, and the derived feature flags at accept time. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Adapter validation accepts invalid atoms and can crash the shared server for struct-map inputs.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds runtime adapter replacement so new connections can use updated feature modules without restarting supervision.
Changes:
- Adds validated adapter updates through
Espex,Server, andServerState. - Documents reconnect-based runtime reconfiguration.
- Adds server and TCP integration tests.
File summaries
| File | Description |
|---|---|
lib/espex.ex |
Exposes and documents update_adapters/2. |
lib/espex/server.ex |
Handles adapter-update calls. |
lib/espex/server_state.ex |
Merges and validates adapter changes. |
lib/espex/supervisor.ex |
Documents runtime adapter updates. |
guides/architecture.md |
Explains adapter snapshot behavior. |
README.md |
Advertises runtime adapter replacement. |
test/espex/server_test.exs |
Tests merging, disabling, and rejection. |
test/espex/disconnect_clients_test.exs |
Verifies updated flags after reconnect. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Copilot review on #29 caught two holes in update_adapters/2. is_atom/1 let false or a typo atom through, and the next accepted connection then crashed calling list_instances/0 on it; a value must now be nil or pass Code.ensure_loaded?/1. And a struct satisfied is_map/1, so Enum.reduce_while raised inside Espex.Server, which under :rest_for_one restarts the listener and drops every live connection; the public functions and merge_adapters/2 now guard with is_non_struct_map/1 so a struct fails at the caller. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
Espex.update_adapters/2: replace some or all adapter modules at runtime (nildisables a feature). Keyword list or map; unknown keys and non-module values are rejected with nothing applied. Takes effect on the next accepted connection; pair withdisconnect_clients/1.ServerState.merge_adapters/2added (validated merge);Server.update_adapters/2added.update_adapters/2reports the new Bluetooth feature flags.Espexmoduledoc,Espex.Supervisormoduledoc, architecture guide, README.🤖 Generated with Claude Code