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: set priority for messages to sleeping nodes again #6953

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions packages/zwave-js/src/lib/driver/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5381,6 +5381,9 @@ ${handlers.length} left`,
this.ensureReady();

let node: ZWaveNode | undefined;
if (isNodeQuery(msg) || isCommandClassContainer(msg)) {
node = this.getNodeUnsafe(msg);
}

if (options.priority == undefined) {
options.priority = getDefaultPriority(msg);
Expand Down
6 changes: 4 additions & 2 deletions packages/zwave-js/src/lib/log/Driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ export class DriverLogger extends ZWaveLoggerBase<DriverLogContext> {
}]`
: "";
const command = isCommandClassContainer(trns.message)
? ` (${trns.message.command.constructor.name})`
? `: ${trns.message.command.constructor.name}`
: "";
message += `\n· ${prefix} ${
FunctionType[trns.message.functionType]
}${command}${postfix}`;
}${command}${postfix} (P: ${
getEnumMemberName(MessagePriority, trns.priority)
})`;
}
} else {
message += " (empty)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,102 @@ integrationTest(
},
},
);

integrationTest(
"When a command to a sleeping node is pending, other commands are still handled",
{
// debug: true,

provisioningDirectory: path.join(
__dirname,
"fixtures/nodeAsleepMessageOrder",
),

nodeCapabilities: [
{
id: 10,
capabilities: {
commandClasses: [
CommandClasses.Basic,
CommandClasses["Wake Up"],
],
isListening: false,
isFrequentListening: false,
},
},
{
id: 17,
capabilities: {
commandClasses: [CommandClasses.Basic],
},
},
],

customSetup: async (driver, mockController, mockNodes) => {
const [mockNode10] = mockNodes;

const doNotAnswerWhenAsleep: MockNodeBehavior = {
onControllerFrame(controller, self, frame) {
if (!mockNode10.autoAckControllerFrames) return true;
},
};
mockNode10.defineBehavior(doNotAnswerWhenAsleep);
},

testBody: async (t, driver, nodes, mockController, mockNodes) => {
const [node10, node17] = nodes;
const [mockNode10, mockNode17] = mockNodes;

// Node 10 is sleeping
node10.markAsAsleep();
mockNode10.autoAckControllerFrames = false;

// Queue a command to node 10
const commandToNode10 = node10.commandClasses.Basic.set(60);

// Queue a command to node 17
const commandToNode17 = node17.commandClasses.Basic.set(99);

driver.driverLog.print("BEFORE wakeup");
driver.driverLog.sendQueue(driver["queue"]);

let result = await Promise.race([
wait(500).then(() => "timeout"),
commandToNode17.then(() => "ok"),
]);
t.is(result, "ok");

// The first command should not have been sent
mockNode10.assertReceivedControllerFrame(
(f) =>
f.type === MockZWaveFrameType.Request
&& f.payload instanceof BasicCCGet,
{
noMatch: true,
},
);

driver.driverLog.print("AFTER first command");
driver.driverLog.sendQueue(driver["queue"]);

// Node 10 wakes up
mockNode10.autoAckControllerFrames = true;
const cc: CommandClass = new WakeUpCCWakeUpNotification(
mockNode10.host,
{
nodeId: mockController.host.ownNodeId,
},
);
mockNode10.sendToController(createMockZWaveRequestFrame(cc, {
ackRequested: false,
}));

// And the first command should be sent
result = await Promise.race([
wait(500).then(() => "timeout"),
commandToNode10.then(() => "ok"),
]);
t.is(result, "ok");
},
},
);
Loading