Skip to content

Commit

Permalink
2.1 added supprot for silence mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hjuhlin committed Oct 18, 2021
1 parent 40998b6 commit 38db769
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ This is a plugin for Aqua Temp pool heater.
2.0.0
* Added Eve Total Power Consumption

2.1.0
* Added support for silence mode.

# Default config
```json
"platforms": [
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": "2.0.1",
"version": "2.1.0",
"description": "This is a plugin for Aqua Temp pool heater.",
"license": "Apache-2.0",
"repository": {
Expand Down
34 changes: 34 additions & 0 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 serviceSwitch: Service;
private startUp: boolean;

constructor(
Expand Down Expand Up @@ -47,6 +48,11 @@ export class ThermostatAccessory {
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.serviceSwitch = this.accessory.getService(this.platform.Service.Switch) || this.accessory.addService(this.platform.Service.Switch);
this.serviceSwitch.setCharacteristic(this.platform.Characteristic.On, false);
this.serviceSwitch.getCharacteristic(this.platform.Characteristic.On).on('set', this.setOn.bind(this));


if (this.config['ViewElectricPowerUsage'] as boolean) {
this.service.addOptionalCharacteristic(this.platform.customCharacteristic.characteristic.ElectricPower);
this.service.addOptionalCharacteristic(this.platform.customCharacteristic.characteristic.TotalPowerConsumption);
Expand Down Expand Up @@ -124,6 +130,34 @@ export class ThermostatAccessory {
});
}

setOn(value: CharacteristicValue, callback: CharacteristicSetCallback) {
if (this.startUp===true) {
return;
}

const onOff = value ? '1': '0';

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

const result = <AquaTempObject>results;

if (result.is_reuslt_suc===false) {
this.log.error(result.error_msg);
this.log.error(result.error_code);
this.log.error(result.error_msg_code);
} else {
this.log.info('Changed silence mode to ' +(value));
}
}).catch((error) => {
if (error==='NotLoggedIn') {
this.platform.getToken(false);
}
});

callback(null);
}

setResetTotal(value: CharacteristicValue, callback: CharacteristicSetCallback) {
this.accessory.context.totalenergy = 0;
this.accessory.context.lastReset = value;
Expand Down
11 changes: 10 additions & 1 deletion src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {
if (deviceResult.is_reuslt_suc) {
const thermostatObject = this.getAccessory(device, 'thermostat');
const thermostatService = thermostatObject.accessory.getService(this.Service.Thermostat);
const thermostatSwitchService = thermostatObject.accessory.getService(this.Service.Switch);

const thermometerObject = this.getAccessory(device, 'thermometer');
const thermometerService = thermometerObject.accessory.getService(this.Service.TemperatureSensor);
Expand Down Expand Up @@ -168,6 +169,14 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {
}
}

if (thermostatSwitchService!==undefined && codeData.code ==='Manual-mute') {
const isOn = codeData.value==='1'?true: false;
thermostatSwitchService.updateCharacteristic(this.Characteristic.On, isOn);

if (this.config['Debug'] as boolean) {
this.log.info('Update silence mode for ' + device.device_nick_name + ': '+isOn);
}
}
}

if (this.config['ViewElectricPowerUsage'] as boolean) {
Expand Down Expand Up @@ -348,7 +357,7 @@ export class AquaTempHomebridgePlatform implements DynamicPlatformPlugin {

const thermostatObject = this.getAccessory(device, 'thermostat');
if (this.config['EveLoging'] as boolean === true) {
const fakeGatoService = new this.FakeGatoHistoryService('thermo', thermostatObject.accessory,
const fakeGatoService = new this.FakeGatoHistoryService('custom', thermostatObject.accessory,
{log: this.log, storage: 'fs', disableTimer:true});

thermostatObject.accessory.context.fakeGatoService = fakeGatoService;
Expand Down
34 changes: 33 additions & 1 deletion src/utils/httprequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class HttpRequest {
},
body: {
device_code: deviceCode,
protocal_codes: ['T02', 'T05', 'T12', 'R02', 'power'],
protocal_codes: ['T02', 'T05', 'T12', 'R02', 'power', 'Manual-mute'],
},
json: true,
}, (error, response, body) => {
Expand Down Expand Up @@ -161,4 +161,36 @@ export class HttpRequest {
});
});
}

ChangeSilenceModeOfDevice(deviceCode: string, value: string, token: string) {
return new Promise((resolve, reject) => {
request(
{
url: this.urlUpdateDevice,
method: 'POST',
headers: {
'x-token': token,
},
body: {
param: [{
device_code: deviceCode,
value: value,
protocol_code: 'Manual-mute',
}],
},
json: true,
}, (error, response, body) => {
if (response.statusCode === 401) {
reject('NotLoggedIn');
}

if (error) {
reject(error);
} else {
resolve(body);
}
});
});
}

}

0 comments on commit 38db769

Please sign in to comment.