Skip to content

Commit

Permalink
refactor: return new this in CC.from impls
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Nov 5, 2024
1 parent 4f9acd5 commit ab5676b
Show file tree
Hide file tree
Showing 64 changed files with 330 additions and 279 deletions.
4 changes: 2 additions & 2 deletions packages/cc/src/cc/AlarmSensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export class AlarmSensorCCReport extends AlarmSensorCC {
// ignore zero durations
const duration = raw.payload.readUInt16BE(3) || undefined;

return new AlarmSensorCCReport({
return new this({
// Alarm Sensor reports may be forwarded by a different node, in this case
// (and only then!) the payload contains the original node ID
nodeId: sourceNodeId || ctx.sourceNodeId,
Expand Down Expand Up @@ -496,7 +496,7 @@ export class AlarmSensorCCSupportedReport extends AlarmSensorCC {
AlarmSensorType["General Purpose"],
);

return new AlarmSensorCCSupportedReport({
return new this({
nodeId: ctx.sourceNodeId,
supportedSensorTypes,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/cc/src/cc/AssociationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class AssociationCCSet extends AssociationCC {
const groupId = raw.payload[0];
const nodeIds = [...raw.payload.subarray(1)];

return new AssociationCCSet({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
nodeIds,
Expand Down Expand Up @@ -589,7 +589,7 @@ export class AssociationCCRemove extends AssociationCC {
}
const nodeIds = [...raw.payload.subarray(1)];

return new AssociationCCRemove({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
nodeIds,
Expand Down Expand Up @@ -649,7 +649,7 @@ export class AssociationCCReport extends AssociationCC {
const reportsToFollow = raw.payload[2];
const nodeIds = [...raw.payload.subarray(3)];

return new AssociationCCReport({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
maxNodes,
Expand Down Expand Up @@ -741,7 +741,7 @@ export class AssociationCCGet extends AssociationCC {
validatePayload(raw.payload.length >= 1);
const groupId = raw.payload[0];

return new AssociationCCGet({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
});
Expand Down Expand Up @@ -784,7 +784,7 @@ export class AssociationCCSupportedGroupingsReport extends AssociationCC {
validatePayload(raw.payload.length >= 1);
const groupCount = raw.payload[0];

return new AssociationCCSupportedGroupingsReport({
return new this({
nodeId: ctx.sourceNodeId,
groupCount,
});
Expand Down Expand Up @@ -832,7 +832,7 @@ export class AssociationCCSpecificGroupReport extends AssociationCC {
validatePayload(raw.payload.length >= 1);
const group = raw.payload[0];

return new AssociationCCSpecificGroupReport({
return new this({
nodeId: ctx.sourceNodeId,
group,
});
Expand Down
12 changes: 6 additions & 6 deletions packages/cc/src/cc/AssociationGroupInfoCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC {
raw.payload.subarray(2, 2 + nameLength).toString("utf8"),
);

return new AssociationGroupInfoCCNameReport({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
name,
Expand Down Expand Up @@ -562,7 +562,7 @@ export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC {
validatePayload(raw.payload.length >= 1);
const groupId = raw.payload[0];

return new AssociationGroupInfoCCNameGet({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
});
Expand Down Expand Up @@ -631,7 +631,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC {
groups.push({ groupId, mode, profile, eventCode });
}

return new AssociationGroupInfoCCInfoReport({
return new this({
nodeId: ctx.sourceNodeId,
isListMode,
hasDynamicInfo,
Expand Down Expand Up @@ -743,7 +743,7 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC {
groupId = raw.payload[1];
}

return new AssociationGroupInfoCCInfoGet({
return new this({
nodeId: ctx.sourceNodeId,
refreshCache,
listMode,
Expand Down Expand Up @@ -821,7 +821,7 @@ export class AssociationGroupInfoCCCommandListReport
offset += bytesRead + 1;
}

return new AssociationGroupInfoCCCommandListReport({
return new this({
nodeId: ctx.sourceNodeId,
groupId,
commands,
Expand Down Expand Up @@ -903,7 +903,7 @@ export class AssociationGroupInfoCCCommandListGet
const allowCache = !!(raw.payload[0] & 0b1000_0000);
const groupId = raw.payload[1];

return new AssociationGroupInfoCCCommandListGet({
return new this({
nodeId: ctx.sourceNodeId,
allowCache,
groupId,
Expand Down
6 changes: 3 additions & 3 deletions packages/cc/src/cc/BarrierOperatorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ export class BarrierOperatorCCReport extends BarrierOperatorCC {
currentState = UNKNOWN_STATE;
}

return new BarrierOperatorCCReport({
return new this({
nodeId: ctx.sourceNodeId,
position,
currentState,
Expand Down Expand Up @@ -696,7 +696,7 @@ export class BarrierOperatorCCSignalingCapabilitiesReport
SubsystemType.Audible,
);

return new BarrierOperatorCCSignalingCapabilitiesReport({
return new this({
nodeId: ctx.sourceNodeId,
supportedSubsystemTypes,
});
Expand Down Expand Up @@ -806,7 +806,7 @@ export class BarrierOperatorCCEventSignalingReport extends BarrierOperatorCC {
const subsystemType: SubsystemType = raw.payload[0];
const subsystemState: SubsystemState = raw.payload[1];

return new BarrierOperatorCCEventSignalingReport({
return new this({
nodeId: ctx.sourceNodeId,
subsystemType,
subsystemState,
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/BasicCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class BasicCCSet extends BasicCC {
validatePayload(raw.payload.length >= 1);
const targetValue = raw.payload[0];

return new BasicCCSet({
return new this({
nodeId: ctx.sourceNodeId,
targetValue,
});
Expand Down Expand Up @@ -447,7 +447,7 @@ export class BasicCCReport extends BasicCC {
duration = Duration.parseReport(raw.payload[2]);
}

return new BasicCCReport({
return new this({
nodeId: ctx.sourceNodeId,
currentValue,
targetValue,
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/BatteryCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export class BatteryCCReport extends BatteryCC {
};
}

return new BatteryCCReport({
return new this({
nodeId: ctx.sourceNodeId,
...ccOptions,
});
Expand Down Expand Up @@ -672,7 +672,7 @@ export class BatteryCCHealthReport extends BatteryCC {
true, // The temperature field may be omitted
);

return new BatteryCCHealthReport({
return new this({
nodeId: ctx.sourceNodeId,
maximumCapacity,
temperature,
Expand Down
6 changes: 3 additions & 3 deletions packages/cc/src/cc/BinarySensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export class BinarySensorCCReport extends BinarySensorCC {
type = raw.payload[1];
}

return new BinarySensorCCReport({
return new this({
nodeId: ctx.sourceNodeId,
value,
type,
Expand Down Expand Up @@ -452,7 +452,7 @@ export class BinarySensorCCGet extends BinarySensorCC {
sensorType = raw.payload[0];
}

return new BinarySensorCCGet({
return new this({
nodeId: ctx.sourceNodeId,
sensorType,
});
Expand Down Expand Up @@ -508,7 +508,7 @@ export class BinarySensorCCSupportedReport extends BinarySensorCC {
(t) => t !== 0,
);

return new BinarySensorCCSupportedReport({
return new this({
nodeId: ctx.sourceNodeId,
supportedSensorTypes,
});
Expand Down
4 changes: 2 additions & 2 deletions packages/cc/src/cc/BinarySwitchCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export class BinarySwitchCCSet extends BinarySwitchCC {
duration = Duration.parseSet(raw.payload[1]);
}

return new BinarySwitchCCSet({
return new this({
nodeId: ctx.sourceNodeId,
targetValue,
duration,
Expand Down Expand Up @@ -409,7 +409,7 @@ export class BinarySwitchCCReport extends BinarySwitchCC {
duration = Duration.parseReport(raw.payload[2]);
}

return new BinarySwitchCCReport({
return new this({
nodeId: ctx.sourceNodeId,
currentValue,
targetValue,
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/CRC16CC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class CRC16CCCommandEncapsulation extends CRC16CC {
validatePayload(expectedCRC === actualCRC);

const encapsulated = CommandClass.parse(ccBuffer, ctx);
return new CRC16CCCommandEncapsulation({
return new this({
nodeId: ctx.sourceNodeId,
encapsulated,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/cc/src/cc/CentralSceneCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class CentralSceneCCNotification extends CentralSceneCC {
slowRefresh = !!(raw.payload[1] & 0b1000_0000);
}

return new CentralSceneCCNotification({
return new this({
nodeId: ctx.sourceNodeId,
sequenceNumber,
keyAttribute,
Expand Down Expand Up @@ -447,7 +447,7 @@ export class CentralSceneCCSupportedReport extends CentralSceneCC {
}
}

return new CentralSceneCCSupportedReport({
return new this({
nodeId: ctx.sourceNodeId,
sceneCount,
supportsSlowRefresh,
Expand Down Expand Up @@ -539,7 +539,7 @@ export class CentralSceneCCConfigurationReport extends CentralSceneCC {
validatePayload(raw.payload.length >= 1);
const slowRefresh = !!(raw.payload[0] & 0b1000_0000);

return new CentralSceneCCConfigurationReport({
return new this({
nodeId: ctx.sourceNodeId,
slowRefresh,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/cc/src/cc/ClimateControlScheduleCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class ClimateControlScheduleCCReport extends ClimateControlScheduleCC {
sp.state !== "Unused"
);

return new ClimateControlScheduleCCReport({
return new this({
nodeId: ctx.sourceNodeId,
weekday,
schedule,
Expand Down Expand Up @@ -432,7 +432,7 @@ export class ClimateControlScheduleCCChangedReport
validatePayload(raw.payload.length >= 1);
const changeCounter = raw.payload[0];

return new ClimateControlScheduleCCChangedReport({
return new this({
nodeId: ctx.sourceNodeId,
changeCounter,
});
Expand Down Expand Up @@ -483,7 +483,7 @@ export class ClimateControlScheduleCCOverrideReport
const overrideState: SetbackState = decodeSetbackState(raw.payload[1])
|| raw.payload[1];

return new ClimateControlScheduleCCOverrideReport({
return new this({
nodeId: ctx.sourceNodeId,
overrideType,
overrideState,
Expand Down
2 changes: 1 addition & 1 deletion packages/cc/src/cc/ClockCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class ClockCCReport extends ClockCC {
minute <= 59,
);

return new ClockCCReport({
return new this({
nodeId: ctx.sourceNodeId,
weekday,
hour,
Expand Down
12 changes: 6 additions & 6 deletions packages/cc/src/cc/ColorSwitchCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ export class ColorSwitchCCSupportedReport extends ColorSwitchCC {
ColorComponent["Warm White"],
);

return new ColorSwitchCCSupportedReport({
return new this({
nodeId: ctx.sourceNodeId,
supportedColorComponents,
});
Expand Down Expand Up @@ -772,7 +772,7 @@ export class ColorSwitchCCReport extends ColorSwitchCC {
duration = Duration.parseReport(raw.payload[3]);
}

return new ColorSwitchCCReport({
return new this({
nodeId: ctx.sourceNodeId,
colorComponent,
currentValue,
Expand Down Expand Up @@ -923,7 +923,7 @@ export class ColorSwitchCCGet extends ColorSwitchCC {
validatePayload(raw.payload.length >= 1);
const colorComponent: ColorComponent = raw.payload[0];

return new ColorSwitchCCGet({
return new this({
nodeId: ctx.sourceNodeId,
colorComponent,
});
Expand Down Expand Up @@ -1014,7 +1014,7 @@ export class ColorSwitchCCSet extends ColorSwitchCC {
duration = Duration.parseSet(raw.payload[offset]);
}

return new ColorSwitchCCSet({
return new this({
nodeId: ctx.sourceNodeId,
...colorTable,
duration,
Expand Down Expand Up @@ -1123,7 +1123,7 @@ export class ColorSwitchCCStartLevelChange extends ColorSwitchCC {
duration = Duration.parseSet(raw.payload[3]);
}

return new ColorSwitchCCStartLevelChange({
return new this({
nodeId: ctx.sourceNodeId,
ignoreStartLevel,
direction,
Expand Down Expand Up @@ -1205,7 +1205,7 @@ export class ColorSwitchCCStopLevelChange extends ColorSwitchCC {
validatePayload(raw.payload.length >= 1);
const colorComponent: ColorComponent = raw.payload[0];

return new ColorSwitchCCStopLevelChange({
return new this({
nodeId: ctx.sourceNodeId,
colorComponent,
});
Expand Down
Loading

0 comments on commit ab5676b

Please sign in to comment.