Skip to content

Commit

Permalink
Load DescriptorServer before changing (#1344)
Browse files Browse the repository at this point in the history
* Load DescriptorServer before changing

... to prevent locking issues when not fully initialized.
fixes #1339

* FIx example paths

fixes #1343

* Fix example paths

* Add PowerSourceServer test

Confirmed not working before last change to PowerSourceServer but works now

---------

Co-authored-by: Greg Lauckhart <[email protected]>
  • Loading branch information
Apollon77 and lauckhart authored Oct 31, 2024
1 parent 020e96d commit 15d283a
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ The main work (all changes without a GitHub username in brackets in the below li
## __WORK IN PROGRESS__
-->

## __WORK IN PROGRESS__

- @matter/node
- Fix: Ensures to fully load the Descriptor cluster before adding additional device types


## 0.11.1 (2024-10-31)

- @matter/create
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
"lint-fix": "eslint --fix \"**/*.ts\"",
"format": "prettier --write 'packages/**/*.ts' 'codegen/**/*.ts' 'chip-testing/**/*.ts' 'compat/**/*.ts'",
"format-verify": "prettier --check 'packages/**/*.ts' 'codegen/**/*.ts' 'chip-testing/**/*.ts'",
"matter-device": "matter-run packages/examples/src/examples/device-onoff-cli/DeviceNode.ts",
"matter-bridge": "matter-run packages/examples/src/examples/device-onoff-bridge-cli/BridgedDevicesNode.ts",
"matter-composeddevice": "matter-run packages/examples/src/examples/device-onoff-composed-cli/ComposedDeviceNode.ts",
"matter-multidevice": "matter-run packages/examples/src/examples/device-onoff-multiple-devices-cli/MultiDeviceNode.ts",
"matter-controller": "matter-run packages/examples/src/examples/controller-cli/ControllerNode.ts",
"matter-device": "matter-run packages/examples/src/device-onoff/DeviceNode.ts",
"matter-bridge": "matter-run packages/examples/src/device-bridge-onoff/BridgedDevicesNode.ts",
"matter-composeddevice": "matter-run packages/examples/src/device-composed-onoff/ComposedDeviceNode.ts",
"matter-multidevice": "matter-run packages/examples/src/device-multipleonoff/MultiDeviceNode.ts",
"matter-controller": "matter-run packages/examples/src/controller/ControllerNode.ts",
"shell": "matter-run packages/nodejs-shell/src/app.ts",
"relock": "node -e \"fs.rmSync('package-lock.json', { force: true }); fs.rmSync('node_modules', { recursive: true, force: true });\" && npm install"
},
Expand Down
38 changes: 19 additions & 19 deletions packages/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@
"clean": "matter-build clean",
"build": "matter-build",
"build-clean": "matter-build --clean",
"matter-light": "matter-run src/examples/device-onoff-light/LightDevice.ts",
"matter-measuredsocket": "matter-run src/examples/device-socket-with-measurement/MeasuredSocketDevice.ts",
"matter-sensor": "matter-run src/examples/device-temperature-humidity-sensor-cli/SensorDeviceNode.ts",
"matter-excelsior1000": "matter-run src/examples/device-window-covering-light-composed/IlluminatedRollerShade.ts",
"matter-device": "matter-run src/examples/device-onoff-cli/DeviceNode.ts",
"matter-bridge": "matter-run src/examples/device-onoff-bridge-cli/BridgedDevicesNode.ts",
"matter-composeddevice": "matter-run src/examples/device-onoff-composed-cli/ComposedDeviceNode.ts",
"matter-multidevice": "matter-run src/examples/device-onoff-multiple-devices-cli/MultiDeviceNode.ts",
"matter-controller": "matter-run src/examples/controller-cli/ControllerNode.ts",
"bundle-device": "esbuild src/examples/device-onoff-cli/DeviceNode.ts --bundle --platform=node --conditions=esbuild --external:@stoprocent/bleno --external:@stoprocent/bluetooth-hci-socket --sourcemap --minify --outfile=build/bundle/DeviceNode.cjs",
"matter-light": "matter-run src/device-onoff-light/LightDevice.ts",
"matter-measuredsocket": "matter-run src/device-measuring-socket/MeasuredSocketDevice.ts",
"matter-sensor": "matter-run src/device-sensor/SensorDeviceNode.ts",
"matter-excelsior1000": "matter-run src/device-composed-wc-light/IlluminatedRollerShade.ts",
"matter-device": "matter-run src/device-onoff/DeviceNode.ts",
"matter-bridge": "matter-run src/device-bridge-onoff/BridgedDevicesNode.ts",
"matter-composeddevice": "matter-run src/device-composed-onoff/ComposedDeviceNode.ts",
"matter-multidevice": "matter-run src/device-multiple-onoff/MultiDeviceNode.ts",
"matter-controller": "matter-run src/controller/ControllerNode.ts",
"bundle-device": "esbuild src/device-onoff/DeviceNode.ts --bundle --platform=node --conditions=esbuild --external:@stoprocent/bleno --external:@stoprocent/bluetooth-hci-socket --sourcemap --minify --outfile=build/bundle/DeviceNode.cjs",
"matter-device-bundled": "node --enable-source-maps build/bundle/DeviceNode.cjs"
},
"bin": {
"matter-light": "dist/esm/examples/device-onoff-light/LightDevice.ts",
"matter-measuredsocket": "dist/esm/examples/device-socket-with-measurement/MeasuredSocketDevice.ts",
"matter-excelsior1000": "dist/esm/examples/device-window-covering-light-composed/IlluminatedRollerShade.ts",
"matter-sensor": "dist/esm/examples/device-temperature-humidity-sensor-cli/SensorDeviceNode.js",
"matter-device": "dist/esm/examples/device-onoff-cli/DeviceNode.js",
"matter-bridge": "dist/esm/examples/device-onoff-bridge-cli/BridgedDevicesNode.js",
"matter-composeddevice": "dist/esm/examples/device-onoff-composed-cli/ComposedDeviceNode.js",
"matter-multidevice": "dist/esm/examples/device-onoff-multiple-devices-cli/MultiDeviceNode.js",
"matter-controller": "dist/esm/examples/controller-cli/ControllerNode.js"
"matter-light": "dist/esm/device-onoff-light/LightDevice.ts",
"matter-measuredsocket": "dist/esm/device-measuring-socket/MeasuredSocketDevice.ts",
"matter-excelsior1000": "dist/esm/device-composed-wc-light/IlluminatedRollerShade.ts",
"matter-sensor": "dist/esm/device-sensor/SensorDeviceNode.js",
"matter-device": "dist/esm/device-onoff/DeviceNode.js",
"matter-bridge": "dist/esm/device-bridge-onoff/BridgedDevicesNode.js",
"matter-composeddevice": "dist/esm/device-composed-onoff/ComposedDeviceNode.js",
"matter-multidevice": "dist/esm/device-multiple-onoff/MultiDeviceNode.js",
"matter-controller": "dist/esm/controller/ControllerNode.js"
},
"dependencies": {
"@matter/main": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class BridgedDeviceBasicInformationServer extends BridgedDeviceBasicInfor
}

// Ensure endpoint is a bridged node
this.agent.get(DescriptorServer).addDeviceTypes("BridgedNode");
(await this.agent.load(DescriptorServer)).addDeviceTypes("BridgedNode");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { OtaSoftwareUpdateProviderBehavior } from "./OtaSoftwareUpdateProviderBe
* This is the default server implementation of {@link OtaSoftwareUpdateProviderBehavior}.
*/
export class OtaSoftwareUpdateProviderServer extends OtaSoftwareUpdateProviderBehavior {
override initialize() {
this.agent.get(DescriptorServer).addDeviceTypes("OtaProvider");
override async initialize() {
(await this.agent.load(DescriptorServer)).addDeviceTypes("OtaProvider");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { OtaSoftwareUpdateRequestorBehavior } from "./OtaSoftwareUpdateRequestor
* This is the default server implementation of {@link OtaSoftwareUpdateRequestorBehavior}.
*/
export class OtaSoftwareUpdateRequestorServer extends OtaSoftwareUpdateRequestorBehavior {
override initialize() {
this.agent.get(DescriptorServer).addDeviceTypes("OtaRequestor");
override async initialize() {
(await this.agent.load(DescriptorServer)).addDeviceTypes("OtaRequestor");
}
}
4 changes: 2 additions & 2 deletions packages/node/src/behaviors/power-source/PowerSourceServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PowerSourceBehavior } from "./PowerSourceBehavior.js";
* This is the default server implementation of {@link PowerSourceBehavior}.
*/
export class PowerSourceServer extends PowerSourceBehavior {
override initialize() {
this.agent.get(DescriptorServer).addDeviceTypes("PowerSource");
override async initialize() {
(await this.agent.load(DescriptorServer)).addDeviceTypes("PowerSource");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const PowerTopologyBase = PowerTopologyBehavior.with(
* the SetTopology and DynamicPowerFlow features are used.
*/
export class PowerTopologyServerLogic extends PowerTopologyBase {
override initialize(): void {
override async initialize() {
if (this.agent.has(ElectricalPowerMeasurementBehavior) || this.agent.has(ElectricalEnergyMeasurementBehavior)) {
this.agent.get(DescriptorServer).addDeviceTypes("ElectricalSensor");
(await this.agent.load(DescriptorServer)).addDeviceTypes("ElectricalSensor");
}

if (this.state.activeEndpoints !== undefined) {
Expand Down
38 changes: 38 additions & 0 deletions packages/node/test/behaviors/power-source/PowerSourceServerTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2022-2024 Matter.js Authors
* SPDX-License-Identifier: Apache-2.0
*/

import { PowerSourceDt } from "@matter/model";
import { PowerSource } from "@matter/types/clusters/power-source";
import { PowerSourceServer } from "../../../src/behaviors/power-source/PowerSourceServer.js";
import { HumiditySensorDevice } from "../../../src/devices/humidity-sensor.js";
import { MockEndpoint } from "../../endpoint/mock-endpoint.js";
import { MockServerNode } from "../../node/mock-server-node.js";

describe("PowerSourceServer", () => {
it("successfully augments descriptor", async () => {
const node = new MockServerNode();
const sensor = new MockEndpoint(
HumiditySensorDevice.with(
PowerSourceServer.with(PowerSource.Feature.Battery, PowerSource.Feature.Replaceable).set({
status: PowerSource.PowerSourceStatus.Active,
order: 1,
description: "aa batteries",
batChargeLevel: PowerSource.BatChargeLevel.Ok,
batReplacementNeeded: false,
batReplaceability: PowerSource.BatReplaceability.UserReplaceable,
batReplacementDescription: "open, replace",
batQuantity: 2,
}),
),
{ owner: node },
);
await node.add(sensor);
expect(sensor.state.descriptor.deviceTypeList).deep.equals([
{ deviceType: HumiditySensorDevice.deviceType, revision: HumiditySensorDevice.deviceRevision },
{ deviceType: PowerSourceDt.id, revision: PowerSourceDt.revision },
]);
});
});
2 changes: 1 addition & 1 deletion packages/protocol/src/mdns/MdnsScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ export class MdnsScanner implements Scanner {
};
} else {
logger.debug(
`Adding operational device ${matterName} in cache (interface ${netInterface}) with TXT data:`,
`Adding operational device ${matterName} in cache (interface ${netInterface}, ttl=${ttl}) with TXT data:`,
MdnsScanner.discoveryDataDiagnostics(txtData),
);
device = {
Expand Down

0 comments on commit 15d283a

Please sign in to comment.