Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
* Trying to fix start up bug
  • Loading branch information
hjuhlin committed Apr 28, 2021
1 parent 0bc30f3 commit cacb3b4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ This is a plugin for Aqua Temp pool heater.
* Added support for target temperature
* Added code to remove old devices (should clean up stuff from 1.3.0 and older)

1.4.1
* Trying to fix start up bug

# Default config
```json
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.0",
"version": "1.4.1",
"description": "This is a plugin for Aqua Temp pool heater.",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 0 additions & 2 deletions src/accessories/ThermometerAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ export class ThermometerAccessory {
this.accessory.addService(this.platform.Service.TemperatureSensor);

this.service.setCharacteristic(this.platform.Characteristic.Name, device.device_nick_name);

this.service.setCharacteristic(this.platform.Characteristic.CurrentTemperature, 0);
}
}
36 changes: 11 additions & 25 deletions src/accessories/ThermostatAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { HttpRequest } from '../utils/httprequest';

export class ThermostatAccessory {
private service: Service;
private startUp: boolean;

constructor(
private readonly platform: AquaTempHomebridgePlatform,
Expand All @@ -16,6 +17,8 @@ export class ThermostatAccessory {
public readonly log: Logger,
public readonly token: string,
) {
const startUp = true;

this.accessory.getService(this.platform.Service.AccessoryInformation)!
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'AquaTemp')
.setCharacteristic(this.platform.Characteristic.Model, 'AquaTempThermostat')
Expand All @@ -32,36 +35,16 @@ export class ThermostatAccessory {
validValues: [0, 1],
});

this.service.setCharacteristic(this.platform.Characteristic.CurrentTemperature, 0);

const httpRequest = new HttpRequest(this.config, log);

httpRequest.GetDeviceStatus(accessory.context.device.device_code, token).then((deviceResults)=> {

const deviceResult = <AquaTempObject>deviceResults;

for (const codeData of deviceResult.object_result) {
if (codeData.code ==='power') {
const isOn = codeData.value==='0'?false:true;
this.service.setCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState,
isOn?this.platform.Characteristic.CurrentHeatingCoolingState.HEAT: this.platform.Characteristic.CurrentHeatingCoolingState.OFF);
}

if (codeData.code ==='T02') {
this.service.setCharacteristic(this.platform.Characteristic.CurrentTemperature, codeData.value);
}

if (codeData.code ==='R02') {
this.service.setCharacteristic(this.platform.Characteristic.TargetTemperature, codeData.value);
}
}
});

this.service.getCharacteristic(this.platform.Characteristic.TargetHeatingCoolingState).onSet(this.setState.bind(this));
this.service.getCharacteristic(this.platform.Characteristic.TargetTemperature).onSet(this.setTemperature.bind(this));

this.startUp = false;
}

setState(value: CharacteristicValue) {
if (this.startUp===true) {
return;
}

let on = false;

Expand All @@ -88,6 +71,9 @@ export class ThermostatAccessory {
}

setTemperature(value: CharacteristicValue) {
if (this.startUp===true) {
return;
}

const temp = value as string;

Expand Down
11 changes: 9 additions & 2 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {

if (start) {
this.discoverDevices();
this.updateDeviceStatus();
}

} else {
Expand Down Expand Up @@ -184,6 +183,12 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {
const aquaTempObject = <AquaTempObject>results;

if (aquaTempObject.is_reuslt_suc) {
this.accessories.forEach(accessory => {
if (this.config['ClearAllAtStartUp'] as boolean) {
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
this.log.info('Removing existing accessory:', accessory.displayName);
}
});

this.log.info('Found ' +aquaTempObject.object_result.length + ' device');

Expand All @@ -207,12 +212,14 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {
}
}

if (found === false || this.config['ClearAllAtStartUp'] as boolean) {
if (found === false) {
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
this.log.info('Removing existing accessory:', accessory.displayName);
}
});

this.updateDeviceStatus();

} else {
this.log.error(aquaTempObject.error_msg);
this.log.error(aquaTempObject.error_code);
Expand Down

0 comments on commit cacb3b4

Please sign in to comment.