Skip to content

Commit

Permalink
refactor: remove host instance from CCs
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone committed Oct 15, 2024
1 parent 3671f11 commit 6437856
Show file tree
Hide file tree
Showing 242 changed files with 1,840 additions and 2,728 deletions.
14 changes: 5 additions & 9 deletions packages/cc/src/cc/AlarmSensorCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
CCEncodingContext,
GetValueDB,
ZWaveApplicationHost,
ZWaveHost,
} from "@zwave-js/host/safe";
import { getEnumMemberName, isEnumMember, pick } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
Expand Down Expand Up @@ -131,7 +130,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI {
public async get(sensorType?: AlarmSensorType) {
this.assertSupportsCommand(AlarmSensorCommand, AlarmSensorCommand.Get);

const cc = new AlarmSensorCCGet(this.applHost, {
const cc = new AlarmSensorCCGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
sensorType,
Expand All @@ -150,7 +149,7 @@ export class AlarmSensorCCAPI extends PhysicalCCAPI {
AlarmSensorCommand.SupportedGet,
);

const cc = new AlarmSensorCCSupportedGet(this.applHost, {
const cc = new AlarmSensorCCSupportedGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
});
Expand Down Expand Up @@ -324,10 +323,9 @@ duration: ${currentValue.duration}`;
@CCCommand(AlarmSensorCommand.Report)
export class AlarmSensorCCReport extends AlarmSensorCC {
public constructor(
host: ZWaveHost,
options: CommandClassDeserializationOptions,
) {
super(host, options);
super(options);
validatePayload(this.payload.length >= 5, this.payload[1] !== 0xff);
// Alarm Sensor reports may be forwarded by a different node, in this case
// (and only then!) the payload contains the original node ID
Expand Down Expand Up @@ -405,10 +403,9 @@ export interface AlarmSensorCCGetOptions extends CCCommandOptions {
@expectedCCResponse(AlarmSensorCCReport, testResponseForAlarmSensorGet)
export class AlarmSensorCCGet extends AlarmSensorCC {
public constructor(
host: ZWaveHost,
options: CommandClassDeserializationOptions | AlarmSensorCCGetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
// TODO: Deserialize payload
throw new ZWaveError(
Expand Down Expand Up @@ -443,10 +440,9 @@ export class AlarmSensorCCGet extends AlarmSensorCC {
@CCCommand(AlarmSensorCommand.SupportedReport)
export class AlarmSensorCCSupportedReport extends AlarmSensorCC {
public constructor(
host: ZWaveHost,
options: CommandClassDeserializationOptions,
) {
super(host, options);
super(options);
validatePayload(this.payload.length >= 1);
const bitMaskLength = this.payload[0];
validatePayload(this.payload.length >= 1 + bitMaskLength);
Expand Down
35 changes: 14 additions & 21 deletions packages/cc/src/cc/AssociationCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
CCParsingContext,
GetValueDB,
ZWaveApplicationHost,
ZWaveHost,
} from "@zwave-js/host/safe";
import { validateArgs } from "@zwave-js/transformers";
import { distinct } from "alcalzone-shared/arrays";
Expand Down Expand Up @@ -106,7 +105,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
AssociationCommand.SupportedGroupingsGet,
);

const cc = new AssociationCCSupportedGroupingsGet(this.applHost, {
const cc = new AssociationCCSupportedGroupingsGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
});
Expand All @@ -126,7 +125,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
AssociationCommand.SupportedGroupingsReport,
);

const cc = new AssociationCCSupportedGroupingsReport(this.applHost, {
const cc = new AssociationCCSupportedGroupingsReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupCount,
Expand All @@ -142,7 +141,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
public async getGroup(groupId: number) {
this.assertSupportsCommand(AssociationCommand, AssociationCommand.Get);

const cc = new AssociationCCGet(this.applHost, {
const cc = new AssociationCCGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand All @@ -168,7 +167,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
AssociationCommand.Report,
);

const cc = new AssociationCCReport(this.applHost, {
const cc = new AssociationCCReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
...options,
Expand All @@ -186,7 +185,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
): Promise<SupervisionResult | undefined> {
this.assertSupportsCommand(AssociationCommand, AssociationCommand.Set);

const cc = new AssociationCCSet(this.applHost, {
const cc = new AssociationCCSet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand Down Expand Up @@ -222,7 +221,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
);
}

const cc = new AssociationCCRemove(this.applHost, {
const cc = new AssociationCCRemove({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
...options,
Expand Down Expand Up @@ -269,7 +268,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
AssociationCommand.SpecificGroupGet,
);

const cc = new AssociationCCSpecificGroupGet(this.applHost, {
const cc = new AssociationCCSpecificGroupGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
});
Expand All @@ -294,7 +293,7 @@ export class AssociationCCAPI extends PhysicalCCAPI {
AssociationCommand.SpecificGroupReport,
);

const cc = new AssociationCCSpecificGroupReport(this.applHost, {
const cc = new AssociationCCSpecificGroupReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
group,
Expand Down Expand Up @@ -508,10 +507,9 @@ export interface AssociationCCSetOptions extends CCCommandOptions {
@useSupervision()
export class AssociationCCSet extends AssociationCC {
public constructor(
host: ZWaveHost,
options: CommandClassDeserializationOptions | AssociationCCSetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
this.groupId = this.payload[0];
Expand Down Expand Up @@ -568,12 +566,11 @@ export interface AssociationCCRemoveOptions {
@useSupervision()
export class AssociationCCRemove extends AssociationCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| (AssociationCCRemoveOptions & CCCommandOptions),
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
if (this.payload[0] !== 0) {
Expand Down Expand Up @@ -624,12 +621,11 @@ export interface AssociationCCReportSpecificOptions {
@CCCommand(AssociationCommand.Report)
export class AssociationCCReport extends AssociationCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| (AssociationCCReportSpecificOptions & CCCommandOptions),
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 3);
Expand Down Expand Up @@ -713,10 +709,9 @@ export interface AssociationCCGetOptions extends CCCommandOptions {
@expectedCCResponse(AssociationCCReport)
export class AssociationCCGet extends AssociationCC {
public constructor(
host: ZWaveHost,
options: CommandClassDeserializationOptions | AssociationCCGetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
this.groupId = this.payload[0];
Expand Down Expand Up @@ -756,12 +751,11 @@ export interface AssociationCCSupportedGroupingsReportOptions
@CCCommand(AssociationCommand.SupportedGroupingsReport)
export class AssociationCCSupportedGroupingsReport extends AssociationCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationCCSupportedGroupingsReportOptions,
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
Expand Down Expand Up @@ -799,12 +793,11 @@ export interface AssociationCCSpecificGroupReportOptions {
@CCCommand(AssociationCommand.SpecificGroupReport)
export class AssociationCCSpecificGroupReport extends AssociationCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| (AssociationCCSpecificGroupReportOptions & CCCommandOptions),
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
Expand Down
31 changes: 12 additions & 19 deletions packages/cc/src/cc/AssociationGroupInfoCC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {
CCEncodingContext,
GetValueDB,
ZWaveApplicationHost,
ZWaveHost,
} from "@zwave-js/host/safe";
import { cpp2js, getEnumMemberName, num2hex } from "@zwave-js/shared/safe";
import { validateArgs } from "@zwave-js/transformers";
Expand Down Expand Up @@ -112,7 +111,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.NameGet,
);

const cc = new AssociationGroupInfoCCNameGet(this.applHost, {
const cc = new AssociationGroupInfoCCNameGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand All @@ -133,7 +132,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.NameReport,
);

const cc = new AssociationGroupInfoCCNameReport(this.applHost, {
const cc = new AssociationGroupInfoCCNameReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand All @@ -151,7 +150,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.InfoGet,
);

const cc = new AssociationGroupInfoCCInfoGet(this.applHost, {
const cc = new AssociationGroupInfoCCInfoGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand Down Expand Up @@ -184,7 +183,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.InfoReport,
);

const cc = new AssociationGroupInfoCCInfoReport(this.applHost, {
const cc = new AssociationGroupInfoCCInfoReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
...options,
Expand All @@ -205,7 +204,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.CommandListGet,
);

const cc = new AssociationGroupInfoCCCommandListGet(this.applHost, {
const cc = new AssociationGroupInfoCCCommandListGet({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand All @@ -230,7 +229,7 @@ export class AssociationGroupInfoCCAPI extends PhysicalCCAPI {
AssociationGroupInfoCommand.CommandListReport,
);

const cc = new AssociationGroupInfoCCCommandListReport(this.applHost, {
const cc = new AssociationGroupInfoCCCommandListReport({
nodeId: this.endpoint.nodeId,
endpoint: this.endpoint.index,
groupId,
Expand Down Expand Up @@ -474,12 +473,11 @@ export interface AssociationGroupInfoCCNameReportOptions
@CCCommand(AssociationGroupInfoCommand.NameReport)
export class AssociationGroupInfoCCNameReport extends AssociationGroupInfoCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationGroupInfoCCNameReportOptions,
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
Expand Down Expand Up @@ -542,12 +540,11 @@ export interface AssociationGroupInfoCCNameGetOptions extends CCCommandOptions {
@expectedCCResponse(AssociationGroupInfoCCNameReport)
export class AssociationGroupInfoCCNameGet extends AssociationGroupInfoCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationGroupInfoCCNameGetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
this.groupId = this.payload[0];
Expand Down Expand Up @@ -588,15 +585,14 @@ export interface AssociationGroupInfoCCInfoReportSpecificOptions {
@CCCommand(AssociationGroupInfoCommand.InfoReport)
export class AssociationGroupInfoCCInfoReport extends AssociationGroupInfoCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| (
& AssociationGroupInfoCCInfoReportSpecificOptions
& CCCommandOptions
),
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 1);
Expand Down Expand Up @@ -708,12 +704,11 @@ export type AssociationGroupInfoCCInfoGetOptions =
@expectedCCResponse(AssociationGroupInfoCCInfoReport)
export class AssociationGroupInfoCCInfoGet extends AssociationGroupInfoCC {
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationGroupInfoCCInfoGetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
const optionByte = this.payload[0];
Expand Down Expand Up @@ -773,12 +768,11 @@ export class AssociationGroupInfoCCCommandListReport
extends AssociationGroupInfoCC
{
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationGroupInfoCCCommandListReportOptions,
) {
super(host, options);
super(options);

if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
Expand Down Expand Up @@ -866,12 +860,11 @@ export class AssociationGroupInfoCCCommandListGet
extends AssociationGroupInfoCC
{
public constructor(
host: ZWaveHost,
options:
| CommandClassDeserializationOptions
| AssociationGroupInfoCCCommandListGetOptions,
) {
super(host, options);
super(options);
if (gotDeserializationOptions(options)) {
validatePayload(this.payload.length >= 2);
this.allowCache = !!(this.payload[0] & 0b1000_0000);
Expand Down
Loading

0 comments on commit 6437856

Please sign in to comment.