Skip to content

Commit

Permalink
Implement setACDemandControl
Browse files Browse the repository at this point in the history
  • Loading branch information
Matze2 committed Oct 4, 2024
1 parent 33cebe2 commit 0404c83
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/DaikinAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ export class DaikinAC {
});
}

/**
* Changes the passed options, the rest remains unchanged
*/
public setACDemandControl(obj: Partial<DemandControl>, callback: defaultCallback<DemandControl>) {
this.clearUpdateTimeout();
this._daikinRequest.getACDemandControl((err, _ret, completeValues) => {
if (err || completeValues === null) {
this.initUpdateTimeout();
if (callback) callback(err, completeValues);
return;
}
// we read the current data and change that set in values
completeValues.overwrite(obj);
this._daikinRequest.setACDemandControl(completeValues, (errSet, _ret, daikinSetResponse) => {
if (this._logger) this._logger(JSON.stringify(daikinSetResponse));
this.getACDemandControl((errGet, daikinGetResponse) => {
this.initUpdateTimeout();
const errFinal = errSet ? errSet : errGet;
if (callback) callback(errFinal, daikinGetResponse);
});
});
});
}

public getACSensorInfo(callback: defaultCallback<SensorInfoResponse>) {
this._daikinRequest.getACSensorInfo((err, _ret, daikinResponse) => {
if (this._logger) this._logger(JSON.stringify(daikinResponse));
Expand Down
12 changes: 12 additions & 0 deletions src/DaikinACRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ export class DaikinACRequest {
});
}

public setACDemandControl(obj: DemandControl, callback: DaikinResponseCb<SetCommandResponse>) {
try {
const requestDict = obj.getRequestDict();
this.doPost(`http://${this.ip}/aircon/set_demand_control`, requestDict, (data, _response) => {
const dict = DaikinDataParser.processResponse(data, callback, requestDict);
if (dict !== null) SetCommandResponse.parseResponse(dict, callback);
});
} catch (e) {
callback(e instanceof Error ? e : new Error(e as string), null, null);
}
}

public getACSensorInfo(callback: DaikinResponseCb<SensorInfoResponse>) {
this.doGet(`http://${this.ip}/aircon/get_sensor_info`, {}, (data, _response) => {
const dict = DaikinDataParser.processResponse(data, callback);
Expand Down

0 comments on commit 0404c83

Please sign in to comment.