Skip to content

Commit

Permalink
refactor: autosave :D
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 11, 2024
1 parent cbec3d4 commit 9b94e88
Show file tree
Hide file tree
Showing 133 changed files with 1,376 additions and 961 deletions.
16 changes: 16 additions & 0 deletions ZWaveHost properties.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ZWaveHost, properties used:

getDeviceConfig
ownNodeId
homeId
nodeIdType
securityManager
__internalIsMockNode
getSafeCCVersion
getSupportedCCVersion
isCCSecure

getNextCallbackId -> how did zwave-rs do this?

for a specific node: getHighestSecurityClass, hasSecurityClass, setSecurityClass --> GetNode<...> ?
for a specific endpoint: isCCSecure ?
5 changes: 3 additions & 2 deletions packages/cc/src/cc/AlarmSensorCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CCEncodingContext,
CommandClasses,
type EndpointId,
type MaybeNotKnown,
Expand Down Expand Up @@ -421,9 +422,9 @@ export class AlarmSensorCCGet extends AlarmSensorCC {

public sensorType: AlarmSensorType;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.sensorType]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
25 changes: 13 additions & 12 deletions packages/cc/src/cc/AssociationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
SupervisionResult,
} from "@zwave-js/core/safe";
import {
type CCEncodingContext,
CommandClasses,
MAX_NODES,
type MessageOrCCLogEntry,
Expand Down Expand Up @@ -520,9 +521,9 @@ export class AssociationCCSet extends AssociationCC {
public groupId: number;
public nodeIds: number[];

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.groupId, ...this.nodeIds]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -590,12 +591,12 @@ export class AssociationCCRemove extends AssociationCC {
public groupId?: number;
public nodeIds?: number[];

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([
this.groupId || 0,
...(this.nodeIds || []),
]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -679,14 +680,14 @@ export class AssociationCCReport extends AssociationCC {
.reduce((prev, cur) => prev.concat(...cur), []);
}

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([
this.groupId,
this.maxNodes,
this.reportsToFollow,
...this.nodeIds,
]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -731,9 +732,9 @@ export class AssociationCCGet extends AssociationCC {

public groupId: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.groupId]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -772,9 +773,9 @@ export class AssociationCCSupportedGroupingsReport extends AssociationCC {
@ccValue(AssociationCCValues.groupCount)
public groupCount: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.groupCount]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -814,9 +815,9 @@ export class AssociationCCSpecificGroupReport extends AssociationCC {

public group: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.group]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
25 changes: 13 additions & 12 deletions packages/cc/src/cc/AssociationGroupInfoCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CCEncodingContext,
CommandClasses,
type EndpointId,
type MaybeNotKnown,
Expand Down Expand Up @@ -513,12 +514,12 @@ export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC {
return true;
}

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.concat([
Buffer.from([this.groupId, this.name.length]),
Buffer.from(this.name, "utf8"),
]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -557,9 +558,9 @@ export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC {

public groupId: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.groupId]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -649,7 +650,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC {
return true;
}

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.alloc(1 + this.groups.length * 7, 0);

this.payload[0] = (this.isListMode ? 0b1000_0000 : 0)
Expand All @@ -663,7 +664,7 @@ export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC {
// The remaining bytes are zero
}

return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -732,15 +733,15 @@ export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC {
public listMode?: boolean;
public groupId?: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
const isListMode = this.listMode === true;
const optionByte = (this.refreshCache ? 0b1000_0000 : 0)
| (isListMode ? 0b0100_0000 : 0);
this.payload = Buffer.from([
optionByte,
isListMode ? 0 : this.groupId!,
]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -812,7 +813,7 @@ export class AssociationGroupInfoCCCommandListReport
)
public readonly commands: ReadonlyMap<CommandClasses, readonly number[]>;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
// To make it easier to encode possible extended CCs, we first
// allocate as much space as we may need, then trim it again
this.payload = Buffer.allocUnsafe(2 + this.commands.size * 3);
Expand All @@ -827,7 +828,7 @@ export class AssociationGroupInfoCCCommandListReport
}
this.payload[1] = offset - 2; // list length

return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -884,12 +885,12 @@ export class AssociationGroupInfoCCCommandListGet
public allowCache: boolean;
public groupId: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([
this.allowCache ? 0b1000_0000 : 0,
this.groupId,
]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
13 changes: 7 additions & 6 deletions packages/cc/src/cc/BarrierOperatorCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CCEncodingContext,
CommandClasses,
type MaybeNotKnown,
type MaybeUnknown,
Expand Down Expand Up @@ -569,9 +570,9 @@ export class BarrierOperatorCCSet extends BarrierOperatorCC {

public targetState: BarrierState.Open | BarrierState.Closed;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.targetState]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -712,9 +713,9 @@ export class BarrierOperatorCCEventSignalingSet extends BarrierOperatorCC {
public subsystemType: SubsystemType;
public subsystemState: SubsystemState;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.subsystemType, this.subsystemState]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -810,9 +811,9 @@ export class BarrierOperatorCCEventSignalingGet extends BarrierOperatorCC {

public subsystemType: SubsystemType;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.subsystemType]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
9 changes: 5 additions & 4 deletions packages/cc/src/cc/BasicCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CCEncodingContext,
CommandClasses,
Duration,
type MaybeNotKnown,
Expand Down Expand Up @@ -376,9 +377,9 @@ export class BasicCCSet extends BasicCC {

public targetValue: number;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.targetValue]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -485,7 +486,7 @@ export class BasicCCReport extends BasicCC {
return true;
}

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([
this.currentValue ?? 0xfe,
this.targetValue ?? 0xfe,
Expand All @@ -501,7 +502,7 @@ export class BasicCCReport extends BasicCC {
this.payload = this.payload.subarray(0, 1);
}

return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
5 changes: 3 additions & 2 deletions packages/cc/src/cc/BatteryCC.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { timespan } from "@zwave-js/core";
import type {
CCEncodingContext,
MessageOrCCLogEntry,
MessageRecord,
SinglecastCC,
Expand Down Expand Up @@ -527,7 +528,7 @@ export class BatteryCCReport extends BatteryCC {
@ccValue(BatteryCCValues.lowTemperatureStatus)
public readonly lowTemperatureStatus: boolean | undefined;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.isLow ? 0xff : this.level]);
if (this.chargingStatus != undefined) {
this.payload = Buffer.concat([
Expand All @@ -549,7 +550,7 @@ export class BatteryCCReport extends BatteryCC {
]),
]);
}
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
13 changes: 7 additions & 6 deletions packages/cc/src/cc/BinarySensorCC.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
type CCEncodingContext,
CommandClasses,
type EndpointId,
type MaybeNotKnown,
Expand Down Expand Up @@ -391,9 +392,9 @@ export class BinarySensorCCReport extends BinarySensorCC {
public type: BinarySensorType;
public value: boolean;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.value ? 0xff : 0x00, this.type]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -445,9 +446,9 @@ export class BinarySensorCCGet extends BinarySensorCC {

public sensorType: BinarySensorType | undefined;

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = Buffer.from([this.sensorType ?? BinarySensorType.Any]);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down Expand Up @@ -493,13 +494,13 @@ export class BinarySensorCCSupportedReport extends BinarySensorCC {
@ccValue(BinarySensorCCValues.supportedSensorTypes)
public supportedSensorTypes: BinarySensorType[];

public serialize(): Buffer {
public serialize(ctx: CCEncodingContext): Buffer {
this.payload = encodeBitMask(
this.supportedSensorTypes.filter((t) => t !== BinarySensorType.Any),
undefined,
0,
);
return super.serialize();
return super.serialize(ctx);
}

public toLogEntry(host?: ZWaveValueHost): MessageOrCCLogEntry {
Expand Down
Loading

0 comments on commit 9b94e88

Please sign in to comment.