diff --git a/README.md b/README.md index 03b7272..775e462 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 1f52a16..bca1422 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "homebridge-aqua-temp", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 1d75795..0bc413b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/accessories/ThermometerAccessory.ts b/src/accessories/ThermometerAccessory.ts index 929391c..5814008 100644 --- a/src/accessories/ThermometerAccessory.ts +++ b/src/accessories/ThermometerAccessory.ts @@ -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); } } diff --git a/src/accessories/ThermostatAccessory.ts b/src/accessories/ThermostatAccessory.ts index a552def..3d9ebe7 100644 --- a/src/accessories/ThermostatAccessory.ts +++ b/src/accessories/ThermostatAccessory.ts @@ -7,6 +7,7 @@ import { HttpRequest } from '../utils/httprequest'; export class ThermostatAccessory { private service: Service; + private startUp: boolean; constructor( private readonly platform: AquaTempHomebridgePlatform, @@ -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') @@ -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 = 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; @@ -88,6 +71,9 @@ export class ThermostatAccessory { } setTemperature(value: CharacteristicValue) { + if (this.startUp===true) { + return; + } const temp = value as string; diff --git a/src/platform.ts b/src/platform.ts index 3eda35f..2ab5418 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -152,7 +152,6 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin { if (start) { this.discoverDevices(); - this.updateDeviceStatus(); } } else { @@ -184,6 +183,12 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin { const 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'); @@ -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);