Skip to content

Commit

Permalink
Get demand control data as the last step
Browse files Browse the repository at this point in the history
To not risk that existing data cannot be retrieved anymore
  • Loading branch information
Matze2 committed Sep 28, 2024
1 parent 79afa3c commit 8b7ddf0
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/DaikinAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ export class DaikinAC {
if (this._updateCallback) this._updateCallback(err);
return;
}
this.getACDemandControl((err, _info) => {
this.getACSensorInfo((err, _info) => {
if (err) {
this.initUpdateTimeout();
if (this._updateCallback) this._updateCallback(err);
return;
}
this.getACSensorInfo((err, _info) => {
this.getACDemandControl((err, _info) => {
this.initUpdateTimeout();
if (this._updateCallback) this._updateCallback(err);
});
Expand Down Expand Up @@ -191,6 +191,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

0 comments on commit 8b7ddf0

Please sign in to comment.