Skip to content

Fix ghost device pairing and stale device cache (closes #61) - #62

Open
snurre66 wants to merge 5 commits into
athombv:masterfrom
snurre66:fix/issue-61-pairing-stale-devices
Open

Fix ghost device pairing and stale device cache (closes #61)#62
snurre66 wants to merge 5 commits into
athombv:masterfrom
snurre66:fix/issue-61-pairing-stale-devices

Conversation

@snurre66

Copy link
Copy Markdown

Problem

Resolves #61 where unpowered/previously-paired devices remained in the discovery cache indefinitely and were unintentionally added to Homey alongside chosen devices due to the pair wizard iterating over window.found_devices.

Solution

  1. drivers/homeyduino/pair/add_devices.html: Fixed device addition loop to only add devices present in window.selected_devices.
  2. drivers/homeyduino/device.js: In onDeleted(), reset paired: false and unsubscribe the device so discovery timeout pruning (_deleteAfterTimeout()) cleans up offline removed boards.
  3. drivers/homeyduino/driver.js: In onPairListDevices(), filter out already-paired devices and stale devices whose lastSeen timestamp has timed out. Registered session.setHandler("list_devices") for SDK v3 pair views.

@snurre66

snurre66 commented Aug 15, 2026

Copy link
Copy Markdown
Author

Probably also fixes #50

@snurre66
snurre66 force-pushed the fix/issue-61-pairing-stale-devices branch from 0c69945 to 51dc268 Compare August 15, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #61 by preventing stale/unreachable discovery entries from being presented and/or accidentally paired, and by ensuring removed devices can be pruned from the discovery cache.

Changes:

  • Pair UI now adds only devices explicitly selected by the user (instead of iterating over all discovered devices).
  • Device deletion now marks the underlying discovery device as unpaired and unsubscribes it so discovery timeout pruning can remove it.
  • Pairing device list now filters out already-paired devices and devices whose lastSeen is outside the timeout window; also registers an SDK v3 list_devices session handler.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
drivers/homeyduino/pair/add_devices.html Limits Homey.addDevice calls to selected devices only.
drivers/homeyduino/device.js Ensures deleted devices are marked unpaired/unsubscribed for discovery cleanup.
drivers/homeyduino/driver.js Filters pairing candidates (already paired + stale) and registers list_devices handler for SDK v3.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread drivers/homeyduino/driver.js Outdated
Comment on lines +109 to +112
let settings = existingDevice.getSettings ? existingDevice.getSettings() : null;
if (settings && settings.id) existingIds.add(settings.id);
let data = existingDevice.getData ? existingDevice.getData() : null;
if (data && data.id) existingIds.add(data.id);
Comment on lines 5 to 9
var devices = (window.selected_devices || []).map(function(deviceKey){
return window.found_devices[deviceKey];
}).filter(function(device){
return device && device.data && device.data.id;
});
@wouter-athom

Copy link
Copy Markdown
Contributor

Hey @snurre66, thanks for your contribution! I tested your fix and everything seems to be in order. If you can resolve the issues pointed out by copilot I'll make sure your PR gets merged.

@wouter-athom wouter-athom self-assigned this Aug 18, 2026
@snurre66

snurre66 commented Aug 18, 2026 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Pairing wizard lists/adds a device that has no power and is not reachable on the network

3 participants