Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: identification of primary controller role on older controllers #7174

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/zwave-js/src/lib/controller/Controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ export class ZWaveController
}
}

// This seems odd, but isPrimary comes from the Serial API init data command,
// while isSecondary comes from the GetControllerCapabilities command. They don't really do what their name implies
// and sometimes contradict each other...
private _isPrimary: MaybeNotKnown<boolean>;
private _isSecondary: MaybeNotKnown<boolean>;

private _isUsingHomeIdFromOtherNetwork: MaybeNotKnown<boolean>;
Expand Down Expand Up @@ -888,6 +892,11 @@ export class ZWaveController
/** The role of the controller on the network */
public get role(): MaybeNotKnown<ControllerRole> {
if (this._wasRealPrimary) return ControllerRole.Primary;
// Ideally we'd rely on wasRealPrimary, but there are some older controllers out there where this flag isn't set.
if (this._isPrimary && this._isSIS && this._isSecondary === false) {
return ControllerRole.Primary;
}

switch (this._isSecondary) {
case true:
return ControllerRole.Secondary;
Expand Down Expand Up @@ -6939,7 +6948,7 @@ ${associatedNodes.join(", ")}`,
// and remember the new info
this._zwaveApiVersion = initData.zwaveApiVersion;
this._zwaveChipType = initData.zwaveChipType;
this._isSecondary = !initData.isPrimary;
this._isPrimary = initData.isPrimary;
this._isSIS = initData.isSIS;
this._nodeType = initData.nodeType;
this._supportsTimers = initData.supportsTimers;
Expand Down
Loading