Skip to content

Commit

Permalink
Trying to fix token refresh bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuhlin committed May 16, 2021
1 parent 4311b7a commit 1ef81bc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This is a plugin for Aqua Temp pool heater.
1.4.2
* Fixing with correct Characteristic

1.4.3, 1.4.4
1.4.3, 1.4.4, 1.4.5
* Trying to fix token refresh bug


Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": false,
"displayName": "Aqua Temp Plugin",
"name": "homebridge-aqua-temp",
"version": "1.4.4",
"version": "1.4.5",
"description": "This is a plugin for Aqua Temp pool heater.",
"license": "Apache-2.0",
"repository": {
Expand Down
1 change: 0 additions & 1 deletion src/accessories/ThermometerAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class ThermometerAccessory {
private readonly device: ObjectResult,
public readonly config: PlatformConfig,
public readonly log: Logger,
public readonly token: string,
) {
this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'AquaTemp')
Expand Down
13 changes: 10 additions & 3 deletions src/accessories/ThermostatAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export class ThermostatAccessory {
private readonly jsonItem: ObjectResult,
public readonly config: PlatformConfig,
public readonly log: Logger,
public readonly token: string,
) {
const startUp = true;

Expand Down Expand Up @@ -62,7 +61,7 @@ export class ThermostatAccessory {
}

const httpRequest = new HttpRequest(this.config, this.log);
httpRequest.ChangePowerOfDevice(this.accessory.context.device.device_code, on, this.token).then((results)=> {
httpRequest.ChangePowerOfDevice(this.accessory.context.device.device_code, on, this.platform.Token).then((results)=> {

const result = <AquaTempObject>results;

Expand All @@ -75,6 +74,10 @@ export class ThermostatAccessory {
this.log.info('Changed state to ' +(value?'HEAT':'OFF'));
}
}
}).catch((error) => {
if (error==='NotLoggedIn') {
this.platform.getToken(false);
}
});
}

Expand All @@ -86,7 +89,7 @@ export class ThermostatAccessory {
const temp = value as string;

const httpRequest = new HttpRequest(this.config, this.log);
httpRequest.ChangeTargetTemperatureOfDevice(this.accessory.context.device.device_code, temp, this.token).then((results)=> {
httpRequest.ChangeTargetTemperatureOfDevice(this.accessory.context.device.device_code, temp, this.platform.Token).then((results)=> {

const result = <AquaTempObject>results;

Expand All @@ -99,6 +102,10 @@ export class ThermostatAccessory {
this.log.info('Changed target temperature to ' +(value));
}
}
}).catch((error) => {
if (error==='NotLoggedIn') {
this.platform.getToken(false);
}
});
}
}
4 changes: 2 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {

for (const device of aquaTempObject.object_result) {
const thermostatObject = this.getAccessory(device, 'thermostat');
new ThermostatAccessory(this, thermostatObject.accessory, device, this.config, this.log, this.Token);
new ThermostatAccessory(this, thermostatObject.accessory, device, this.config, this.log);
this.addOrRestorAccessory(thermostatObject.accessory, device.device_nick_name, 'thermostat', thermostatObject.exists);

const airObject = this.getAccessory(device, 'thermometer');
new ThermometerAccessory(this, airObject.accessory, device, this.config, this.log, this.Token);
new ThermometerAccessory(this, airObject.accessory, device, this.config, this.log);
this.addOrRestorAccessory(airObject.accessory, device.device_nick_name, 'thermometer', airObject.exists);
}

Expand Down

0 comments on commit 1ef81bc

Please sign in to comment.