Skip to content

Add Espex.update_adapters/2 for runtime adapter changes - #29

Merged
bbangert merged 2 commits into
mainfrom
feat/update-adapters
Sep 15, 2026
Merged

bbangert merged 2 commits into
mainfrom
feat/update-adapters

Conversation

@bbangert

Copy link
Copy Markdown
Owner
  • Espex.update_adapters/2: replace some or all adapter modules at runtime (nil disables 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 with disconnect_clients/1.
  • ServerState.merge_adapters/2 added (validated merge); Server.update_adapters/2 added.
  • Tests: Server merge/disable/reject cases; real-TCP case showing a reconnect after update_adapters/2 reports the new Bluetooth feature flags.
  • Docs: Espex moduledoc, Espex.Supervisor moduledoc, architecture guide, README.

🤖 Generated with Claude Code

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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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, and ServerState.
  • 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.

Comment thread lib/espex/server_state.ex Outdated
Comment thread lib/espex/server_state.ex
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The API, validation, state transition, integration behavior, tests, and documentation are consistent and complete.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 0 new
  • Review effort level: Balanced

@bbangert
bbangert merged commit 740512f into main Sep 15, 2026
4 checks passed
@bbangert
bbangert deleted the feat/update-adapters branch September 15, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants