Skip to content

Commit

Permalink
Merge pull request #268 from Matze2/expose-demand-control-vars
Browse files Browse the repository at this point in the history
Add support to read demand control data
  • Loading branch information
Apollon77 authored Oct 4, 2024
2 parents 158db62 + bdef0da commit 0c110c3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -47,7 +47,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
node-version: [16.x, 18.x, 20.x, 22.x]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
Expand Down Expand Up @@ -75,7 +75,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
node-version: [20.x]

steps:
- name: Checkout code
Expand Down
31 changes: 29 additions & 2 deletions src/DaikinAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
YearPowerResponse,
} from './models';
import { DaikinACOptions, DaikinACRequest, Logger } from './DaikinACRequest';
import { DemandControl } from './models/DemandControl';

export * from './DaikinACTypes';

Expand All @@ -25,6 +26,9 @@ export class DaikinAC {
get currentACControlInfo(): ControlInfo | null {
return this._currentACControlInfo;
}
get currentACDemandControl(): DemandControl | null {
return this._currentACDemandControl;
}
get currentACSensorInfo(): SensorInfoResponse | null {
return this._currentACSensorInfo;
}
Expand All @@ -47,6 +51,8 @@ export class DaikinAC {
private _currentACModelInfo: null | ModelInfoResponse = null;
private _currentACControlInfo: null | ControlInfo = null;
private _currentACSensorInfo: null | SensorInfoResponse = null;
private _currentACDemandControl: null | DemandControl = null;
private _acDemandControlSupported = true;

private _logger: null | Logger;
private _daikinRequest: DaikinACRequest;
Expand Down Expand Up @@ -105,8 +111,15 @@ export class DaikinAC {
return;
}
this.getACSensorInfo((err, _info) => {
this.initUpdateTimeout();
if (this._updateCallback) this._updateCallback(err);
if (err || !this._acDemandControlSupported) {
this.initUpdateTimeout();
if (this._updateCallback) this._updateCallback(err);
return;
}
this.getACDemandControl((_err, _info) => {
this.initUpdateTimeout();
if (this._updateCallback) this._updateCallback(null);
});
});
});
}
Expand Down Expand Up @@ -170,6 +183,20 @@ export class DaikinAC {
});
}

public getACDemandControl(callback: defaultCallback<DemandControl>) {
this._daikinRequest.getACDemandControl((err, _ret, daikinResponse) => {
if (this._logger) this._logger(JSON.stringify(daikinResponse));
if (!err) {
this._currentACDemandControl = daikinResponse;
} else {
if (this._logger) this._logger(`Disabling demand control support: ${err.message}`);
this._acDemandControlSupported = false;
}

if (callback) callback(err, daikinResponse);
});
}

public getACSensorInfo(callback: defaultCallback<SensorInfoResponse>) {
this._daikinRequest.getACSensorInfo((err, _ret, daikinResponse) => {
if (this._logger) this._logger(JSON.stringify(daikinResponse));
Expand Down
8 changes: 8 additions & 0 deletions src/DaikinACRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './models';
import { SetCommandResponse, SetSpecialModeRequest } from './models';
import { SpecialModeKind } from './DaikinACTypes';
import { DemandControl } from './models/DemandControl';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const RestClient = require('node-rest-client').Client;
Expand Down Expand Up @@ -240,6 +241,13 @@ export class DaikinACRequest {
}
}

public getACDemandControl(callback: DaikinResponseCb<DemandControl>) {
this.doGet(`http://${this.ip}/aircon/get_demand_control`, {}, (data, _response) => {
const dict = DaikinDataParser.processResponse(data, callback);
if (dict !== null) DemandControl.parseResponse(dict, callback);
});
}

public getACSensorInfo(callback: DaikinResponseCb<SensorInfoResponse>) {
this.doGet(`http://${this.ip}/aircon/get_sensor_info`, {}, (data, _response) => {
const dict = DaikinDataParser.processResponse(data, callback);
Expand Down
19 changes: 19 additions & 0 deletions src/models/DemandControl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DaikinDataParser, ResponseDict } from '../DaikinDataParser';
import { DaikinResponseCb } from '../DaikinACRequest';

export class DemandControl {
public type?: number;
public enabled?: boolean;
public mode?: number;
public maxPower?: number;

// ret=OK,type=1,en_demand=1,mode=0,max_pow=55,scdl_per_day=4,moc=0,tuc=0,wec=0,thc=0,frc=0,sac=0,suc=0
public static parseResponse(dict: ResponseDict, cb: DaikinResponseCb<DemandControl>): void {
const result = new DemandControl();
result.type = DaikinDataParser.resolveInteger(dict, 'type');
result.enabled = DaikinDataParser.resolveBool(dict, 'en_demand');
result.mode = DaikinDataParser.resolveInteger(dict, 'mode');
result.maxPower = DaikinDataParser.resolveInteger(dict, 'max_pow');
cb(null, 'OK', result);
}
}

0 comments on commit 0c110c3

Please sign in to comment.