Skip to content

Extract KnownDeviceRegistry, use it in all device factories#95

Merged
heavyrubberslave merged 2 commits into
mainfrom
chore/known-device-registry
Jul 16, 2026
Merged

Extract KnownDeviceRegistry, use it in all device factories#95
heavyrubberslave merged 2 commits into
mainfrom
chore/known-device-registry

Conversation

@heavyrubberslave

@heavyrubberslave heavyrubberslave commented Jul 14, 2026

Copy link
Copy Markdown
Member

Centralizes the previously duplicated known-device lookup/creation/persist logic (found in SlvCtrlPlusDeviceFactory, ButtplugIoDeviceFactory, AiroticDeviceProvider and Zc95DeviceFactory) into a single shared KnownDeviceRegistry, and skips the settings.json write/broadcast when persisting an already-known, unchanged identity.

Estim2bDeviceFactory now resolves an identity through the registry too (for a stable, human-readable device name during a single connection) but never persists it, since the estim2b transport has no way to derive a deterministic device id, unlike zc95 (firmware-reported serial no.) or slvCtrlPlus/Airotic/ Buttplug.io.

Summary by CodeRabbit

  • New Features

    • Added centralized device recognition and naming, helping reconnecting devices retain their identity.
    • New devices can receive provided names or automatically generated names.
    • Device records are saved only when necessary, preventing duplicate entries.
  • Bug Fixes

    • Improved handling when a known device’s type changes by rebuilding its identity appropriately.
  • Tests

    • Added coverage for device recognition, persistence, reconnect behavior, naming, and device factory integration.

Centralizes the previously duplicated known-device lookup/creation/persist
logic (found in SlvCtrlPlusDeviceFactory, ButtplugIoDeviceFactory,
AiroticDeviceProvider and Zc95DeviceFactory) into a single shared
KnownDeviceRegistry, and skips the settings.json write/broadcast when
persisting an already-known, unchanged identity.

Estim2bDeviceFactory now resolves an identity through the registry too (for a
stable, human-readable device name during a single connection) but never
persists it, since the estim2b transport has no way to derive a deterministic
device id, unlike zc95 (firmware-reported serial no.) or slvCtrlPlus/Airotic/
Buttplug.io.
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2981e497-c129-4a96-b9dd-f5cc988eed30

📥 Commits

Reviewing files that changed from the base of the PR and between 1822628 and bfa2bf1.

📒 Files selected for processing (10)
  • src/device/knownDeviceRegistry.ts
  • src/device/protocol/airotic/airoticDeviceProvider.ts
  • src/device/protocol/buttplugIo/buttplugIoDeviceFactory.ts
  • src/device/protocol/estim2b/estim2bDeviceFactory.ts
  • src/device/protocol/slvCtrlPlus/slvCtrlPlusDeviceFactory.ts
  • src/device/protocol/zc95/zc95DeviceFactory.ts
  • src/serviceMap.ts
  • src/serviceProvider/deviceServiceProvider.ts
  • tests/unit/device/knownDeviceRegistry.spec.ts
  • tests/unit/device/protocol/zc95/zc95DeviceFactory.spec.ts

📝 Walkthrough

Walkthrough

A shared KnownDeviceRegistry now handles known-device resolution and persistence. Device providers and factories receive the registry through service wiring, replacing direct Settings and name-generator usage. Registry behavior and Zc95 integration tests are updated accordingly.

Changes

Known device registry integration

Layer / File(s) Summary
Registry resolution and persistence contract
src/device/knownDeviceRegistry.ts, tests/unit/device/knownDeviceRegistry.spec.ts
Adds centralized known-device lookup, type mismatch handling, name selection, and instance-aware persistence with unit and integration coverage.
Protocol factory and provider adoption
src/device/protocol/..., tests/unit/device/protocol/zc95/...
Updates Airotic, ButtplugIo, Estim2b, SlvCtrlPlus, and Zc95 integrations to resolve and persist devices through the registry.
Service registration and dependency wiring
src/serviceMap.ts, src/serviceProvider/deviceServiceProvider.ts
Registers device.knownDeviceRegistry and injects it into the affected device factories and provider.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DeviceProvider
  participant DeviceFactory
  participant KnownDeviceRegistry
  participant Settings
  DeviceProvider->>KnownDeviceRegistry: resolve device identity
  DeviceFactory->>KnownDeviceRegistry: resolve device identity
  KnownDeviceRegistry->>Settings: read known-device entry
  Settings-->>KnownDeviceRegistry: existing entry or none
  KnownDeviceRegistry-->>DeviceFactory: resolved KnownDevice
  DeviceFactory->>KnownDeviceRegistry: persist after successful creation
  KnownDeviceRegistry->>Settings: add new instance when required
Loading

Possibly related PRs

Suggested labels: patch

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main refactor: extracting KnownDeviceRegistry and wiring it through the device creation code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/known-device-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@heavyrubberslave heavyrubberslave added the patch Creates a new patch/bugfix release if merged label Jul 15, 2026
@heavyrubberslave
heavyrubberslave marked this pull request as ready for review July 15, 2026 05:38
@heavyrubberslave
heavyrubberslave merged commit afb2358 into main Jul 16, 2026
7 checks passed
@heavyrubberslave
heavyrubberslave deleted the chore/known-device-registry branch July 16, 2026 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Creates a new patch/bugfix release if merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant