Skip to content

Commit

Permalink
Fix PowerTopology implementation and Device type adding logic (#1200)
Browse files Browse the repository at this point in the history
* Do not assert activeEndpoints when not available

* makes sure to always initialize Endpoint Devicetypes
  • Loading branch information
Apollon77 authored Sep 19, 2024
1 parent ef3610f commit 96e0dc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/node/src/behaviors/descriptor/DescriptorServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ export class DescriptorServer extends DescriptorBehavior {
// Initialize ServerList
this.state.serverList = this.#serverList;

// Initialize device type list
// Initialize DeviceTypeList
this.#initializeDeviceTypeList();
}

/** Initialize device type list when it is not already initialized. */
#initializeDeviceTypeList() {
if (!this.state.deviceTypeList.length) {
const partType = this.endpoint.type;
this.state.deviceTypeList = [
Expand Down Expand Up @@ -73,6 +78,7 @@ export class DescriptorServer extends DescriptorBehavior {
* @param deviceTypes an array of objects or named device types as defined in {@link MatterModel.standard}
*/
addDeviceTypes(...deviceTypes: (DescriptorServer.DeviceType | string)[]) {
this.#initializeDeviceTypeList(); // Initialize if not already done
const list = this.state.deviceTypeList;

nextInput: for (let newDeviceType of deviceTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export class PowerTopologyServerLogic extends PowerTopologyBase {
this.agent.get(DescriptorServer).addDeviceTypes("ElectricalSensor");
}

this.#assertActiveEndpointsAllowed(this.state.activeEndpoints);

this.reactTo(this.events.activeEndpoints$Changing, this.#assertActiveEndpointsAllowed);
if (this.state.activeEndpoints !== undefined) {
this.#assertActiveEndpointsAllowed(this.state.activeEndpoints);
this.reactTo(this.events.activeEndpoints$Changing, this.#assertActiveEndpointsAllowed);
}
}

#assertActiveEndpointsAllowed(list: EndpointNumber[]) {
Expand Down

0 comments on commit 96e0dc9

Please sign in to comment.