Skip to content

Commit

Permalink
Merge pull request #25 from philipostli/23-add-firmware-to-settings
Browse files Browse the repository at this point in the history
23 Add firmware to settings
  • Loading branch information
PatrickE94 authored Oct 25, 2024
2 parents c8baa2a + f485756 commit 5525a02
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down Expand Up @@ -1263,6 +1279,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down Expand Up @@ -1412,6 +1444,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down
30 changes: 30 additions & 0 deletions drivers/go/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class GoCharger extends Homey.Device {
);

await this.migrateCapabilities();
await this.migrateSettings();
this.registerCapabilityListeners();

this.cronTasks.push(
Expand All @@ -44,6 +45,29 @@ export class GoCharger extends Homey.Device {
this.log('GoCharger has been initialized');
}

/**
* Migrate settings from the old settings format to the new one.
* If the deviceid setting is empty, poll the charger info and store the device id.
*/
private async migrateSettings() {
if (this.api === undefined) return;

if (this.getSetting('deviceid') === ""){
await this.api.getCharger(this.getData().id)
.then((charger) => {
this.setSettings({
deviceid: charger.DeviceId,
});
})
.then(() => {
this.logToDebug(`Got charger info - added device id`);
})
.catch((e) => {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}
}

/**
* Verify all expected capabilities and apply changes to capabilities.
*
Expand Down Expand Up @@ -346,6 +370,12 @@ export class GoCharger extends Homey.Device {
);
break;

case ApolloDeviceObservation.SmartComputerSoftwareApplicationVersion:
await this.setSettings({
firmware: state.ValueAsString,
});
break;

// The data for the previous session is JSON stringified into this state
// variable
case ApolloDeviceObservation.CompletedSession:
Expand Down
16 changes: 16 additions & 0 deletions drivers/go/driver.settings.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down
1 change: 1 addition & 0 deletions drivers/go/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class GoDriver extends Homey.Driver {
settings: {
username,
password,
deviceid: charger.DeviceId,
},
})) || []
);
Expand Down
30 changes: 30 additions & 0 deletions drivers/home/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class HomeCharger extends Homey.Device {
);

await this.migrateCapabilities();
await this.migrateSettings();
this.registerCapabilityListeners();

this.cronTasks.push(
Expand All @@ -44,6 +45,29 @@ export class HomeCharger extends Homey.Device {
this.log('HomeCharger has been initialized');
}

/**
* Migrate settings from the old settings format to the new one.
* If the deviceid setting is empty, poll the charger info and store the device id.
*/
private async migrateSettings() {
if (this.api === undefined) return;

if (this.getSetting('deviceid') === ""){
await this.api.getCharger(this.getData().id)
.then((charger) => {
this.setSettings({
deviceid: charger.DeviceId,
});
})
.then(() => {
this.logToDebug(`Got charger info - added device id`);
})
.catch((e) => {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}
}

/**
* Verify all expected capabilities and apply changes to capabilities.
*
Expand Down Expand Up @@ -335,6 +359,12 @@ export class HomeCharger extends Homey.Device {
);
break;

case SmartDeviceObservation.SmartComputerSoftwareApplicationVersion:
await this.setSettings({
firmware: state.ValueAsString,
});
break;

// The data for the previous session is JSON stringified into this state
// variable
case SmartDeviceObservation.CompletedSession:
Expand Down
16 changes: 16 additions & 0 deletions drivers/home/driver.settings.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down
1 change: 1 addition & 0 deletions drivers/home/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class HomeDriver extends Homey.Driver {
settings: {
username,
password,
deviceid: charger.DeviceId,
},
})) || []
);
Expand Down
30 changes: 30 additions & 0 deletions drivers/pro/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class ProCharger extends Homey.Device {
);

await this.migrateCapabilities();
await this.migrateSettings();
this.registerCapabilityListeners();

this.cronTasks.push(
Expand All @@ -44,6 +45,29 @@ export class ProCharger extends Homey.Device {
this.log('ProCharger has been initialized');
}

/**
* Migrate settings from the old settings format to the new one.
* If the deviceid setting is empty, poll the charger info and store the device id.
*/
private async migrateSettings() {
if (this.api === undefined) return;

if (this.getSetting('deviceid') === ""){
await this.api.getCharger(this.getData().id)
.then((charger) => {
this.setSettings({
deviceid: charger.DeviceId,
});
})
.then(() => {
this.logToDebug(`Got charger info - added device id`);
})
.catch((e) => {
this.logToDebug(`Failed to poll charger info: ${e}`);
});
}
}

/**
* Verify all expected capabilities and apply changes to capabilities.
*
Expand Down Expand Up @@ -337,6 +361,12 @@ export class ProCharger extends Homey.Device {
);
break;

case SmartDeviceObservation.SmartComputerSoftwareApplicationVersion:
await this.setSettings({
firmware: state.ValueAsString,
});
break;

// The data for the previous session is JSON stringified into this state
// variable
case SmartDeviceObservation.CompletedSession:
Expand Down
16 changes: 16 additions & 0 deletions drivers/pro/driver.settings.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@
"en": "Show voltage per phase"
},
"value": false
},
{
"id": "firmware",
"type": "label",
"label": {
"en": "Firmware version"
},
"value": ""
},
{
"id": "deviceid",
"type": "label",
"label": {
"en": "Device ID"
},
"value": ""
}
]
},
Expand Down
1 change: 1 addition & 0 deletions drivers/pro/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class ProDriver extends Homey.Driver {
settings: {
username,
password,
deviceid: charger.DeviceId,
},
})) || []
);
Expand Down

0 comments on commit 5525a02

Please sign in to comment.