Socket
Socket
Sign inDemoInstall

daikin-controller

Package Overview
Dependencies
7
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.2 to 2.0.0

.eslintrc.js

510

lib/DaikinAC.js

@@ -1,272 +0,266 @@

/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
var DaikinACRequest = require('./DaikinACRequest');
var DaikinACTypes = require('./DaikinACTypes');
function DaikinAC(ip, options, callback) {
if (typeof options === 'function' && !callback) {
callback = options;
options= {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DaikinAC = void 0;
const DaikinACRequest_1 = require("./DaikinACRequest");
class DaikinAC {
constructor(ip, options, callback) {
this._currentACModelInfo = null;
this._currentACControlInfo = null;
this._currentACSensorInfo = null;
this._updateInterval = null;
this._updateCallback = null;
this._currentCommonBasicInfo = null;
this._updateTimeout = null;
this._logger = null;
if (options.logger) {
this._logger = options.logger;
}
this._daikinRequest = new DaikinACRequest_1.DaikinACRequest(ip, options);
this.getCommonBasicInfo((err, _info) => {
if (err) {
if (callback)
callback(err, null);
return;
}
this.getACModelInfo(callback);
});
}
if (!options) {
options = {};
get currentACModelInfo() {
return this._currentACModelInfo;
}
this.logger = null;
if (options.logger) {
this.logger = options.logger;
get currentACControlInfo() {
return this._currentACControlInfo;
}
this.daikinRequest = new DaikinACRequest(ip, options);
this.updateInterval = null;
this.updateTimeout = null;
this.updateCallback = null;
this.currentCommonBasicInfo = null;
this.currentACModelInfo = null;
this.currentACControlInfo = null;
this.currentACSensorInfo = null;
var self = this;
this.getCommonBasicInfo(function(err) {
if (err) {
if (callback) callback(err);
return;
}
self.getACModelInfo(callback);
});
}
DaikinAC.prototype.setUpdate = function setUpdate(updateInterval, callback) {
this.updateInterval = updateInterval;
if (typeof callback === 'function') {
this.updateCallback = callback;
get currentACSensorInfo() {
return this._currentACSensorInfo;
}
this.updateData();
};
DaikinAC.prototype.initUpdateTimeout = function initUpdateTimeout() {
var self = this;
if (this.updateInterval && !this.updateTimeout) {
if (this.logger) this.logger('start update timeout');
this.updateTimeout = setTimeout(function() {
self.updateData();
}, this.updateInterval);
get updateInterval() {
return this._updateInterval;
}
};
DaikinAC.prototype.clearUpdateTimeout = function clearUpdateTimeout() {
if (this.updateTimeout) {
clearTimeout(this.updateTimeout);
this.updateTimeout = null;
if (this.logger) this.logger('clear update timeout');
get currentCommonBasicInfo() {
return this._currentCommonBasicInfo;
}
};
DaikinAC.prototype.updateData = function updateData() {
this.clearUpdateTimeout();
var self = this;
this.getACControlInfo(function(err) {
if (err) {
self.initUpdateTimeout();
if (self.updateCallback) self.updateCallback(err);
return;
get updateTimeout() {
return this._updateTimeout;
}
setUpdate(updateInterval, callback) {
this._updateInterval = updateInterval;
if (typeof callback === 'function') {
this._updateCallback = callback;
}
self.getACSensorInfo(function (err) {
self.initUpdateTimeout();
if (self.updateCallback) self.updateCallback(err);
});
});
};
DaikinAC.prototype.stopUpdate = function stopUpdate() {
this.clearUpdateTimeout();
this.updateInterval = null;
this.updateCallback = null;
};
DaikinAC.prototype.getCommonBasicInfo = function getCommonBasicInfo(callback) {
var self = this;
this.daikinRequest.getCommonBasicInfo(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
self.currentCommonBasicInfo = daikinResponse;
if (self.currentCommonBasicInfo && self.currentCommonBasicInfo.lpwFlag === 1) {
self.daikinRequest && self.daikinRequest.addDefaultParameter('lpw', '');
this.updateData();
}
initUpdateTimeout() {
if (this._updateInterval && !this._updateTimeout) {
if (this._logger)
this._logger('start update timeout');
this._updateTimeout = setTimeout(() => {
this.updateData();
}, this._updateInterval);
}
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getCommonRemoteMethod = function getCommonRemoteMethod(callback) {
var self = this;
this.daikinRequest.getCommonRemoteMethod(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACControlInfo = function getACControlInfo(callback) {
var self = this;
this.daikinRequest.getACControlInfo(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (!err) self.currentACControlInfo = daikinResponse;
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.setACControlInfo = function setACControlInfo(values, callback) {
var self = this;
this.clearUpdateTimeout();
this.daikinRequest.getACControlInfo(function (err, ret, completeValues) {
if (err) {
self.initUpdateTimeout();
if (callback) callback(err, completeValues);
return;
}
clearUpdateTimeout() {
if (this._updateTimeout) {
clearTimeout(this._updateTimeout);
this._updateTimeout = null;
if (this._logger)
this._logger('clear update timeout');
}
// we read the current data and change that set in values
for (var key in values) {
completeValues[key] = values[key];
if (self.logger) self.logger('change ' + key + ' to ' + values[key]);
}
self.daikinRequest.setACControlInfo(completeValues, function(errSet, ret, daikinSetResponse) {
if (self.logger) self.logger(JSON.stringify(daikinSetResponse));
self.getACControlInfo(function(errGet, daikinGetResponse) {
self.initUpdateTimeout();
var errFinal = errSet ? errSet : errGet;
if (callback) callback(errFinal, daikinGetResponse);
}
updateData() {
this.clearUpdateTimeout();
this.getACControlInfo((err, _info) => {
if (err) {
this.initUpdateTimeout();
if (this._updateCallback)
this._updateCallback(err);
return;
}
this.getACSensorInfo((err, _info) => {
this.initUpdateTimeout();
if (this._updateCallback)
this._updateCallback(err);
});
});
});
};
DaikinAC.prototype.getACSensorInfo = function getACSensorInfo(callback) {
var self = this;
this.daikinRequest.getACSensorInfo(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
self.currentACSensorInfo = daikinResponse;
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACModelInfo = function getACModelInfo(callback) {
var self = this;
this.daikinRequest.getACModelInfo(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
self.currentACModelInfo = daikinResponse;
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACWeekPower = function getACWeekPower(callback) {
var self = this;
this.daikinRequest.getACWeekPower(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACYearPower = function getACYearPower(callback) {
var self = this;
this.daikinRequest.getACYearPower(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACWeekPowerExtended = function getACWeekPowerExtended(callback) {
var self = this;
this.daikinRequest.getACWeekPowerExtended(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.getACYearPowerExtended = function getACYearPowerExtended(callback) {
var self = this;
this.daikinRequest.getACYearPowerExtended(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (callback) callback(err, daikinResponse);
});
};
DaikinAC.prototype.enableAdapterLED = function enableAdapterLED(callback) {
this.clearUpdateTimeout();
var self = this;
this.daikinRequest.setCommonAdapterLED({'led': true}, function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (err) {
self.initUpdateTimeout();
if (callback) callback(err, daikinResponse);
return;
}
self.getCommonBasicInfo(function(errGet, daikinGetResponse) {
self.initUpdateTimeout();
var errFinal = err ? err : errGet;
if (callback) callback(errFinal, daikinResponse);
}
stopUpdate() {
this.clearUpdateTimeout();
this._updateInterval = null;
this._updateCallback = null;
}
getCommonBasicInfo(callback) {
this._daikinRequest.getCommonBasicInfo((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
this._currentCommonBasicInfo = daikinResponse;
if (this._currentCommonBasicInfo && this._currentCommonBasicInfo.lpwFlag === 1) {
this._daikinRequest && this._daikinRequest.addDefaultParameter('lpw', '');
}
if (callback)
callback(err, daikinResponse);
});
});
};
DaikinAC.prototype.disableAdapterLED = function disableAdapterLED(callback) {
this.clearUpdateTimeout();
var self = this;
this.daikinRequest.setCommonAdapterLED({'led': false}, function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (err) {
self.initUpdateTimeout();
if (callback) callback(err, daikinResponse);
return;
}
self.getCommonBasicInfo(function(errGet, daikinGetResponse) {
self.initUpdateTimeout();
var errFinal = err ? err : errGet;
if (callback) callback(errFinal, daikinResponse);
}
getCommonRemoteMethod(callback) {
this._daikinRequest.getCommonRemoteMethod((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (callback)
callback(err, daikinResponse);
});
});
};
DaikinAC.prototype.rebootAdapter = function rebootAdapter(callback) {
this.clearUpdateTimeout();
var self = this;
this.daikinRequest.commonRebootAdapter(function (err, ret, daikinResponse) {
if (self.logger) self.logger(JSON.stringify(daikinResponse));
if (err) {
self.initUpdateTimeout();
if (callback) callback(err, daikinResponse);
return;
}
setTimeout(function() {
self.getCommonBasicInfo(function(errGet, daikinGetResponse) {
self.initUpdateTimeout();
var errFinal = err ? err : errGet;
if (callback) callback(errFinal, daikinResponse);
}
getACControlInfo(callback) {
this._daikinRequest.getACControlInfo((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (!err)
this._currentACControlInfo = daikinResponse;
if (callback)
callback(err, daikinResponse);
});
}
/**
* Changes the passed options, the rest remains unchanged
*/
setACControlInfo(obj, callback) {
this.clearUpdateTimeout();
this._daikinRequest.getACControlInfo((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.setACControlInfo(completeValues, (errSet, _ret, daikinSetResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinSetResponse));
this.getACControlInfo((errGet, daikinGetResponse) => {
this.initUpdateTimeout();
const errFinal = errSet ? errSet : errGet;
if (callback)
callback(errFinal, daikinGetResponse);
});
});
}, 2000);
});
};
DaikinAC.prototype.setACSpecialMode = function setACSpecialMode(values, callback) {
this.clearUpdateTimeout();
var self = this;
self.daikinRequest.setACSpecialMode(values, function(errSet, ret, daikinSetResponse) {
if (self.logger) self.logger(JSON.stringify(daikinSetResponse));
if (callback) callback(errSet, daikinSetResponse);
});
};
module.exports = DaikinAC;
module.exports.Power = DaikinACTypes.Power;
module.exports.Mode = DaikinACTypes.Mode;
module.exports.FanRate = DaikinACTypes.FanRate;
module.exports.FanDirection = DaikinACTypes.FanDirection;
module.exports.SpecialModeState = DaikinACTypes.SpecialModeState;
module.exports.SpecialModeKind = DaikinACTypes.SpecialModeKind;
module.exports.SpecialModeResponse = DaikinACTypes.SpecialModeResponse;
});
}
getACSensorInfo(callback) {
this._daikinRequest.getACSensorInfo((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
this._currentACSensorInfo = daikinResponse;
if (callback)
callback(err, daikinResponse);
});
}
getACModelInfo(callback) {
this._daikinRequest.getACModelInfo((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
this._currentACModelInfo = daikinResponse;
if (callback)
callback(err, daikinResponse);
});
}
getACWeekPower(callback) {
this._daikinRequest.getACWeekPower((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (callback)
callback(err, daikinResponse);
});
}
getACYearPower(callback) {
this._daikinRequest.getACYearPower((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (callback)
callback(err, daikinResponse);
});
}
getACWeekPowerExtended(callback) {
this._daikinRequest.getACWeekPowerExtended((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (callback)
callback(err, daikinResponse);
});
}
getACYearPowerExtended(callback) {
this._daikinRequest.getACYearPowerExtended((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (callback)
callback(err, daikinResponse);
});
}
enableAdapterLED(callback) {
this.clearUpdateTimeout();
this._daikinRequest.setCommonLED(true, (err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (err) {
this.initUpdateTimeout();
if (callback)
callback(err, daikinResponse);
return;
}
this.getCommonBasicInfo((errGet, _daikinGetResponse) => {
this.initUpdateTimeout();
const errFinal = err ? err : errGet;
if (callback)
callback(errFinal, daikinResponse);
});
});
}
disableAdapterLED(callback) {
this.clearUpdateTimeout();
this._daikinRequest.setCommonLED(false, (err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (err) {
this.initUpdateTimeout();
if (callback)
callback(err, daikinResponse);
return;
}
this.getCommonBasicInfo((errGet, _daikinGetResponse) => {
this.initUpdateTimeout();
const errFinal = err ? err : errGet;
if (callback)
callback(errFinal, daikinResponse);
});
});
}
rebootAdapter(callback) {
this.clearUpdateTimeout();
this._daikinRequest.rebootAdapter((err, _ret, daikinResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinResponse));
if (err) {
this.initUpdateTimeout();
if (callback)
callback(err, daikinResponse);
return;
}
setTimeout(() => {
this.getCommonBasicInfo((errGet, _daikinGetResponse) => {
this.initUpdateTimeout();
const errFinal = err ? err : errGet;
if (callback)
callback(errFinal, daikinResponse);
});
}, 2000);
});
}
setACSpecialMode(obj, callback) {
this.clearUpdateTimeout();
this._daikinRequest.setACSpecialMode(obj, (errSet, _ret, daikinSetResponse) => {
if (this._logger)
this._logger(JSON.stringify(daikinSetResponse));
if (callback)
callback(errSet, daikinSetResponse);
});
}
}
exports.DaikinAC = DaikinAC;

@@ -1,431 +0,225 @@

/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
var RestClient = require('node-rest-client').Client;
var DaikinACTypes = require('./DaikinACTypes');
function DaikinACRequest(ip, options) {
this.ip = ip;
this.logger = null;
if (! options) {
options = {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DaikinACRequest = void 0;
const DaikinDataParser_1 = require("./DaikinDataParser");
const models_1 = require("./models");
const models_2 = require("./models");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const RestClient = require('node-rest-client').Client;
class DaikinACRequest {
constructor(ip, options) {
this.logger = null;
this.defaultParameters = {};
this.useGetToPost = false;
this.ip = ip;
if (options.logger !== undefined) {
this.logger = options.logger;
}
if (options.useGetToPost) {
this.useGetToPost = true;
}
this.restClient = new RestClient();
}
if (typeof options === 'function') {
this.logger = options;
options = {};
addDefaultParameter(key, value) {
this.defaultParameters[key] = value;
}
else if (options.logger) {
this.logger = options.logger;
doGet(url, parameters, callback) {
const reqParams = Object.assign({}, this.defaultParameters, parameters);
const data = {
parameters: reqParams,
headers: {
'Content-Type': 'text/plain',
'User-Agent': 'DaikinOnlineController/2.4.2 CFNetwork/978.0.7 Darwin/18.6.0',
Accept: '*/*',
'Accept-Language': 'de-de',
'Accept-Encoding': 'gzip, deflate',
},
requestConfig: {
timeout: 5000,
noDelay: true,
keepAlive: false, //Enable/disable keep-alive functionalityidle socket.
//keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
},
responseConfig: {
timeout: 5000, //response timeout
},
};
if (this.logger)
this.logger(`Call GET ${url} with ${JSON.stringify(reqParams)}`);
const req = this.restClient.get(url, data, callback);
req.on('requestTimeout', (req) => {
if (this.logger)
this.logger('request has expired');
req.abort();
callback(new Error(`Error while communicating with Daikin device: Timeout`));
});
req.on('responseTimeout', (_res) => {
if (this.logger)
this.logger('response has expired');
});
req.on('error', (err) => {
if (err.code) {
err = err.code;
}
else if (err.message) {
err = err.message;
}
else {
err = err.toString();
}
callback(new Error(`Error while communicating with Daikin device: ${err}`));
});
}
this.defaultParameters = {};
this.useGetToPost = false;
this.getRequest = this.doGet;
this.postRequest = this.doPost;
if (options.useGetToPost) {
this.postRequest = this.doGet;
doPost(url, parameters, callback) {
if (this.useGetToPost) {
this.doGet(url, parameters, callback);
return;
}
const reqParams = Object.assign({}, this.defaultParameters, parameters);
const data = {
data: reqParams,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'DaikinOnlineController/2.4.2 CFNetwork/978.0.7 Darwin/18.6.0',
Accept: '*/*',
'Accept-Language': 'de-de',
'Accept-Encoding': 'gzip, deflate',
},
requestConfig: {
timeout: 5000,
noDelay: true,
keepAlive: false, //Enable/disable keep-alive functionalityidle socket.
//keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
},
responseConfig: {
timeout: 5000, //response timeout
},
};
if (this.logger) {
this.logger(`Call POST ${url} with ${JSON.stringify(reqParams)}`);
}
const req = this.restClient.post(url, data, callback);
req.on('requestTimeout', (req) => {
if (this.logger)
this.logger('request has expired');
req.abort();
});
req.on('responseTimeout', (_res) => {
if (this.logger)
this.logger('response has expired');
});
req.on('error', (err) => {
if (err.code !== undefined) {
err = err.code;
}
else if (err.message) {
err = err.message;
}
else {
err = err.toString();
}
callback(new Error(`Error while communicating with Daikin device: ${err}`));
});
}
this.restClient = new RestClient();
}
DaikinACRequest.prototype.addDefaultParameter = function addDefaultParameter(key, value) {
this.defaultParameters[key] = value;
};
DaikinACRequest.prototype.getCommonBasicInfo = function getCommonBasicInfo(callback) {
this.getRequest('http://' + this.ip + '/common/basic_info', function (data, response) {
parseResponse(data, '/common/basic_info', callback);
});
};
DaikinACRequest.prototype.getCommonRemoteMethod = function getCommonRemoteMethod(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_remote_method', function (data, response) {
parseResponse(data, '/aircon/get_remote_method', callback);
});
};
DaikinACRequest.prototype.setCommonAdapterLED = function setCommonLED(values, callback) {
var normalizedVals;
try {
normalizedVals = this.normalizeValues(values,'/common/set_led');
setACSpecialMode(obj, callback) {
this.doPost(`http://${this.ip}/aircon/set_special_mode`, obj.getRequestDict(), (data, _res) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_2.SetCommandResponse.parseResponse(dict, callback);
});
}
catch (err) {
if (callback) callback(err.message);
return;
getACYearPowerExtended(callback) {
this.doGet(`http://${this.ip}/aircon/get_year_power_ex`, {}, (data, _res) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.YearPowerExtendedResponse.parseResponse(dict, callback);
});
}
this.postRequest('http://' + this.ip + '/common/set_led', normalizedVals, function (data, response) {
parseResponse(data, 'response', callback);
});
};
DaikinACRequest.prototype.commonRebootAdapter = function rebootAdapter(callback) {
this.postRequest('http://' + this.ip + '/common/reboot', function (data, response) {
parseResponse(data, 'response', callback);
});
};
DaikinACRequest.prototype.getACModelInfo = function getACModelInfo(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_model_info', function (data, response) {
parseResponse(data, '/aircon/get_model_info', callback);
});
};
DaikinACRequest.prototype.getACControlInfo = function getACControlInfo(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_control_info', function (data, response) {
parseResponse(data, '/aircon/get_control_info', callback);
});
};
DaikinACRequest.prototype.setACControlInfo = function setACControlInfo(values, callback) {
var normalizedVals;
try {
normalizedVals = this.normalizeValues(values,'/aircon/set_control_info');
getCommonBasicInfo(callback) {
this.doGet(`http://${this.ip}/common/basic_info`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.BasicInfoResponse.parseResponse(dict, callback);
});
}
catch (err) {
if (callback) callback(err.message);
return;
getCommonRemoteMethod(callback) {
this.doGet(`http://${this.ip}/aircon/get_remote_method`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.RemoteMethodResponse.parseResponse(dict, callback);
});
}
this.postRequest('http://' + this.ip + '/aircon/set_control_info', normalizedVals, function (data, response) {
parseResponse(data, 'response', callback);
});
};
DaikinACRequest.prototype.getACSensorInfo = function getACSensorInfo(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_sensor_info', function (data, response) {
parseResponse(data, '/aircon/get_sensor_info', callback);
});
};
DaikinACRequest.prototype.getACWeekPower = function getACWeekPower(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_week_power', function (data, response) {
parseResponse(data, '/aircon/get_week_power', callback);
});
};
DaikinACRequest.prototype.getACYearPower = function getACYearPower(callback) {
if (this.logger) this.logger('Call GET http://' + this.ip + '/aircon/get_year_power');
this.getRequest('http://' + this.ip + '/aircon/get_year_power', function (data, response) {
parseResponse(data, '/aircon/get_year_power', callback);
});
};
DaikinACRequest.prototype.getACWeekPowerExtended = function getACWeekPowerExtended(callback) {
if (this.logger) this.logger('Call GET http://' + this.ip + '/aircon/get_week_power_ex');
this.getRequest('http://' + this.ip + '/aircon/get_week_power_ex', function (data, response) {
parseResponse(data, '/aircon/get_week_power_ex', callback);
});
};
DaikinACRequest.prototype.getACYearPowerExtended = function getACYearPowerExtended(callback) {
this.getRequest('http://' + this.ip + '/aircon/get_year_power_ex', function (data, response) {
parseResponse(data, '/aircon/get_year_power_ex', callback);
});
};
DaikinACRequest.prototype.setACSpecialMode = function setACSpecialMode(values, callback) {
var normalizedVals;
try {
normalizedVals = this.normalizeValues(values,'/aircon/set_special_mode');
setCommonLED(ledOn, callback) {
this.doPost(`http://${this.ip}/common/set_led`, { led: ledOn ? 1 : 0 }, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_2.SetCommandResponse.parseResponse(dict, callback);
});
}
catch (err) {
if (callback) callback(err.message);
return;
rebootAdapter(callback) {
this.doPost(`http://${this.ip}/common/reboot`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_2.SetCommandResponse.parseResponse(dict, callback);
});
}
if (normalizedVals.spmode_kind === '0') {
var vals = {
'en_streamer': normalizedVals.set_spmode
};
this.postRequest('http://' + this.ip + '/aircon/set_special_mode', vals, function (data, response) {
parseResponse(data, 'response', callback);
getACModelInfo(callback) {
this.doGet(`http://${this.ip}/aircon/get_model_info`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.ModelInfoResponse.parseResponse(dict, callback);
});
}
else {
this.postRequest('http://' + this.ip + '/aircon/set_special_mode', normalizedVals, function (data, response) {
parseResponse(data, 'response', callback);
getACControlInfo(callback) {
this.doGet(`http://${this.ip}/aircon/get_control_info`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.ControlInfo.parseResponse(dict, callback);
});
}
};
DaikinACRequest.prototype.normalizeValues = function normalizeValues(values, endpoint) {
if (!DaikinACTypes.fieldDef[endpoint]) {
throw Error('Unknown endpoint ' + endpoint);
}
var requestValues = {};
for (var param in DaikinACTypes.fieldDef[endpoint]) {
//console.log('check ' + param + '/' + DaikinACTypes.fieldDef[endpoint][param].name);
if (values[DaikinACTypes.fieldDef[endpoint][param].name] !== undefined) {
requestValues[param] = values[DaikinACTypes.fieldDef[endpoint][param].name];
setACControlInfo(obj, callback) {
try {
this.doPost(`http://${this.ip}/aircon/set_control_info`, obj.getRequestDict(), (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_2.SetCommandResponse.parseResponse(dict, callback);
});
}
else if (values[param] !== undefined) {
requestValues[param] = values[param];
catch (e) {
callback(e instanceof Error ? e : new Error(e), null, null);
}
else if (DaikinACTypes.fieldDef[endpoint][param].required) {
throw Error('Required Field ' + param + '/' + DaikinACTypes.fieldDef[endpoint][param].name + ' do not exists');
}
//console.log(JSON.stringify(requestValues[param]));
switch (DaikinACTypes.fieldDef[endpoint][param].type) {
case 'Boolean':
requestValues[param] = requestValues[param]?1:0;
break;
case 'Integer':
case 'Float':
if (typeof requestValues[param] === 'number' && DaikinACTypes.fieldDef[endpoint][param].min && requestValues[param] < DaikinACTypes.fieldDef[endpoint][param].min) {
requestValues[param] = DaikinACTypes.fieldDef[endpoint][param].min;
}
if (typeof requestValues[param] === 'number' && DaikinACTypes.fieldDef[endpoint][param].max && requestValues[param] > DaikinACTypes.fieldDef[endpoint][param].max) {
requestValues[param] = DaikinACTypes.fieldDef[endpoint][param].max;
}
break;
case 'Array':
if (Array.isArray(requestValues[param])) {
requestValues[param] = requestValues[param].join('/');
}
}
}
if (requestValues.stemp) {
if (typeof requestValues.stemp === 'number') {
requestValues.stemp = (Math.round(requestValues.stemp * 2) / 2).toFixed(1);
}
getACSensorInfo(callback) {
this.doGet(`http://${this.ip}/aircon/get_sensor_info`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.SensorInfoResponse.parseResponse(dict, callback);
});
}
if (requestValues.shum) {
if (typeof requestValues.stemp === 'number') {
requestValues.shum = Math.round(requestValues.shum);
}
getACWeekPower(callback) {
this.doGet(`http://${this.ip}/aircon/get_week_power`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.WeekPowerResponse.parseResponse(dict, callback);
});
}
return requestValues;
};
DaikinACRequest.prototype.doGet = function doGet(url, parameters, callback) {
if (typeof parameters === 'function') {
callback = parameters;
parameters = undefined;
getACYearPower(callback) {
if (this.logger)
this.logger(`Call GET http://${this.ip}/aircon/get_year_power`);
this.doGet(`http://${this.ip}/aircon/get_year_power`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.YearPowerResponse.parseResponse(dict, callback);
});
}
var reqParams = Object.assign({}, this.defaultParameters, parameters);
var data = {
'parameters': reqParams,
'headers': {
'Content-Type': 'text/plain',
'User-Agent': 'DaikinOnlineController/2.4.2 CFNetwork/978.0.7 Darwin/18.6.0',
'Accept': '*/*',
'Accept-Language': 'de-de',
'Accept-Encoding': 'gzip, deflate'
},
'requestConfig': {
'timeout': 5000, //request timeout in milliseconds
'noDelay': true, //Enable/disable the Nagle algorithm
'keepAlive': false //Enable/disable keep-alive functionalityidle socket.
//keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
},
'responseConfig': {
'timeout': 5000 //response timeout
}
};
if (this.logger) this.logger('Call GET ' + url + ' with ' + JSON.stringify(reqParams));
var req = this.restClient.get(url, data, callback);
var self = this;
req.on('requestTimeout', function (req) {
if (self.logger) self.logger('request has expired');
req.abort();
});
req.on('responseTimeout', function (res) {
if (self.logger) self.logger('response has expired');
});
req.on('error', function (err) {
if (err.code) {
err = err.code;
}
else if (err.message) {
err = err.message;
}
else {
err = err.toString();
}
callback(new Error('Error while communicating with Daikin device: ' + err));
});
};
DaikinACRequest.prototype.doPost = function doPost(url, parameters, callback) {
if (typeof parameters === 'function') {
callback = parameters;
parameters = undefined;
getACWeekPowerExtended(callback) {
if (this.logger)
this.logger(`Call GET http://${this.ip}/aircon/get_week_power_ex`);
this.doGet(`http://${this.ip}/aircon/get_week_power_ex`, {}, (data, _response) => {
const dict = DaikinDataParser_1.DaikinDataParser.processResponse(data, callback);
if (dict !== null)
models_1.WeekPowerExtendedResponse.parseResponse(dict, callback);
});
}
var reqParams = Object.assign({}, this.defaultParameters, parameters);
var data = {
'data': reqParams,
'headers': {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'DaikinOnlineController/2.4.2 CFNetwork/978.0.7 Darwin/18.6.0',
'Accept': '*/*',
'Accept-Language': 'de-de',
'Accept-Encoding': 'gzip, deflate'
},
'requestConfig': {
'timeout': 5000, //request timeout in milliseconds
'noDelay': true, //Enable/disable the Nagle algorithm
'keepAlive': false //Enable/disable keep-alive functionalityidle socket.
//keepAliveDelay: 1000 //and optionally set the initial delay before the first keepalive probe is sent
},
'responseConfig': {
'timeout': 5000 //response timeout
}
};
if (this.logger) this.logger('Call POST ' + url + ' with ' + JSON.stringify(reqParams));
var req = this.restClient.post(url, data, callback);
var self = this;
req.on('requestTimeout', function (req) {
if (self.logger) self.logger('request has expired');
req.abort();
});
req.on('responseTimeout', function (res) {
if (self.logger) self.logger('response has expired');
});
req.on('error', function (err) {
if (err.code) {
err = err.code;
}
else if (err.message) {
err = err.message;
}
else {
err = err.toString();
}
callback(new Error('Error while communicating with Daikin device: ' + err));
});
};
function parseResponse(input, endpoint, callback) {
function parseDaikinResponse(s) {
const regex = /(?:^|,)([a-zA-Z0-9_]+)=(.*?)(?=$|,([a-zA-Z0-9_]+)=)/g;
let match;
let result = {};
while(match = regex.exec(s)) {
result[match[1]] = match[2];
}
return result;
}
var ret = null;
var responseData = null;
if (input instanceof Error) {
callback(input, null, null);
return;
}
if (Buffer.isBuffer(input)) {
input = input.toString();
}
if (input.includes('=')) {
responseData = parseDaikinResponse(input);
} else {
callback('Cannot parse response: ' + input, null, null);
return;
}
if (responseData.ret) {
ret = responseData.ret;
switch (responseData.ret) {
case 'OK': delete responseData.ret;
break;
case 'PARAM NG': delete responseData.ret;
callback('Wrong Parameters in request: ' + input, ret, responseData);
return;
case 'ADV NG': delete responseData.ret;
callback('Wrong ADV: ' + input, ret, responseData);
return;
default: callback('Unknown response: ' + input, ret, responseData);
return;
}
}
else {
callback('Unknown response: ' + input, ret, responseData);
return;
}
if (DaikinACTypes.fieldDef[endpoint]) {
var mappedResponse = {};
for (var field in responseData) {
//console.log('handle field ' + field);
if (DaikinACTypes.fieldDef[endpoint][field]) {
//console.log('fielddef for field ' + field + ' exists');
var fieldHandled = false;
if (DaikinACTypes.fieldDef[endpoint][field].type !== 'Array' && DaikinACTypes.fieldDef[endpoint][field].altValues) {
//console.log('check altVals for field ' + field);
for (var altValue in DaikinACTypes.fieldDef[endpoint][field].altValues) {
//console.log('check altVals for field ' + field + ' - ' + altValue);
if (responseData[field] === DaikinACTypes.fieldDef[endpoint][field].altValues[altValue]) {
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = DaikinACTypes.fieldDef[endpoint][field].altValues[altValue];
fieldHandled = true;
break;
}
}
}
//console.log('altVals for field ' + field + ' done: ' + fieldHandled);
if (!fieldHandled) {
//console.log('check/convert type for field ' + field + ': ' + DaikinACTypes.fieldDef[endpoint][field].type);
switch (DaikinACTypes.fieldDef[endpoint][field].type) {
case 'Boolean':
if (typeof responseData[field] !== 'number') {
responseData[field] = parseInt(responseData[field], 10);
}
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = !!responseData[field];
break;
case 'Integer':
if (typeof responseData[field] !== 'number') {
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = parseInt(responseData[field], 10);
//console.log('check/convert type for field ' + field + ' TO ' + DaikinACTypes.fieldDef[endpoint][field].type);
}
else {
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = responseData[field];
}
break;
case 'Float':
if (typeof responseData[field] !== 'number') {
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = parseFloat(responseData[field]);
//console.log('check/convert type for field ' + field + ' TO ' + DaikinACTypes.fieldDef[endpoint][field].type);
}
else {
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = responseData[field];
}
break;
case 'Array':
var arr = responseData[field].split('/');
for (var i = 0; i < arr.length; i++) {
arr[i] = parseInt(arr[i], 10);
}
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = arr;
break;
default:
mappedResponse[DaikinACTypes.fieldDef[endpoint][field].name] = decodeURIComponent(responseData[field]);
}
}
}
else {
//if (this.logger) this.logger('undefined field ' + field + ' for endpoint ' + endpoint);
}
}
callback(null, ret, mappedResponse);
return;
}
callback(null, ret, responseData);
}
module.exports = DaikinACRequest;
exports.DaikinACRequest = DaikinACRequest;

@@ -1,229 +0,21 @@

/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
var Power = {
'OFF': false,
'ON': true
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FanDirection = exports.SpecialModeResponse = exports.Power = void 0;
exports.Power = {
OFF: false,
ON: true,
};
var Mode = {
'AUTO': 0,
'AUTO1': 1,
'AUTO2': 7,
'DEHUMDID': 2,
'COLD': 3,
'HOT': 4,
'FAN': 6
exports.SpecialModeResponse = {
'N/A': '',
POWERFUL: '2',
ECONO: '12',
STREAMER: '13',
'POWERFUL/STREAMER': '2/13',
'ECONO/STREAMER': '12/13',
};
var SpecialModeState = {
'OFF': '0',
'ON': '1'
exports.FanDirection = {
STOP: 0,
VERTICAL: 1,
HORIZONTAL: 2,
VERTICAL_AND_HORIZONTAL: 3,
};
var SpecialModeKind = {
'STREAMER': '0', // Flash STREAMER Air-Purifier
'POWERFUL': '1', // POWERFUL Operation
'ECONO': '2' // ECONO Operation
};
var SpecialModeResponse = {
'N/A': '',
'POWERFUL': '2',
'ECONO': '12',
'STREAMER': '13',
'POWERFUL/STREAMER': '2/13',
'ECONO/STREAMER': '12/13'
};
var FanRate = {
'AUTO': 'A',
'SILENCE': 'B',
'LEVEL_1': 3,
'LEVEL_2': 4,
'LEVEL_3': 5,
'LEVEL_4': 6,
'LEVEL_5': 7
};
var FanDirection = {
'STOP': 0,
'VERTICAL': 1,
'HORIZONTAL': 2,
'VERTICAL_AND_HORIZONTAL': 3
};
var ErrorCode = {
OK: 0
};
var Type = {
'AC': "aircon"
// ...
};
var Method = {
'POLLING': "polling"
};
var AdpMode = {
'RUN': "run"
};
var fieldDef = {
'/common/basic_info': {
'type': {'name': 'type', 'type': 'String', 'altValues': Type},
'reg': {'name': 'region', 'type': 'String'},
'dst': {'name': 'dst', 'type': 'Boolean'},
'ver': {'name': 'adapterVersion', 'type': 'String'},
'pow': {'name': 'power', 'type': 'Boolean', 'altValues': Power},
'location': {'name': 'location', 'type': 'Integer'},
'name': {'name': 'name', 'type': 'String'},
'icon': {'name': 'icon', 'type': 'Integer'},
'method': {'name': 'method', 'type': 'String', 'altValues': Method},
'port': {'name': 'port', 'type': 'Integer'},
'id': {'name': 'id', 'type': 'String'}, // unit identifier
'pw': {'name': 'password', 'type': 'String'}, // password
'lpw_flag': {'name': 'lpwFlag', 'type': 'Integer'},
'pv': {'name': 'pv', 'type': 'Integer'},
'cpv': {'name': 'cpv', 'type': 'Integer'},
'cpv_minor': {'name': 'cpvMinor', 'type': 'Integer'},
'led': {'name': 'led', 'type': 'Boolean'}, // status LED on or off
'en_setzone': {'name': 'enSetzone', 'type': 'Integer'},
'mac': {'name': 'macAddress', 'type': 'String'},
'adp_mode': {'name': 'adapterMode', 'type': 'String', 'altValues': AdpMode},
'err': {'name': 'error', 'type': 'Integer'}, // 255
'en_hol': {'name': 'enHol', 'type': 'Integer'},
'en_grp': {'name': 'enGroup', 'type': 'Integer'},
'grp_name': {'name': 'groupName', 'type': 'String'},
'adp_kind': {'name': 'adapterKind', 'type': 'Integer'}
},
'/common/get_remote_method': {
'method': {'name': 'method', 'type': 'String'},
'notice_ip_int': {'name': 'noticeIpInt', 'type': 'Integer'},
'notice_sync_int': {'name': 'noticeSyncInt', 'type': 'Integer'}
},
'/aircon/get_control_info': {
'pow': {'name': 'power', 'type': 'Boolean', 'altValues': Power},
'mode': {'name': 'mode', 'type': 'Integer', 'altValues': Mode},
'stemp': {'name': 'targetTemperature', 'type': 'Float', 'altValues': {'M': 'M'}},
'shum': {'name': 'targetHumidity', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // "AUTO" or Number from 0..50
'f_rate': {'name': 'fanRate', 'type': 'Integer', 'altValues': FanRate},
'f_dir': {'name': 'fanDirection', 'type': 'Integer', 'altValues': FanDirection},
// the following are returned, but not set-able
'adv': {'name': 'specialMode', 'type': 'String', 'altValues': SpecialModeResponse},
'dt1': {'name': 'targetTemperatureMode1', 'type': 'Float', 'altValues': {'M': 'M'}}, // "M" or Number 10..41
'dt2': {'name': 'targetTemperatureMode2', 'type': 'Float', 'altValues': {'M': 'M'}},
'dt3': {'name': 'targetTemperatureMode3', 'type': 'Float', 'altValues': {'M': 'M'}},
'dt4': {'name': 'targetTemperatureMode4', 'type': 'Float', 'altValues': {'M': 'M'}},
'dt5': {'name': 'targetTemperatureMode5', 'type': 'Float', 'altValues': {'M': 'M'}},
'dt7': {'name': 'targetTemperatureMode7', 'type': 'Float', 'altValues': {'M': 'M'}},
'dh1': {'name': 'targetHumidityMode1', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dh2': {'name': 'targetHumidityMode2', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dh3': {'name': 'targetHumidityMode3', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dh4': {'name': 'targetHumidityMode4', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dh5': {'name': 'targetHumidityMode5', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dh7': {'name': 'targetHumidityMode7', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dhh': {'name': 'targetHumidityModeH', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}}, // AUTO or Number
'dfr1': {'name': 'fanRateMode1', 'type': 'Integer', 'altValues': FanRate},
'dfr2': {'name': 'fanRateMode2', 'type': 'Integer', 'altValues': FanRate},
'dfr3': {'name': 'fanRateMode3', 'type': 'Integer', 'altValues': FanRate},
'dfr4': {'name': 'fanRateMode4', 'type': 'Integer', 'altValues': FanRate},
'dfr5': {'name': 'fanRateMode5', 'type': 'Integer', 'altValues': FanRate},
'dfr6': {'name': 'fanRateMode6', 'type': 'Integer', 'altValues': FanRate},
'dfr7': {'name': 'fanRateMode7', 'type': 'Integer', 'altValues': FanRate},
'dfrh': {'name': 'fanRateModeH', 'type': 'Integer', 'altValues': FanRate},
'dfd1': {'name': 'fanDirectionMode1', 'type': 'Integer', 'altValues': FanDirection},
'dfd2': {'name': 'fanDirectionMode2', 'type': 'Integer', 'altValues': FanDirection},
'dfd3': {'name': 'fanDirectionMode3', 'type': 'Integer', 'altValues': FanDirection},
'dfd4': {'name': 'fanDirectionMode4', 'type': 'Integer', 'altValues': FanDirection},
'dfd5': {'name': 'fanDirectionMode5', 'type': 'Integer', 'altValues': FanDirection},
'dfd6': {'name': 'fanDirectionMode6', 'type': 'Integer', 'altValues': FanDirection},
'dfd7': {'name': 'fanDirectionMode7', 'type': 'Integer', 'altValues': FanDirection},
'dfdh': {'name': 'fanDirectionModeH', 'type': 'Integer', 'altValues': FanDirection},
'b_mode': {'name': 'modeB', 'type': 'Integer', 'altValues': Mode},
'b_stemp': {'name': 'targetTemperatureB', 'type': 'Float', 'altValues': {'M': 'M'}},
'b_shum': {'name': 'targetHumidityB', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}},
'b_f_rate': {'name': 'fanRateB', 'type': 'Integer', 'altValues': FanRate},
'b_f_dir': {'name': 'fanDirectionB', 'type': 'Integer', 'altValues': FanDirection},
'alert': {'name': 'error', 'type': 'Integer'} // 255
},
'/aircon/set_control_info': {
'pow': {'name': 'power', 'type': 'Boolean', 'altValues': Power, 'required': true},
'mode': {'name': 'mode', 'type': 'Integer', 'altValues': Mode, 'min': 0, 'max': 7, 'required': true},
'stemp': {'name': 'targetTemperature', 'type': 'Float', 'altValues': {'M': 'M'}, 'min': 10, 'max': 41, 'required': true},
'shum': {'name': 'targetHumidity', 'type': 'Float', 'altValues': {'AUTO': 'AUTO'}, 'min': 0, 'max': 50, 'required': true}, // "AUTO" or Number from 0..50
'f_rate': {'name': 'fanRate', 'type': 'Integer', 'altValues': FanRate, 'min': 3, 'max': 7, 'required': false},
'f_dir': {'name': 'fanDirection', 'type': 'Integer', 'altValues': FanDirection, 'min': 0, 'max': 3, 'required': false}
},
'/aircon/get_model_info': { //ret=OK,model=NOTSUPPORT,type=N,pv=0,cpv=0,mid=NA,s_fdir=1,en_scdltmr=1
'model': {'name': 'model', 'type': 'String'},
'type': {'name': 'type', 'type': 'String'},
'pv': {'name': 'pv', 'type': 'Integer'},
'cpv': {'name': 'cpv', 'type': 'Integer'},
'mid': {'name': 'mid', 'type': 'String'},
's_fdir': {'name': 'sFanDirection', 'type': 'Integer', 'altValues': FanDirection},
'en_scdltmr': {'name': 'enScdltmr', 'type': 'Integer'}
},
'/aircon/get_sensor_info': { // ret=OK,htemp=21.5,hhum=-,otemp=-,err=0,cmpfreq=0
'htemp': {'name': 'indoorTemperature', 'type': 'Float'},
'hhum': {'name': 'indoorHumidity', 'type': 'Float'},
'otemp': {'name': 'outdoorTemperature', 'type': 'Float'},
'err': {'name': 'error', 'type': 'Integer'},
'cmpfreq': {'name': 'cmpfreq', 'type': 'Integer'}
},
'/aircon/get_week_power': { // ret=OK,today_runtime=24,datas=0/0/0/0/0/0/0
'today_runtime': {'name': 'todayRuntime', 'type': 'Integer'},
'datas': {'name': 'data', 'type': 'Array'}
},
'/aircon/get_year_power': { // ret=OK,previous_year=0/0/0/0/0/0/0/0/0/0/0/0,this_year=0/0/0
'previous_year': {'name': 'previousYear', 'type': 'Array'},
'this_year': {'name': 'currentYear', 'type': 'Array'}
},
'/aircon/get_week_power_ex': { // ret=OK,s_dayw=6,week_heat=0/0/0/0/0/0/0/0/0/0/0/0/0/0,week_cool=0/0/0/0/0/0/0/0/0/0/0/0/0/0
's_dayw': {'name': 'sDayw', 'type': 'Integer'},
'week_heat': {'name': 'heatWeek', 'type': 'Array'},
'week_cool': {'name': 'coolWeek', 'type': 'Array'}
},
'/aircon/get_year_power_ex': { // ret=OK,curr_year_heat=0/0/0/0/0/0/0/0/0/0/0/0,prev_year_heat=0/0/0/0/0/0/0/0/0/0/0/0,curr_year_cool=0/0/0/0/0/0/0/0/0/0/0/0,prev_year_cool=0/0/0/0/0/0/0/0/0/0/0/0
'curr_year_heat': {'name': 'heatCurrentYear', 'type': 'Array'},
'prev_year_heat': {'name': 'heatPreviousYear', 'type': 'Array'},
'curr_year_cool': {'name': 'coolCurrentYear', 'type': 'Array'},
'prev_year_cool': {'name': 'coolPreviousYear', 'type': 'Array'}
},
'/aircon/set_special_mode': {
'set_spmode': {'name': 'state', 'type': 'Integer', 'altValues': SpecialModeState, 'min': 0, 'max': 1,'required': true},
'spmode_kind': {'name': 'kind', 'type': 'Integer', 'altValues': SpecialModeKind, 'min': 0, 'max': 2, 'required': true}
},
'/common/set_led': {
'led': {'name': 'led', 'type': 'Boolean', 'altValues': Power, 'required': true}
},
'/common/reboot': {
},
'response': {
'adv': {'name': 'specialMode', 'type': 'String', 'altValues': SpecialModeResponse}
}
};
module.exports.Power = Power;
module.exports.Mode = Mode;
module.exports.FanRate = FanRate;
module.exports.FanDirection = FanDirection;
module.exports.SpecialModeState = SpecialModeState;
module.exports.SpecialModeKind = SpecialModeKind;
module.exports.SpecialModeResponse = SpecialModeResponse;
module.exports.fieldDef = fieldDef;

@@ -1,73 +0,65 @@

/* jshint -W097 */
// jshint strict:true
/*jslint node: true */
/*jslint esversion: 6 */
'use strict';
var udp = require("dgram");
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DaikinDiscovery = void 0;
const dgram_1 = require("dgram");
// Change this to true to output debugging logs to the console
var debug = false;
// TODO: Which parameterrs are really needed
// TODO: Also initialize DaicinAC instances?
function discover(waitForCount, callback) {
var listenAddress='0.0.0.0';
var listenPort=30000;
var probePort=30050;
var probeAddress='255.255.255.255';
var probeAttempts=10;
var probeInterval=500;
var probeData = new Buffer.from('DAIKIN_UDP/common/basic_info');
var probeTimeout;
var discoveredDevices = {};
var udpSocket = udp.createSocket({type:"udp4", reuseAddr:true});
udpSocket.on('error', function (err) {
if (debug) console.log('ERROR udpSocket: ' + err);
});
udpSocket.bind(listenPort, listenAddress, function() {
udpSocket.addMembership('224.0.0.1');
udpSocket.setBroadcast(true);
});
udpSocket.on("message", function (message, remote) {
if (debug) console.log(remote.address + ':' + remote.port +' - ' + message);
discoveredDevices[remote.address] = message.toString();
if (Object.keys(discoveredDevices).length >= waitForCount) {
finalizeDiscovery();
const debug = false;
class DaikinDiscovery {
constructor(waitForCount, callback) {
this.listenAddress = '0.0.0.0';
this.listenPort = 30000;
this.probePort = 30050;
this.probeAddress = '255.255.255.255';
this.probeAttempts = 10;
this.probeInterval = 500;
this.probeData = Buffer.from('DAIKIN_UDP/common/basic_info');
this.probeTimeout = null;
this.discoveredDevices = {};
this.callback = callback;
// TODO: Which parameterrs are really needed
// TODO: Also initialize DaicinAC instances?
this.udpSocket = (0, dgram_1.createSocket)({ type: 'udp4', reuseAddr: true });
this.udpSocket.on('error', (err) => {
this.log(`ERROR udpSocket: ${err}`);
});
this.udpSocket.bind(this.listenPort, this.listenAddress, () => {
this.udpSocket.addMembership('224.0.0.1');
this.udpSocket.setBroadcast(true);
});
this.udpSocket.on('message', (message, remote) => {
this.log(`${remote.address}:${remote.port} - ${message}`);
// this.discoveredDevices[remote.address] = message.toString();
this.discoveredDevices[remote.address] = remote.address;
if (Object.keys(this.discoveredDevices).length >= waitForCount) {
this.finalizeDiscovery();
}
});
this.udpSocket.on('listening', () => {
this.sendProbes(this.probeAttempts);
});
}
sendProbes(attemptsLeft) {
this.probeTimeout = null;
if (attemptsLeft <= 0) {
this.finalizeDiscovery();
return;
}
});
udpSocket.on('listening', function() {
sendProbes(probeAttempts);
});
function sendProbes(attemptsLeft) {
probeTimeout = null;
if (attemptsLeft > 0) {
if (debug) console.log('Send UDP discovery package ' + attemptsLeft);
udpSocket.send(probeData, 0, probeData.length, probePort, probeAddress);
probeTimeout = setTimeout(sendProbes, probeInterval, --attemptsLeft);
}
else {
finalizeDiscovery();
}
this.log(`Send UDP discovery package ${attemptsLeft}`);
this.udpSocket.send(this.probeData, 0, this.probeData.length, this.probePort, this.probeAddress);
this.probeTimeout = setTimeout(this.sendProbes.bind(this), this.probeInterval, --attemptsLeft);
}
function finalizeDiscovery() {
if (probeTimeout) {
clearTimeout(probeTimeout);
probeTimeout = null;
finalizeDiscovery() {
if (this.probeTimeout !== null) {
clearTimeout(this.probeTimeout);
this.probeTimeout = null;
}
udpSocket.close();
if (debug) console.log('Discovery finished with ' + Object.keys(discoveredDevices).length + ' devices found');
callback(discoveredDevices);
this.udpSocket.close();
this.log(`Discovery finished with ${Object.keys(this.discoveredDevices).length} devices found`);
this.callback(this.discoveredDevices);
}
log(message) {
if (debug)
console.log(message);
}
}
module.exports = discover;
exports.DaikinDiscovery = DaikinDiscovery;
{
"name": "daikin-controller",
"version": "1.2.2",
"version": "2.0.0",
"description": "Control Daikin Air Conditioner devices using nodejs",

@@ -18,12 +18,24 @@ "author": "Ingo Fischer <ingo@fischer-ka.de>",

"dependencies": {
"node-rest-client": "^3.1.0",
"node-rest-client": "^3.1.1",
"xmlbuilder": "^15.1.1"
},
"devDependencies": {
"@alcalzone/release-script": "^1.10.0",
"mocha": "^8.4.0",
"chai": "^4.3.4",
"@alcalzone/release-script": "^3.5.9",
"@types/jest": "^27.4.1",
"@types/node": "^17.0.23",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"chai": "^4.3.6",
"eslint": "^8.12.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "4.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"istanbul": "^0.4.5",
"sinon": "^11.1.1",
"nock": "^13.1.0"
"jest": "^27.5.1",
"nock": "^13.2.4",
"prettier": "^2.6.1",
"sinon": "^12.0.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.3",
"ts-node": "^10.7.0"
},

@@ -33,7 +45,13 @@ "bugs": {

},
"main": "index.js",
"main": "lib/index.js",
"scripts": {
"test": "node node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec",
"release": "release-script"
"lint-fix-all": "eslint ./src/{*.ts,*.js} --fix --no-error-on-unmatched-pattern",
"jest-coverage": "jest --coverage",
"test": "npm run jest-coverage",
"quickTestLocalNetwork": "ts-node QuickLocalTest/QuickTestLocalNetwork.ts",
"build": "tsc",
"release": "release-script",
"prettier": "prettier -u -w src QuickLocalTest",
"prepare": "npm run build"
}
}

@@ -59,5 +59,13 @@ # daikin-controller

The library is based on the great work of the unofficial Daikin API documentation project (https://github.com/ael-code/daikin-control). Additional informations on parameters and values can be found there.
Note: For devices with newer WLAN-Adapters like **BRP069C4x** which can only be used by the Daikin Onecta App please use the [Daikin-Controller-Cloud](https://github.com/Apollon77/daikin-controller-cloud) lib instead.
## Projects using this library
* https://flows.nodered.org/node/node-red-contrib-daikin-ac
## Note about v2.0 of this library
The 2.x of the library is a port to Typescript. We tried to not break anything, but reality will proof how good we were on that :-) Some small changes are in that "might" be breaking depending on the usage:
* Error parameter in callbacks is now an Error object and no string anymore
* ...
## Usage example

@@ -82,8 +90,8 @@

```
## Usage informations
The library tries to make it easy to interact with a Daikin device, especially by caching the last read values as seen in the example above. These values can also be queried manually, but the library makes sure that the cached data are always current - this means that after changing some of the settings the relevant data are updated too.
## Usage information
The library tries to make it easy to interact with a Daikin device, especially by caching the last read values as seen in the example above. These values can also be queried manually, but the library makes sure that the cached data are always current - this means that after changing some settings the relevant data are updated too.
On each call the result will be provided to a callback method together with an error flag containing an error message.
The library do not return the same field names as the Device (as listed on the unofficial documentation), but tries to make the fields more human readable in camel case notation together with type conversion where possible. The corresponding mapping can be found in lib/DaikinACTypes.js .
The library do not return the same field names as the Device (as listed on the unofficial documentation), but tries to make the fields more human-readable in camel case notation together with type conversion where possible. The corresponding mapping can be found in lib/DaikinACTypes.ts .

@@ -95,5 +103,5 @@ The callback method should have aa signature like

```
* **err**: null on success or a string value when an error has occured
* **err**: null on success or an Error object when an error has occured
* **ret**: The return value from the device. Can currently be "OK", "PARAM NG" (Wrong Parameters) or "ADV NG" (Wrong ADV)
* **response**: Object that contains the returned fields as keys. Mapping from device fieldnames to library field names see lib/DaikinACTypes.js
* **response**: Object that contains the returned fields as keys. Mapping from device fieldnames to library field names see lib/DaikinACTypes.ts

@@ -108,3 +116,3 @@ ## Manuals

Constructor to initialize the Daikin instance to interact with the device.
Usage see example above, the "options" paraeter is optional. Using "options" you can set a **logger** function (see example). Additionally you can set the special flag **useGetToPost** for older Firmwares of the Daikin-WLAN-Interfaces (<1.4) that only supported HTTP GET also to set data. So if you get errors using it then you try if it works better with this flag.
Usage see example above, the "options" parameter is optional. Using "options" you can set a **logger** function (see example). Additionally you can set the special flag **useGetToPost** for older Firmwares of the Daikin-WLAN-Interfaces (<1.4) that only supported HTTP GET also to set data. So if you get errors using it then you try if it works better with this flag.
The callback function is called after initializing the device and requesting currentCommonBasicInfo and currentACModelInfo.

@@ -134,10 +142,10 @@

Send an update for the "Control-Info" data to the device. values is an object with the following possible keys:
* power: Boolean, enable or disable the device, you can also use DaikinAC-Power for allowed values in human readable format
* mode: Integer, set operation Mode of the device, you can also use DaikinAC-Mode for allowed values in human readable format
* power: Boolean, enable or disable the device, you can also use DaikinAC-Power for allowed values in human-readable format
* mode: Integer, set operation Mode of the device, you can also use DaikinAC-Mode for allowed values in human-readable format
* targetTemperature: Float or "M" for mode 2 (DEHUMDIFICATOR)
* targetHumidity: Float or "AUTO"/"--" for mode 6 (FAN)
* fanRate: Integer or "A"/"B", you can also use DaikinAC-FanRate for allowed values in human readable format
* fanDirection: Integer, you can also use DaikinAC-FanDirection for allowed values in human readable format
* fanRate: Integer or "A"/"B", you can also use DaikinAC-FanRate for allowed values in human-readable format
* fanDirection: Integer, you can also use DaikinAC-FanDirection for allowed values in human-readable format
You can also set single of those keys (e.g. only "Power=true"). When this happends the current data are requested from the device, the relevant values will be changed and all required fields will be re-send to the device. Be carefull, especially on mode changes some values may be needed to be correct (e.g. when changing back from "FAN" to "AUTO" then temperature is empty too, but Auto needs a set temperature).
You can also set single of those keys (e.g. only "Power=true"). When this happens the current data are requested from the device, the relevant values will be changed and all required fields will be re-sent to the device. Be careful, especially on mode changes some values may be needed to be correct (e.g. when changing back from "FAN" to "AUTO" then temperature is empty too, but Auto needs a set temperature).

@@ -201,3 +209,3 @@ ### getACSensorInfo(callback)

```
var Daikin = require('../../index.js');
var Daikin = require('../../lib/index.js');

@@ -232,2 +240,5 @@ Daikin.discover(2, function(result) {

## Changelog
### 2.0.0 (2022-06-09)
* Major update, see notes above
* (theimo1221) Rewrite to typescript

@@ -267,1 +278,4 @@ ### 1.2.2 (2021-06-04)

* initial release
## Disclaimer
**Daikin is a trademark of DAIKIN INDUSTRIES, LTD. I am in no way endorsed by or affiliated with DAIKIN INDUSTRIES, LTD., or any associated subsidiaries, logos or trademarks. This personal project is maintained in spare time.**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc