Fix adapter device ID not incrementing when adding new devices#32
Fix adapter device ID not incrementing when adding new devices#32
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughDevice tab creation now allocates and registers a model-backed device ID; adapter switches preserve an existing device "id" by injecting it into the schema form's default values before rebuilding the form. Changes
Sequence Diagram(s)sequenceDiagram
rect rgba(220,220,255,0.5)
participant User
participant Dialog as AdapterDeviceSettings
participant Model as SettingsModel
participant Tab as DeviceConfigTab
participant Schema as SchemaForm
end
Note over User,Dialog: Flow A — Add new device tab
User->>Dialog: click "Add Tab"
Dialog->>Model: addNewDevice()
Model-->>Dialog: newDeviceId
Dialog->>Model: deviceSettings(newDeviceId).setAdapterId(defaultAdapterId)
Dialog->>Tab: create tab (defaultValues with id = newDeviceId)
Tab->>Schema: rebuildSchemaForm(adapterId, defaultValues)
Schema-->>Tab: populated form (id = newDeviceId)
Note over User,Tab: Flow B — Change adapter in existing tab
User->>Tab: select different adapter
Tab->>Tab: read currentValues["id"] (or use _deviceId)
Tab->>Tab: inject id into defaultValues["id"]
Tab->>Schema: rebuildSchemaForm(newAdapterId, defaultValues)
Schema-->>Tab: populated form (id preserved)
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/dialogs/tst_adapterdevicesettings.cpp`:
- Around line 239-270: Add a regression test that exercises the "ID must remain
unchanged when switching adapter" path in DeviceConfigTab::onAdapterChanged:
extend or add a test (e.g., alongside
TestAdapterDeviceSettings::addTabIncrementsDeviceId) that creates a
SettingsModel, sets up two adapters (e.g., "adapterA" and "adapterB") via
setupAdapter, adds a DeviceConfigTab through
AdapterDeviceSettings/AddableTabWidget, captures the assigned device id from
tab->values()["id"], then simulate changing the tab's adapter to the other
adapter (invoke the same adapter-change action used by
DeviceConfigTab::onAdapterChanged) and assert the tab's id remains equal to the
original id, the model still has that deviceId, and
deviceSettings(...)->adapterId() reflects the new adapter; reference
DeviceConfigTab, AdapterDeviceSettings, AddableTabWidget, SettingsModel and
TestAdapterDeviceSettings when locating where to add the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 65e8170b-b793-442e-a28e-4c961563399e
📒 Files selected for processing (4)
src/customwidgets/deviceconfigtab.cppsrc/dialogs/adapterdevicesettings.cpptests/dialogs/tst_adapterdevicesettings.cpptests/dialogs/tst_adapterdevicesettings.h
When adding a new device via AdapterDeviceSettings, the new tab always received the adapter's hardcoded default id (e.g. 1) instead of a unique one, allowing multiple devices to share the same id. No corresponding SettingsModel device was created either, breaking the invariant that adapter-config device ids must match SettingsModel device ids. Fix handleAddTab() to call addNewDevice() for a unique id and set the adapter on the resulting SettingsModel entry. Also fix onAdapterChanged() in DeviceConfigTab to preserve the existing device id when the user switches the protocol adapter, preventing the unique id from being overwritten by the new adapter's defaults. https://claude.ai/code/session_012tQA6XhU6TKDgqzUwzJqx1
Verify that DeviceConfigTab::onAdapterChanged keeps the assigned device ID unchanged when the user switches to a different adapter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
6c41b0e to
8c86c51
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/customwidgets/deviceconfigtab.cpp`:
- Around line 90-96: The code reads id from _pSchemaForm->values() and skips
setting defaultValues["id"] when id is hidden, allowing adapter defaults to
overwrite and produce duplicate IDs; initialize and store a member _deviceId
from the constructor input deviceValues["id"] (or -1 if absent) and then in the
block that currently checks _pSchemaForm and currentId, fall back to _deviceId
when values().value("id") is missing/invalid so defaultValues["id"] is always
populated with the original device ID; update the constructor to accept and set
_deviceId and update the code around _pSchemaForm->values() to prefer form id
then _deviceId.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5a633c65-4c4d-4210-a82b-f00fd5bd923d
📒 Files selected for processing (4)
src/customwidgets/deviceconfigtab.cppsrc/dialogs/adapterdevicesettings.cpptests/dialogs/tst_adapterdevicesettings.cpptests/dialogs/tst_adapterdevicesettings.h
🚧 Files skipped from review as they are similar to previous changes (2)
- tests/dialogs/tst_adapterdevicesettings.h
- tests/dialogs/tst_adapterdevicesettings.cpp
When the adapter's schema marks the id field as hidden, SchemaFormWidget does not include it in values(), causing onAdapterChanged to skip the defaultValues["id"] assignment and lose the original device ID. Store _deviceId from the constructor's deviceValues so it can serve as a fallback when the form returns an invalid id. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When adding a new device via AdapterDeviceSettings, the new tab always received the adapter's hardcoded default id (e.g. 1) instead of a unique one, allowing multiple devices to share the same id. No corresponding SettingsModel device was created either, breaking the invariant that adapter-config device ids must match SettingsModel device ids.
Fix handleAddTab() to call addNewDevice() for a unique id and set the adapter on the resulting SettingsModel entry. Also fix onAdapterChanged() in DeviceConfigTab to preserve the existing device id when the user switches the protocol adapter, preventing the unique id from being overwritten by the new adapter's defaults.
https://claude.ai/code/session_012tQA6XhU6TKDgqzUwzJqx1
Summary by CodeRabbit
Bug Fixes
Tests