Skip to content

Commit

Permalink
Initializing showVoltage in migrateSettings()
Browse files Browse the repository at this point in the history
  • Loading branch information
philipostli committed Oct 28, 2024
1 parent 5525a02 commit 8ed3346
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
15 changes: 13 additions & 2 deletions drivers/go/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ export class GoCharger extends Homey.Device {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}
}

if (this.getSetting('showVoltage')){
await this.addCapability('measure_voltage.phase1');
await this.addCapability('measure_voltage.phase2');
await this.addCapability('measure_voltage.phase3');
}else{
await this.removeCapability('measure_voltage.phase1');
await this.removeCapability('measure_voltage.phase2');
await this.removeCapability('measure_voltage.phase3');
}

}

/**
* Verify all expected capabilities and apply changes to capabilities.
Expand Down Expand Up @@ -138,7 +149,7 @@ export class GoCharger extends Homey.Device {
newSettings: { [key: string]: string };
changedKeys: string[];
}): Promise<string | void> {
this.log('GoCharger settings where changed: ', JSON.stringify(changes));
//this.log('GoCharger settings where changed: ', JSON.stringify(changes));

// Allow user to select if they want phase voltage as a capability or not.
if (changes.changedKeys.some((k) => k === 'showVoltage')) {
Expand Down
12 changes: 11 additions & 1 deletion drivers/home/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export class HomeCharger extends Homey.Device {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}

if (this.getSetting('showVoltage')){
await this.addCapability('measure_voltage.phase1');
await this.addCapability('measure_voltage.phase2');
await this.addCapability('measure_voltage.phase3');
}else{
await this.removeCapability('measure_voltage.phase1');
await this.removeCapability('measure_voltage.phase2');
await this.removeCapability('measure_voltage.phase3');
}
}

/**
Expand Down Expand Up @@ -127,7 +137,7 @@ export class HomeCharger extends Homey.Device {
newSettings: { [key: string]: string };
changedKeys: string[];
}): Promise<string | void> {
this.log('HomeCharger settings where changed: ', JSON.stringify(changes));
//this.log('HomeCharger settings where changed: ', JSON.stringify(changes));

// Allow user to select if they want phase voltage as a capability or not.
if (changes.changedKeys.some((k) => k === 'showVoltage')) {
Expand Down
12 changes: 11 additions & 1 deletion drivers/pro/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ export class ProCharger extends Homey.Device {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}

if (this.getSetting('showVoltage')){
await this.addCapability('measure_voltage.phase1');
await this.addCapability('measure_voltage.phase2');
await this.addCapability('measure_voltage.phase3');
}else{
await this.removeCapability('measure_voltage.phase1');
await this.removeCapability('measure_voltage.phase2');
await this.removeCapability('measure_voltage.phase3');
}
}

/**
Expand Down Expand Up @@ -129,7 +139,7 @@ export class ProCharger extends Homey.Device {
newSettings: { [key: string]: string };
changedKeys: string[];
}): Promise<string | void> {
this.log('ProCharger settings where changed: ', JSON.stringify(changes));
//this.log('ProCharger settings where changed: ', JSON.stringify(changes));

// Allow user to select if they want phase voltage as a capability or not.
if (changes.changedKeys.some((k) => k === 'showVoltage')) {
Expand Down

0 comments on commit 8ed3346

Please sign in to comment.