diff --git a/build/lib/Device.js b/build/lib/Device.js index 1b4395d..449dda4 100644 --- a/build/lib/Device.js +++ b/build/lib/Device.js @@ -27,19 +27,19 @@ module.exports = __toCommonJS(Device_exports); var import_DeviceInfo = require("./DeviceInfo"); var import_suffixes = require("./suffixes"); class WrongMacError extends Error { + static errorName = "WRONGMAC"; + name = "WRONGMAC"; constructor(message) { super(message); - this.name = "WRONGMAC"; } } -WrongMacError.errorName = "WRONGMAC"; class WrongModelError extends Error { + static errorName = "WRONGMODEL"; + name = "WRONGMODEL"; constructor(message) { super(message); - this.name = "WRONGMODEL"; } } -WrongModelError.errorName = "WRONGMODEL"; function processNetworkError(e) { if (e.response) { return e.response.status; @@ -50,6 +50,7 @@ function processNetworkError(e) { } } class Device extends import_DeviceInfo.DeviceInfo { + adapter; constructor(adapter, ip, pin, pinEncrypted) { super(ip, pin, pinEncrypted); this.adapter = adapter; diff --git a/build/lib/Device.js.map b/build/lib/Device.js.map index 58ef2af..ad9375b 100644 --- a/build/lib/Device.js.map +++ b/build/lib/Device.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/Device.ts"], "sourcesContent": ["import { Client } from './Clients';\nimport { DeviceInfo } from './DeviceInfo';\nimport { Suffixes } from './suffixes';\nimport {Mydlink} from './mydlink';\n\nexport class WrongMacError extends Error {\n static errorName = 'WRONGMAC';\n name = 'WRONGMAC';\n constructor(message: string) {\n super(message);\n }\n}\n\nexport class WrongModelError extends Error {\n static errorName = 'WRONGMODEL';\n name = 'WRONGMODEL';\n constructor(message: string) {\n super(message);\n }\n}\n\n/**\n * Get code from network error.\n * @param {Record} e\n * @returns {number|string}\n */\nexport function processNetworkError(e: Record) : number | string {\n if (e.response) {\n // The request was made and the server responded with a status code\n // that falls out of the range of 2xx\n //See if we are logged out -> login again on next poll.\n //otherwise ignore and try again later?\n return e.response.status;\n } else if (e.request) {\n // The request was made but no response was received\n // `error.request` is an instance of XMLHttpRequest in the browser and an instance of\n // http.ClientRequest in node.js\n //probably ECONNRESET or Timeout -> e.code should be set.\n return e.code;\n } else {\n //something else...?\n return e.code;\n }\n}\n\nexport abstract class Device extends DeviceInfo {\n readonly adapter: Mydlink;\n abstract client: Client;\n protected constructor (adapter : Mydlink, ip : string, pin: string, pinEncrypted: boolean) {\n super(ip, pin, pinEncrypted);\n this.adapter = adapter;\n }\n\n /**\n * Stores device configuration as Device Object in ioBroker Database.\n */\n async createDeviceObject () : Promise {\n //do something here.\n if (!this.id) {\n if (!this.mac) {\n this.adapter.log.warn('Could not create device ' + this.name + ' without MAC. Please check config or if device is online.');\n return;\n }\n }\n\n //also set the native part of the device:\n await this.adapter.extendObjectAsync(this.id, {\n type: 'device',\n common: {\n name: this.name,\n statusStates: {\n onlineId: `${this.adapter.namespace}.${this.id}${Suffixes.reachable}`\n }\n } as Partial,\n native: {\n ip: this.ip,\n mac: this.mac,\n pin: this.pinEncrypted,\n pollInterval: Number(this.pollInterval),\n enabled: this.enabled,\n name: this.name,\n model: this.model,\n useWebSocket: this.isWebsocket,\n pinNotEncrypted: false\n }\n });\n }\n\n /**\n * Creates state-objects for the device.\n */\n async createObjects() : Promise {\n //enabled indicator:\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.enabled, {\n type: 'state',\n common: {\n name: 'enabled',\n type: 'boolean',\n role: 'indicator',\n read: true,\n write: false\n },\n native: {}\n });\n\n //have ready indicator:\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.unreachable, {\n type: 'state',\n common: {\n name: 'unreach',\n type: 'boolean',\n role: 'indicator.maintenance.unreach',\n read: true,\n write: false\n },\n native: {}\n });\n\n //have ready indicator:\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.reachable, {\n type: 'state',\n common: {\n name: 'device is reachable',\n type: 'boolean',\n role: 'indicator.reachable',\n read: true,\n write: false\n },\n native: {}\n });\n }\n\n stop() : void {\n if (this.intervalHandle) {\n this.adapter.clearTimeout(this.intervalHandle);\n }\n if (this.client && typeof this.client.disconnect === 'function') {\n this.client.disconnect();\n }\n this.ready = false;\n this.loggedIn = false;\n }\n\n /**\n * Starts log in for device. Needs to be done before additional commands can work.\n **/\n async login() : Promise {\n try {\n const loginResult = await this.client.login();\n if (loginResult === true) {\n this.adapter.log.debug(`${this.name} successfully logged in: ${loginResult}`);\n this.loggedIn = true;\n this.loginErrorPrinted = false;\n } else {\n if (!this.loginErrorPrinted) {\n this.loginErrorPrinted = true;\n this.loggedIn = false;\n this.adapter.log.debug('Login error: device returned ' + loginResult + ' - this should not really happen.');\n this.adapter.log.error(this.name + ' could not login. Please check credentials and if device is online/connected.');\n }\n }\n } catch (e : any) {\n this.adapter.log.debug('Login error: ' + e.stack);\n\n if (!this.loginErrorPrinted && e.code !== 'ETIMEDOUT' && e.code !== 'ECONNABORTED' && e.code !== 'ECONNRESET' && this.model) {\n this.adapter.log.error(this.name + ' could not login. Please check credentials and if device is online/connected. Error: ' + e.code + ' - ' + e.stack);\n this.loginErrorPrinted = true;\n }\n\n this.loggedIn = false;\n if (!this.pollInterval && this.model) { //if no polling takes place, need to retry login!\n if (this.intervalHandle) {\n this.adapter.clearTimeout(this.intervalHandle);\n }\n this.intervalHandle = this.adapter.setTimeout(() => this.start(), 10000); //retry here if no polling.\n }\n }\n return this.loggedIn;\n }\n\n /**\n * Identification of device needs to happen after successful login.\n * Problem: Maybe needs to create new object of new type. Hm...\n */\n async identify() : Promise {\n //for device identification by IP set name to model here:\n if (!this.name) {\n this.name = this.model;\n }\n\n await this.createObjects();\n this.identified = true;\n return this.identified;\n }\n\n async handleNetworkError(e: any) : Promise {\n const code = processNetworkError(e);\n if ([403, 424].includes(code as number) || this.ready) {\n this.loggedIn = false; //login next polling.\n }\n this.adapter.log.debug('Error during communication ' + this.name + ': ' + code + ' - ' + e.stack + ' - ' + e.body);\n this.ready = false;\n if (this.id) {\n await this.adapter.setStateChangedAsync(this.id + Suffixes.unreachable, true, true);\n await this.adapter.setStateChangedAsync(this.id + Suffixes.reachable, false, true);\n }\n return code;\n }\n\n /**\n * Do polling here.\n * @returns {Promise}\n */\n async onInterval() : Promise {\n //this.log.debug('Polling ' + this.name);\n try {\n if (!this.loggedIn) {\n await this.login();\n }\n if (this.loggedIn && !this.identified) {\n await this.identify();\n }\n if (this.loggedIn && this.identified) {\n this.ready = await this.client.isDeviceReady();\n await this.adapter.setStateChangedAsync(this.id + Suffixes.unreachable, !this.ready, true);\n await this.adapter.setStateAsync(this.id + Suffixes.reachable, this.ready, true);\n }\n } catch (e: any) {\n await this.handleNetworkError(e);\n }\n\n if (this.pollInterval > 0) { //only start timeout again, if set in settings.\n this.intervalHandle = this.adapter.setTimeout(() => this.onInterval(),\n this.pollInterval);\n }\n }\n\n /**\n * starting communication with device from config.\n * @returns {Promise}\n */\n async start() : Promise {\n //if device was already started -> stop it.\n //(use case: ip did change or settings did change)\n if (this.ready) {\n this.stop();\n }\n\n //interrogate enabled devices\n //this will get MAC for manually configured devices.\n if (this.enabled) {\n //login:\n await this.login();\n if (this.loggedIn) {\n try {\n await this.identify();\n this.ready = await this.client.isDeviceReady();\n await this.adapter.setStateAsync(this.id + Suffixes.reachable, this.ready, true);\n await this.adapter.setStateAsync(this.id + Suffixes.unreachable, !this.ready, true);\n } catch (e: any) {\n this.adapter.log.error(this.name + ' could not identify device: ' + e.stack);\n }\n }\n }\n\n //transfer enabled flag to object:\n await this.adapter.setStateAsync(this.id + Suffixes.enabled, {val: this.enabled, ack: true});\n\n //start polling if device is enabled (do this after all is set up).\n if (this.enabled) {\n //some devices, for example W245, don't push. So poll websocket also.\n let interval = this.pollInterval;\n if (interval !== undefined && !Number.isNaN(interval) && interval > 0) {\n if (interval < 500) {\n this.adapter.log.warn('Increasing poll rate to twice per second. Please check device config.');\n interval = 500; //polling twice every second should be enough, right?\n }\n if (interval >= 2147483647) {\n interval = 2147483646;\n this.adapter.log.warn('Poll rate was too high, reduced to prevent issues.');\n }\n this.adapter.log.debug('Start polling for ' + this.name + ' with interval ' + interval);\n this.pollInterval = interval;\n this.intervalHandle = this.adapter.setTimeout(() => this.onInterval(),\n this.pollInterval);\n } else {\n this.pollInterval = 0;\n this.adapter.log.debug('Polling of ' + this.name + ' disabled, interval was ' + interval + ' (0 means disabled)');\n }\n }\n }\n\n /**\n * process a state change.\n * @param _id\n * @param _state\n */\n async handleStateChange(_id : string, _state : ioBroker.State) : Promise {\n if (this.loggedIn) {\n await this.login();\n }\n }\n\n}\n\n"], - "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,wBAA2B;AAC3B,sBAAyB;AAGlB,MAAM,sBAAsB,MAAM;AAAA,EAGrC,YAAY,SAAiB;AACzB,UAAM,OAAO;AAFjB,gBAAO;AAAA,EAGP;AACJ;AANa,cACF,YAAY;AAOhB,MAAM,wBAAwB,MAAM;AAAA,EAGvC,YAAY,SAAiB;AACzB,UAAM,OAAO;AAFjB,gBAAO;AAAA,EAGP;AACJ;AANa,gBACF,YAAY;AAYhB,SAAS,oBAAoB,GAA0C;AAC1E,MAAI,EAAE,UAAU;AAKZ,WAAO,EAAE,SAAS;AAAA,EACtB,WAAW,EAAE,SAAS;AAKlB,WAAO,EAAE;AAAA,EACb,OAAO;AAEH,WAAO,EAAE;AAAA,EACb;AACJ;AAEO,MAAe,eAAe,6BAAW;AAAA,EAGlC,YAAa,SAAmB,IAAa,KAAa,cAAuB;AACvF,UAAM,IAAI,KAAK,YAAY;AAC3B,SAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,qBAAsC;AAExC,QAAI,CAAC,KAAK,IAAI;AACV,UAAI,CAAC,KAAK,KAAK;AACX,aAAK,QAAQ,IAAI,KAAK,6BAA6B,KAAK,OAAO,2DAA2D;AAC1H;AAAA,MACJ;AAAA,IACJ;AAGA,UAAM,KAAK,QAAQ,kBAAkB,KAAK,IAAI;AAAA,MAC1C,MAAM;AAAA,MACN,QAAQ;AAAA,QACJ,MAAM,KAAK;AAAA,QACX,cAAc;AAAA,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,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,kBAAkB,KAAc,QAAyC;AAC3E,QAAI,KAAK,UAAU;AACf,YAAM,KAAK,MAAM;AAAA,IACrB;AAAA,EACJ;AAEJ;", "names": [] } diff --git a/build/lib/DeviceInfo.js b/build/lib/DeviceInfo.js index 7461a34..a05dc43 100644 --- a/build/lib/DeviceInfo.js +++ b/build/lib/DeviceInfo.js @@ -32,74 +32,7 @@ function encryptDecrypt(key, value) { return result; } class DeviceInfo { - /** - * Create DeviceInfo only from Ip and Pin, old createDeviceFromIpAndPin - * @param ip - * @param pin - * @param pinEncrypted - is the supplied pin encrypted? - * @constructor - */ - constructor(ip, pin, pinEncrypted) { - /** - * pin of device, needed for login. Should be protected. - */ - this.pinDecrypted = ""; - /** - * pin of device, needed for login. Should be protected. - */ - this.pinEncrypted = ""; - /** - * mac of device, used as base for ID. Should not change. - */ - this.mac = ""; - /** - * id of device, derived from MAC and usable as part of ioBroker object id. - */ - this.id = ""; - /** - * name of device, used for easier debug output. ;-) Should be derived from user / object settings - */ - this.name = ""; - /** - * did we log in or do we need to try that again? - */ - this.loggedIn = false; - /** - * were we able to identify the device, yet, i.e. determine the model and see if right device is at the IP? - */ - this.identified = false; - /** - * device is ready to report / receive commands - */ - this.ready = false; - /** - * prevent to print loginError on every poll. - */ - this.loginErrorPrinted = false; - /** - * Should we poll? If so, how often? - */ - this.pollInterval = 3e4; - /** - * handle for the pollInterval. Used to clear it on exit. - * (is a timeout handle!!) (might also be used to retry login, even if no polling is enabled!) - */ - this.intervalHandle = void 0; - /** - * Model of the device. - */ - this.model = ""; - /** - * is device enabled? if not -> don't look for it. - */ - this.enabled = true; - /** - * How to get rid of that here?? Hm... - */ - this.isWebsocket = false; - this.ip = ip; - this.setPin(pin, pinEncrypted); - } + static secret; /** * Used to set secret from main.ts -> so we can use it here to decrypt stuff if necessary. * @param secret @@ -107,6 +40,18 @@ class DeviceInfo { static setSecret(secret) { DeviceInfo.secret = secret; } + /** + * ip of device, might change in dhcp setups + */ + ip; + /** + * pin of device, needed for login. Should be protected. + */ + pinDecrypted = ""; + /** + * pin of device, needed for login. Should be protected. + */ + pinEncrypted = ""; /** * Set Pin, please supply if it is encrypted or decrypted. * @param pin @@ -124,12 +69,72 @@ class DeviceInfo { this.pinDecrypted = pin; } } + /** + * mac of device, used as base for ID. Should not change. + */ + mac = ""; + /** + * id of device, derived from MAC and usable as part of ioBroker object id. + */ + id = ""; + /** + * name of device, used for easier debug output. ;-) Should be derived from user / object settings + */ + name = ""; + /** + * did we log in or do we need to try that again? + */ + loggedIn = false; + /** + * were we able to identify the device, yet, i.e. determine the model and see if right device is at the IP? + */ + identified = false; + /** + * device is ready to report / receive commands + */ + ready = false; + /** + * prevent to print loginError on every poll. + */ + loginErrorPrinted = false; + /** + * Should we poll? If so, how often? + */ + pollInterval = 3e4; + /** + * handle for the pollInterval. Used to clear it on exit. + * (is a timeout handle!!) (might also be used to retry login, even if no polling is enabled!) + */ + intervalHandle = void 0; + /** + * Model of the device. + */ + model = ""; + /** + * is device enabled? if not -> don't look for it. + */ + enabled = true; + /** + * How to get rid of that here?? Hm... + */ + isWebsocket = false; /** * create id from mac: */ idFromMac() { this.id = this.mac.toUpperCase().replace(/:/g, ""); } + /** + * Create DeviceInfo only from Ip and Pin, old createDeviceFromIpAndPin + * @param ip + * @param pin + * @param pinEncrypted - is the supplied pin encrypted? + * @constructor + */ + constructor(ip, pin, pinEncrypted) { + this.ip = ip; + this.setPin(pin, pinEncrypted); + } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { diff --git a/build/lib/DeviceInfo.js.map b/build/lib/DeviceInfo.js.map index 8f8325c..129dc67 100644 --- a/build/lib/DeviceInfo.js.map +++ b/build/lib/DeviceInfo.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/DeviceInfo.ts"], "sourcesContent": ["/**\n * Used to encrypt & decrypt pin. Necessary as long as js-controller can't decrypt for us in array structure.\n * @param key\n * @param value\n * @returns string\n */\nfunction encryptDecrypt(key : string, value : string) : string {\n if (!value || !key) {\n return value;\n }\n let result = '';\n for (let i = 0; i < value.length; ++i) {\n result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i));\n }\n return result;\n}\n\nexport class DeviceInfo {\n private static secret : string;\n\n /**\n * Used to set secret from main.ts -> so we can use it here to decrypt stuff if necessary.\n * @param secret\n */\n static setSecret (secret : string) : void {\n DeviceInfo.secret = secret;\n }\n\n /**\n * ip of device, might change in dhcp setups\n */\n ip: string;\n /**\n * pin of device, needed for login. Should be protected.\n */\n pinDecrypted = '';\n /**\n * pin of device, needed for login. Should be protected.\n */\n pinEncrypted = '';\n\n /**\n * Set Pin, please supply if it is encrypted or decrypted.\n * @param pin\n * @param encrypted\n */\n setPin(pin : string, encrypted = false) : void {\n if (!pin) {\n pin = 'INVALID';\n }\n if (encrypted) {\n this.pinEncrypted = pin;\n this.pinDecrypted = encryptDecrypt(DeviceInfo.secret, pin);\n } else {\n this.pinEncrypted = encryptDecrypt(DeviceInfo.secret, pin);\n this.pinDecrypted = pin;\n }\n }\n\n /**\n * mac of device, used as base for ID. Should not change.\n */\n mac = '';\n /**\n * id of device, derived from MAC and usable as part of ioBroker object id.\n */\n id = '';\n /**\n * name of device, used for easier debug output. ;-) Should be derived from user / object settings\n */\n name = '';\n /**\n * did we log in or do we need to try that again?\n */\n loggedIn = false;\n /**\n * were we able to identify the device, yet, i.e. determine the model and see if right device is at the IP?\n */\n identified = false;\n /**\n * device is ready to report / receive commands\n */\n ready = false;\n /**\n * prevent to print loginError on every poll.\n */\n loginErrorPrinted = false;\n /**\n * Should we poll? If so, how often?\n */\n pollInterval = 30000;\n /**\n * handle for the pollInterval. Used to clear it on exit.\n * (is a timeout handle!!) (might also be used to retry login, even if no polling is enabled!)\n */\n intervalHandle: ioBroker.Timeout | undefined = undefined;\n /**\n * Model of the device.\n */\n model = '';\n /**\n * is device enabled? if not -> don't look for it.\n */\n enabled = true;\n /**\n * How to get rid of that here?? Hm...\n */\n isWebsocket = false;\n\n /**\n * create id from mac:\n */\n idFromMac() : void {\n this.id = this.mac.toUpperCase().replace(/:/g, '');\n }\n\n /**\n * Create DeviceInfo only from Ip and Pin, old createDeviceFromIpAndPin\n * @param ip\n * @param pin\n * @param pinEncrypted - is the supplied pin encrypted?\n * @constructor\n */\n constructor(ip: string, pin: string, pinEncrypted: boolean) {\n this.ip = ip;\n this.setPin(pin, pinEncrypted);\n }\n\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,SAAS,eAAe,KAAc,OAAyB;AAC3D,MAAI,CAAC,SAAS,CAAC,KAAK;AAChB,WAAO;AAAA,EACX;AACA,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,EAAE,GAAG;AACnC,cAAU,OAAO,aAAa,IAAI,IAAI,IAAI,MAAM,EAAE,WAAW,CAAC,IAAI,MAAM,WAAW,CAAC,CAAC;AAAA,EACzF;AACA,SAAO;AACX;AAEO,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0GpB,YAAY,IAAY,KAAa,cAAuB;AAxF5D;AAAA;AAAA;AAAA,wBAAe;AAIf;AAAA;AAAA;AAAA,wBAAe;AAuBf;AAAA;AAAA;AAAA,eAAM;AAIN;AAAA;AAAA;AAAA,cAAK;AAIL;AAAA;AAAA;AAAA,gBAAO;AAIP;AAAA;AAAA;AAAA,oBAAW;AAIX;AAAA;AAAA;AAAA,sBAAa;AAIb;AAAA;AAAA;AAAA,iBAAQ;AAIR;AAAA;AAAA;AAAA,6BAAoB;AAIpB;AAAA;AAAA;AAAA,wBAAe;AAKf;AAAA;AAAA;AAAA;AAAA,0BAA+C;AAI/C;AAAA;AAAA;AAAA,iBAAQ;AAIR;AAAA;AAAA;AAAA,mBAAU;AAIV;AAAA;AAAA;AAAA,uBAAc;AAiBV,SAAK,KAAK;AACV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WAAW;AACX,WAAK,eAAe;AACpB,WAAK,eAAe,eAAe,WAAW,QAAQ,GAAG;AAAA,IAC7D,OAAO;AACH,WAAK,eAAe,eAAe,WAAW,QAAQ,GAAG;AACzD,WAAK,eAAe;AAAA,IACxB;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM;AAAA;AAAA;AAAA;AAAA,EAIN,KAAK;AAAA;AAAA;AAAA;AAAA,EAIL,OAAO;AAAA;AAAA;AAAA;AAAA,EAIP,WAAW;AAAA;AAAA;AAAA;AAAA,EAIX,aAAa;AAAA;AAAA;AAAA;AAAA,EAIb,QAAQ;AAAA;AAAA;AAAA;AAAA,EAIR,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAIpB,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,EAKf,iBAA+C;AAAA;AAAA;AAAA;AAAA,EAI/C,QAAQ;AAAA;AAAA;AAAA;AAAA,EAIR,UAAU;AAAA;AAAA;AAAA;AAAA,EAIV,cAAc;AAAA;AAAA;AAAA;AAAA,EAKd,YAAmB;AACf,SAAK,KAAK,KAAK,IAAI,YAAY,EAAE,QAAQ,MAAM,EAAE;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,YAAY,IAAY,KAAa,cAAuB;AACxD,SAAK,KAAK;AACV,SAAK,OAAO,KAAK,YAAY;AAAA,EACjC;AAEJ;", "names": [] } diff --git a/build/lib/SoapSierene.js b/build/lib/SoapSierene.js index bc616f1..c828acf 100644 --- a/build/lib/SoapSierene.js +++ b/build/lib/SoapSierene.js @@ -24,12 +24,9 @@ module.exports = __toCommonJS(SoapSierene_exports); var import_suffixes = require("./suffixes"); var import_soapDevice = require("./soapDevice"); class SoapSiren extends import_soapDevice.SoapDevice { - constructor() { - super(...arguments); - this.soundToPlay = 1; - this.volume = 100; - this.duration = 10; - } + soundToPlay = 1; + volume = 100; + duration = 10; /** * process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour. * @param id diff --git a/build/lib/SoapSierene.js.map b/build/lib/SoapSierene.js.map index 09c9ada..5bf91dc 100644 --- a/build/lib/SoapSierene.js.map +++ b/build/lib/SoapSierene.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/SoapSierene.ts"], "sourcesContent": ["//Control of Sirens possible because of mtfluds work here: https://github.com/mtflud/DCH-S220-Web-Control\nimport {Suffixes} from './suffixes';\nimport {SoapDevice} from './soapDevice';\n\nexport class SoapSiren extends SoapDevice {\n soundToPlay = 1;\n volume = 100;\n duration = 10;\n\n /**\n * process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour.\n * @param id\n * @param state\n */\n async handleStateChange(id : string, state : ioBroker.State) : Promise {\n await super.handleStateChange(id, state);\n\n if (id.endsWith(Suffixes.state)) {\n if (typeof state.val === 'boolean') {\n try {\n let newVal;\n if (state.val) {\n newVal = await this.client.setSoundPlay(this.soundToPlay, this.volume, this.duration);\n } else {\n newVal = !(await this.client.setAlarmDismissed());\n }\n await this.adapter.setStateAsync(id, newVal, true);\n } catch(e: any) {\n await this.handleNetworkError(e);\n }\n } else {\n this.adapter.log.warn('Wrong state type. Only boolean accepted for switch.');\n }\n } else {\n if (id.endsWith(Suffixes.soundType)) {\n if (typeof state.val === 'number' && state.val >= 1 && state.val <= 6) {\n this.soundToPlay = state.val;\n } else {\n this.adapter.log.warn(`Wrong value ${state.val} for sound. Expected number in range 1-6 for ${id}`);\n }\n } else if (id.endsWith(Suffixes.soundVolume)) {\n if (typeof state.val === 'number' && state.val >= 1 && state.val <= 100) {\n this.volume = state.val;\n } else {\n this.adapter.log.warn(`Wrong value ${state.val} for volume. Expected number in range 1-100 for ${id}`);\n }\n } else if (id.endsWith(Suffixes.soundDuration)) {\n if (typeof state.val === 'number' && state.val >= 1 && state.val <= 88888) {\n this.duration = state.val;\n } else {\n this.adapter.log.warn(`Wrong value ${state.val} for duration. Expected number in range 1-88888 (where 88888 means infinite) for ${id}`);\n }\n } else {\n this.adapter.log.warn(`State ${id} set to ${state.val} and ack=false, but can't control anything with it.`);\n }\n }\n }\n\n /**\n * Creates objects for the device.\n */\n async createObjects() : Promise {\n await super.createObjects();\n\n //siren uses \"state\" to switch sirene on/off (or report state)\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.state, {\n type: 'state',\n common: {\n name: 'state of sirene',\n type: 'boolean',\n role: 'switch',\n read: true,\n write: true\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.state);\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.soundType, {\n type: 'state',\n common: {\n name: 'sound to play on next play',\n type: 'number',\n role: 'level.mode.sound',\n read: true,\n write: true,\n min: 1,\n max: 6,\n def: 1,\n states: {\n 1: 'EMERGENCY', 2: 'FIRE', 3: 'AMBULANCE',\n 4: 'POLICE', 5: 'DOOR_CHIME', 6: 'BEEP'\n }\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.soundType);\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.soundVolume, {\n type: 'state',\n common: {\n name: 'volume of sirene on next play',\n type: 'number',\n role: 'level.volume',\n read: true,\n write: true,\n min: 1,\n max: 100,\n def: 50\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.soundVolume);\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.soundDuration, {\n type: 'state',\n common: {\n name: 'duration of sirene on next play (88888 = infinite)',\n type: 'number',\n role: 'level.timer',\n read: true,\n write: true,\n unit: 's',\n min: 1,\n max: 88888,\n def: 60\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.soundVolume);\n\n //get initial values:\n let state = await this.adapter.getStateAsync(this.id + Suffixes.soundType);\n if (state && state.val !== null && state.val as number >= 0) {\n this.soundToPlay = state.val as number;\n }\n state = await this.adapter.getStateAsync(this.id + Suffixes.soundVolume);\n if (state && state.val !== null && state.val as number >= 0) {\n this.volume = state.val as number;\n }\n state = await this.adapter.getStateAsync(this.id + Suffixes.soundDuration);\n if (state && state.val !== null && state.val as number >= 0) {\n this.duration = state.val as number;\n }\n }\n\n /**\n * Do polling here.\n * @returns {Promise}\n */\n async onInterval() : Promise {\n await super.onInterval();\n // if not ready -> communication did fail, will be retried on next poll.\n if (this.ready) {\n //check switch status:\n try {\n const val = await this.client.getSoundPlay() as boolean;\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state, val, true);\n } catch (e: any) {\n await this.handleNetworkError(e);\n }\n }\n }\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAuB;AACvB,wBAAyB;AAElB,MAAM,kBAAkB,6BAAW;AAAA,EAAnC;AAAA;AACH,uBAAc;AACd,kBAAS;AACT,oBAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOX,MAAM,kBAAkB,IAAa,OAAwC;AACzE,UAAM,MAAM,kBAAkB,IAAI,KAAK;AAEvC,QAAI,GAAG,SAAS,yBAAS,KAAK,GAAG;AAC7B,UAAI,OAAO,MAAM,QAAQ,WAAW;AAChC,YAAI;AACA,cAAI;AACJ,cAAI,MAAM,KAAK;AACX,qBAAS,MAAM,KAAK,OAAO,aAAa,KAAK,aAAa,KAAK,QAAQ,KAAK,QAAQ;AAAA,UACxF,OAAO;AACH,qBAAS,CAAE,MAAM,KAAK,OAAO,kBAAkB;AAAA,UACnD;AACA,gBAAM,KAAK,QAAQ,cAAc,IAAI,QAAQ,IAAI;AAAA,QACrD,SAAQ,GAAQ;AACZ,gBAAM,KAAK,mBAAmB,CAAC;AAAA,QACnC;AAAA,MACJ,OAAO;AACH,aAAK,QAAQ,IAAI,KAAK,qDAAqD;AAAA,MAC/E;AAAA,IACJ,OAAO;AACH,UAAI,GAAG,SAAS,yBAAS,SAAS,GAAG;AACjC,YAAI,OAAO,MAAM,QAAQ,YAAY,MAAM,OAAO,KAAK,MAAM,OAAO,GAAG;AACnE,eAAK,cAAc,MAAM;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A,QAAQ,CAAC;AAAA,IACb,CAAC;AACD,UAAM,KAAK,QAAQ,qBAAqB,KAAK,KAAK,yBAAS,WAAW;AAGtE,QAAI,QAAQ,MAAM,KAAK,QAAQ,cAAc,KAAK,KAAK,yBAAS,SAAS;AACzE,QAAI,SAAS,MAAM,QAAQ,QAAQ,MAAM,OAAiB,GAAG;AACzD,WAAK,cAAc,MAAM;AAAA,IAC7B;AACA,YAAQ,MAAM,KAAK,QAAQ,cAAc,KAAK,KAAK,yBAAS,WAAW;AACvE,QAAI,SAAS,MAAM,QAAQ,QAAQ,MAAM,OAAiB,GAAG;AACzD,WAAK,SAAS,MAAM;AAAA,IACxB;AACA,YAAQ,MAAM,KAAK,QAAQ,cAAc,KAAK,KAAK,yBAAS,aAAa;AACzE,QAAI,SAAS,MAAM,QAAQ,QAAQ,MAAM,OAAiB,GAAG;AACzD,WAAK,WAAW,MAAM;AAAA,IAC1B;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,aAA6B;AAC/B,UAAM,MAAM,WAAW;AAEvB,QAAI,KAAK,OAAO;AAEZ,UAAI;AACA,cAAM,MAAM,MAAM,KAAK,OAAO,aAAa;AAC3C,cAAM,KAAK,QAAQ,qBAAqB,KAAK,KAAK,yBAAS,OAAO,KAAK,IAAI;AAAA,MAC/E,SAAS,GAAQ;AACb,cAAM,KAAK,mBAAmB,CAAC;AAAA,MACnC;AAAA,IACJ;AAAA,EACJ;AACJ;", "names": [] } diff --git a/build/lib/WebSocketDevice.js b/build/lib/WebSocketDevice.js index cdeab8f..0a18830 100644 --- a/build/lib/WebSocketDevice.js +++ b/build/lib/WebSocketDevice.js @@ -36,10 +36,11 @@ var import_suffixes = require("./suffixes"); var import_axios = __toESM(require("axios")); var import_dlink_websocketclient = __toESM(require("dlink_websocketclient")); class WebSocketDevice extends import_Device.Device { + client; + numSockets = 1; constructor(adapter, ip, pin, pinEncrypted) { var _a; super(adapter, ip, pin, pinEncrypted); - this.numSockets = 1; this.isWebsocket = true; this.client = new import_dlink_websocketclient.default({ ip: this.ip, diff --git a/build/lib/WebSocketDevice.js.map b/build/lib/WebSocketDevice.js.map index ca04e1f..82bd4a1 100644 --- a/build/lib/WebSocketDevice.js.map +++ b/build/lib/WebSocketDevice.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/WebSocketDevice.ts"], "sourcesContent": ["import {Device, processNetworkError, WrongMacError, WrongModelError} from './Device';\nimport {Suffixes} from './suffixes';\nimport {Mydlink} from './mydlink';\nimport {default as axios} from 'axios';\nimport WebSocketClient from 'dlink_websocketclient';\n\nexport class WebSocketDevice extends Device {\n client: WebSocketClient;\n\n numSockets = 1;\n\n constructor(adapter: Mydlink, ip: string, pin: string, pinEncrypted: boolean) {\n super(adapter, ip, pin, pinEncrypted);\n this.isWebsocket = true;\n\n this.client = new WebSocketClient({\n ip: this.ip,\n pin: this.pinDecrypted,\n keepAlive: 5,\n useTelnetForToken: this.pinDecrypted?.toUpperCase() === 'TELNET',\n log: console.debug\n });\n }\n\n /**\n * Creates objects for the device.\n */\n async createObjects() : Promise {\n await super.createObjects();\n if (this.numSockets > 1) {\n //create state for each socket.\n for (let index = 1; index <= this.numSockets; index += 1) {\n const id = this.id + Suffixes.state + '_' + index;\n await this.adapter.setObjectNotExistsAsync(id, {\n type: 'state',\n common: {\n name: 'Socket ' + index,\n type: 'boolean',\n role: 'switch',\n read: true,\n write: true\n },\n native: { index: index }\n });\n await this.adapter.subscribeStatesAsync(id);\n }\n } else {\n //create state object, for plug this is writable for sensor not.\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.state, {\n type: 'state',\n common: {\n name: 'state of plug',\n type: 'boolean',\n role: 'switch',\n read: true,\n write: true\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.state);\n }\n }\n\n stop() : void {\n super.stop();\n if (this.client && typeof this.client.removeAllListeners === 'function') {\n this.client.removeAllListeners('switch');\n this.client.removeAllListeners('error');\n this.client.removeAllListeners('close');\n this.client.removeAllListeners('message');\n }\n }\n\n /**\n * Do polling here.\n * @returns {Promise}\n */\n async onInterval() : Promise {\n await super.onInterval();\n // if not ready -> communication did fail, will be retried on next poll.\n if (this.ready) {\n try {\n if (this.numSockets > 1) {\n const states = await this.client.state(-1) as Array; //get all socket states.\n for (let index = 1; index <= this.numSockets; index += 1) {\n const id = this.id + Suffixes.state + '_' + index;\n const val = states[index - 1];\n await this.adapter.setStateChangedAsync(id, val, true);\n }\n } else {\n const val = await this.client.state(0) as boolean;\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state, val, true);\n }\n } catch (e) {\n await this.handleNetworkError(e);\n }\n }\n }\n\n /**\n * Error handler for event base client.\n */\n async onError(code? : number, err? : Error) : Promise {\n await this.adapter.setStateAsync(this.id + Suffixes.unreachable, true, true);\n if (code || err) {\n this.adapter.log.debug(`${this.name}: Socket error: ${code} - ${(err ? err.stack : err)}`);\n } else {\n this.adapter.log.debug(this.name + ': Socket closed.');\n }\n this.stop();\n this.ready = false;\n //abuse unused intervalHandle here.\n if (this.intervalHandle) {\n this.adapter.clearTimeout(this.intervalHandle);\n }\n this.intervalHandle = this.adapter.setTimeout(() => {\n this.start();\n }, 10000);\n }\n\n /**\n * starting communication with device from config.\n * @returns {Promise}\n */\n async start() : Promise {\n await super.start();\n\n //event listener:\n this.client.on('switched', async (val : boolean, socket : number) => {\n this.adapter.log.debug(`Event from device ${socket} now ${val}`);\n if (this.numSockets > 1) {\n await this.adapter.setStateAsync(this.id + Suffixes.state + '_' + (socket + 1), val, true);\n } else {\n await this.adapter.setStateAsync(this.id + Suffixes.state, val, true);\n }\n });\n //error handling:\n this.client.on('error', (code : number, error : Error) => this.onError(code, error));\n this.client.on('close', () => this.onError());\n this.client.on('message', (message : string) => this.adapter.log.debug(`${this.name} got message: ${message}`));\n await this.adapter.setStateAsync(this.id + Suffixes.unreachable, false, true);\n this.ready = true;\n this.adapter.log.debug('Setup device event listener.');\n }\n\n /**\n * process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour.\n * @param id\n * @param state\n */\n async handleStateChange(id : string, state : ioBroker.State) : Promise {\n if (typeof state.val === 'boolean') {\n if (!this.loggedIn) {\n await this.login();\n }\n\n let socket = 0;\n if (this.numSockets > 1) {\n socket = Number(id.substring(id.lastIndexOf('_') + 1)) - 1; //convert to 0 based index here.\n }\n try {\n const newVal = await this.client.switch(state.val, socket);\n this.adapter.log.debug(`Switched Socket ${socket} of ${this.name} ${state.val ? 'on' : 'off'}.`);\n await this.adapter.setStateAsync(id, newVal, true);\n } catch(e: any) {\n const code = processNetworkError(e);\n if (code === 403) {\n this.loggedIn = false; //login next polling.\n }\n this.adapter.log.error('Error while switching device ' + this.name + ': ' + code + ' - ' + e.stack);\n }\n } else {\n this.adapter.log.warn('Wrong state type. Only boolean accepted for switch.');\n }\n }\n\n async getModelInfoForSentry() : Promise {\n const url = `http://${this.ip}/login?username=Admin&password=${this.pinDecrypted}`;\n const result = await axios.get(url);\n return result.data;\n }\n\n async identify() : Promise {\n const id = this.client.getDeviceId();\n const mac = id.match(/.{2}/g)!.join(':').toUpperCase(); //add back the :.\n\n if (this.mac && this.mac !== mac) {\n throw new WrongMacError(`${this.name} reported mac ${mac}, expected ${this.mac}, probably ip ${this.ip} wrong and talking to wrong device?`);\n }\n this.mac = mac;\n this.id = id;\n\n //get model from webserver / wifi-ssid:\n const url = `http://${this.ip}/login?username=Admin&password=${this.pinDecrypted}`;\n try {\n const result = await axios.get(url);\n if (result.status === 200) {\n const startPos = result.data.indexOf('SSID: ') + 6;\n const model = result.data.substring(startPos, startPos + 8);\n if (!model) {\n this.adapter.log.warn(`${this.name} identify responded with unknown result, please report: ${result.data}`);\n }\n this.adapter.log.debug('Got model ' + model + ' during identification of ' + this.name);\n if (model !== this.model) {\n const oldModel = this.model;\n this.model = model;\n this.adapter.log.info('Model updated from ' + (oldModel || 'unknown') + ' to ' + model);\n throw new WrongModelError(`${this.name} model changed from ${oldModel} to ${model}`);\n }\n } else {\n this.adapter.log.warn(`${this.name} could not be identified: ${result.data}`);\n }\n } catch (e) {\n const code = await this.handleNetworkError(e);\n console.log('Got code: ' + code);\n if (code === 'ECONNREFUSED') {\n this.adapter.log.debug('Failed to identify -> for now assume W118, because that one is nasty.');\n const model = 'DSP-W118';\n if (model !== this.model) {\n const oldModel = this.model;\n this.model = model;\n this.adapter.log.info('Model updated from ' + (oldModel || 'unknown') + ' to ' + model);\n throw new WrongModelError(`${this.name} model changed from ${oldModel} to ${model}`);\n }\n }\n }\n\n //make sure objects are created.\n const superResult = await super.identify();\n\n //get current state:\n if (this.numSockets > 1) {\n const states = await this.client.state(-1) as Array; //get all states.\n for (let index = 1; index <= this.numSockets; index += 1) {\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state + '_' + index, states[index -1], true);\n }\n } else {\n const state = await this.client.state() as boolean;\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state, state, true);\n }\n\n return superResult;\n }\n}"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0E;AAC1E,sBAAuB;AAEvB,mBAA+B;AAC/B,mCAA4B;AAErB,MAAM,wBAAwB,qBAAO;AAAA,EAKxC,YAAY,SAAkB,IAAY,KAAa,cAAuB;AAXlF;AAYQ,UAAM,SAAS,IAAI,KAAK,YAAY;AAHxC,sBAAa;AAIT,SAAK,cAAc;AAEnB,SAAK,SAAS,IAAI,6BAAAA,QAAgB;AAAA,MAC9B,IAAI,KAAK;AAAA,MACT,KAAK,KAAK;AAAA,MACV,WAAW;AAAA,MACX,qBAAmB,UAAK,iBAAL,mBAAmB,mBAAkB;AAAA,MACxD,KAAK,QAAQ;AAAA,IACjB,CAAC;AAAA,EACL;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBAAgC;AAClC,UAAM,MAAM,cAAc;AAC1B,QAAI,KAAK,aAAa,GAAG;AAErB,eAAS,QAAQ,GAAG,SAAS,KAAK,YAAY,SAAS,G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C,YAAM,KAAK,QAAQ,qBAAqB,KAAK,KAAK,yBAAS,OAAO,OAAO,IAAI;AAAA,IACjF;AAEA,WAAO;AAAA,EACX;AACJ;", "names": ["WebSocketClient", "axios"] } diff --git a/build/lib/autoDetect.js b/build/lib/autoDetect.js index 4ab2193..ba09b78 100644 --- a/build/lib/autoDetect.js +++ b/build/lib/autoDetect.js @@ -34,23 +34,10 @@ module.exports = __toCommonJS(autoDetect_exports); var import_mdns_discovery = __toESM(require("mdns-discovery")); var import_WebSocketDevice = require("./WebSocketDevice"); class AutoDetector { - constructor(adapter) { - this.detectedDevices = {}; - this.debug = false; - this.adapter = adapter; - this.mdns = new import_mdns_discovery.default({ - timeout: 0, - //0 == stay active?? - name: ["_dhnap._tcp.local", "_dcp._tcp.local"], - find: "*", - broadcast: false - }); - this.logDebug("Auto detection started"); - if (this.mdns !== void 0) { - this.mdns.on("entry", this.onDetection.bind(this)); - this.mdns.run(() => adapter.log.info("Discovery done")); - } - } + mdns; + adapter; + detectedDevices = {}; + debug = false; logDebug(message) { if (this.debug) { this.adapter.log.debug(message); @@ -165,6 +152,21 @@ class AutoDetector { this.mdns.close(); } } + constructor(adapter) { + this.adapter = adapter; + this.mdns = new import_mdns_discovery.default({ + timeout: 0, + //0 == stay active?? + name: ["_dhnap._tcp.local", "_dcp._tcp.local"], + find: "*", + broadcast: false + }); + this.logDebug("Auto detection started"); + if (this.mdns !== void 0) { + this.mdns.on("entry", this.onDetection.bind(this)); + this.mdns.run(() => adapter.log.info("Discovery done")); + } + } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { diff --git a/build/lib/autoDetect.js.map b/build/lib/autoDetect.js.map index 67e9f6b..ffd1398 100644 --- a/build/lib/autoDetect.js.map +++ b/build/lib/autoDetect.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/autoDetect.ts"], "sourcesContent": ["/// \n\nimport { Mydlink } from './mydlink';\nimport MulticastDNS from 'mdns-discovery';\n\nimport { WebSocketDevice } from './WebSocketDevice';\n\nexport class AutoDetector {\n mdns: MulticastDNS;\n\n adapter: Mydlink;\n\n detectedDevices: Record = {};\n\n debug = false;\n\n logDebug(message: string) : void {\n if (this.debug) {\n this.adapter.log.debug(message);\n }\n }\n\n async onDetection(entry : { ip: string, type: string, name: string, mac: string | undefined, PTR: any | undefined, TXT : any | undefined}) : Promise {\n //format of data: length-byte + text + length-byte + text + length-byte + text ...\n function extractStringsFromBuffer(buffer : Buffer) : string[] {\n let index = 0;\n const strings = [];\n while(index < buffer.length) {\n const length = buffer.readInt8(index);\n index += 1;\n strings.push(buffer.subarray(index, index + length).toString());\n index += length;\n }\n return strings;\n }\n\n //somehow starts to detect fritzbox later on??\n if (entry.name !== '_dhnap._tcp.local' && entry.name !== '_dcp._tcp.local') {\n //this.log.debug('Ignoring false detection? -> ' + entry.ip + ' - ' + entry.name);\n return;\n }\n if (entry.name === '_dcp._tcp.local') {\n this.logDebug('Maybe detected websocket device');\n console.log(entry);\n //get model:\n let model;\n if (entry.PTR && entry.PTR.data) {\n model = entry.PTR.data.substring(0, 8);\n }\n\n //somehow I get records for devices from wrong IP. or they report devices, they detect under their IP?? not sure...\n //let's connect here and get the MAC -> so we can securely identify the device.\n //then decide if it is a new one (update & present in UI) or an old one (ignore for now).\n const newDevice = new WebSocketDevice(this.adapter, entry.ip, 'INVALID', false);\n newDevice.model = model;\n\n try {\n await newDevice.client.login();\n newDevice.id = newDevice.client.getDeviceId().toUpperCase();\n if (newDevice.id) {\n newDevice.mac = newDevice.id.match(/.{2}/g)!.join(':');\n this.logDebug(`Got websocket device ${model} on ${newDevice.ip}`);\n }\n } catch (e: any) {\n this.logDebug('Could not identify websocket device: ' + e.stack);\n } finally {\n newDevice.stop();\n }\n\n //now use mac to check if we already now that device:\n const device = this.adapter.devices.find(device => device.mac === entry.mac);\n if (device) {\n this.logDebug(`Device was already present as ${device.model} on ${device.ip}`);\n if (device.ip === newDevice.ip && device.model !== newDevice.model) {\n this.logDebug(`Model still differs? ${device.model} != ${newDevice.model}`);\n if (model && device.isWebsocket) {\n this.logDebug('Updated model to ' + model);\n device.model = model;\n await device.createDeviceObject(); //store new model in config.\n }\n }\n } else { //not known yet, add to detected devices:\n this.detectedDevices[entry.ip] = {\n ip: newDevice.ip,\n name: entry.name,\n type: model,\n mac: newDevice.mac,\n mydlink: true,\n useWebSocket: true,\n alreadyPresent: !!device\n };\n }\n }\n\n //this.log.debug('Got discovery: ' + JSON.stringify(entry, null, 2));\n if (entry.TXT && entry.TXT.data) {\n //build detected device and fill it:\n let device = this.detectedDevices[entry.ip];\n if (!device) {\n device = {\n ip: entry.ip,\n name: entry.name\n };\n }\n\n //parse buffer:\n const keyValuePairs = extractStringsFromBuffer(entry.TXT.data);\n for (const pair of keyValuePairs) {\n const [ key, value ] = pair.split('=');\n switch(key.toLowerCase()) {\n //extract mac from buffer:\n case 'mac': {\n device.mac = value.toUpperCase();\n break;\n }\n //extract model number from buffer:\n case 'model_number': {\n device.type = value;\n break;\n }\n //if mydlink=true -> we should look at that device! :)\n case 'mydlink': {\n if (value === 'true') {\n device.mydlink = true; //ok, great :-)\n }\n }\n }\n }\n\n if (device.mydlink) {\n this.detectedDevices[device.ip] = device;\n const oldDevice = this.adapter.devices.find(d => d.mac === device.mac);\n if (oldDevice) {\n //update model, if differs.\n if (oldDevice.model !== device.type) {\n oldDevice.model = device.type;\n }\n //found device we already know. Let's check ip.\n if (device.ip !== oldDevice.ip) {\n oldDevice.ip = device.ip;\n await oldDevice.createDeviceObject(); //store IP in config.\n await oldDevice.start();\n }\n device.alreadyPresent = true;\n }\n this.logDebug('Detected Device now is: ' + JSON.stringify(device, null, 2));\n }\n }\n }\n\n close () : void {\n if (this.mdns && typeof this.mdns.close === 'function') {\n this.mdns.close();\n }\n }\n\n constructor (adapter : Mydlink) {\n this.adapter = adapter;\n this.mdns = new MulticastDNS({\n timeout: 0, //0 == stay active??\n name: [ '_dhnap._tcp.local', '_dcp._tcp.local' ],\n find: '*',\n broadcast: false\n });\n\n\n this.logDebug('Auto detection started');\n if (this.mdns !== undefined) {\n this.mdns.on('entry', this.onDetection.bind(this));\n this.mdns.run(() => adapter.log.info('Discovery done'));\n }\n }\n}\n"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,4BAAyB;AAEzB,6BAAgC;AAEzB,MAAM,aAAa;AAAA,EAqJtB,YAAa,SAAmB;AAhJhC,2BAAuC,CAAC;AAExC,iBAAQ;AA+IJ,SAAK,UAAU;AACf,SAAK,OAAO,IAAI,sBAAAA,QAAa;AAAA,MACzB,SAAS;AAAA;AAAA,MACT,MAAM,CAAE,qBAAqB,iBAAkB;AAAA,MAC/C,MAAM;AAAA,MACN,WAAW;AAAA,IACf,CAAC;AAGD,SAAK,SAAS,wBAAwB;AACtC,QAAI,KAAK,SAAS,QAAW;AACzB,WAAK,KAAK,GAAG,SAAS,KAAK,YAAY,KAAK,IAAI,CAAC;AACjD,WAAK,KAAK,IAAI,MAAM,QAAQ,IAAI,KAAK,gBAAgB,CAAC;AAAA,IAC1D;AAAA,EACJ;AAAA,EA3JA,SAAS,SAAwB;AAC7B,QAAI,KAAK,OAAO;AACZ,WAAK,QAAQ,IAAI,MAAM,OAAO;AAAA,IAClC;AAAA,EACJ;AAAA,EAEA,MAAM,YAAY,OAAyI;AAEvJ,aAAS,yBAAyB,QAA4B;AAC1D,UAAI,QAAQ;AACZ,YAAM,UAAU,CAAC;AACjB,aAAM,QAAQ,OAAO,QAAQ;AACzB,cAAM,SAAS,OAAO,SAAS,KAAK;AACpC,iBAAS;AACT,gBAAQ,KAAK,OAAO,SAAS,OAAO,QAAQ,MAAM,EAAE,SAAS,CAAC;AAC9D,iBAAS;AAAA,MACb;AACA,aAAO;AAAA,IACX;AAGA,QAAI,MAAM,SAAS,uBAAuB,MAAM,SAAS,mBAAmB;AAExE;AAAA,IACJ;AACA,QAAI,MAAM,SAAS,mBAAmB;AAClC,WAAK,SAAS,iCAAi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AACJ;", + "names": ["device", "MulticastDNS"] } diff --git a/build/lib/soapDevice.js b/build/lib/soapDevice.js index 0e865c8..6dedfa9 100644 --- a/build/lib/soapDevice.js +++ b/build/lib/soapDevice.js @@ -37,6 +37,7 @@ var import_Device = require("./Device"); var import_suffixes = require("./suffixes"); var import_soapclient = __toESM(require("./soapclient")); class SoapDevice extends import_Device.Device { + client; constructor(adapter, ip, pin, pinEncrypted) { super(adapter, ip, pin, pinEncrypted); this.client = (0, import_soapclient.default)({ @@ -106,13 +107,10 @@ class SoapDevice extends import_Device.Device { } } class SoapSwitch extends SoapDevice { - constructor() { - super(...arguments); - //currently only know DSP-W215 as soap switch which has all those. - this.hasTemp = true; - this.hasPower = true; - this.hasTotalPower = true; - } + //currently only know DSP-W215 as soap switch which has all those. + hasTemp = true; + hasPower = true; + hasTotalPower = true; /** * Creates objects for the device. */ diff --git a/build/lib/soapDevice.js.map b/build/lib/soapDevice.js.map index fd2c112..42a306e 100644 --- a/build/lib/soapDevice.js.map +++ b/build/lib/soapDevice.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/soapDevice.ts"], "sourcesContent": ["\nimport {Device, WrongMacError, WrongModelError} from './Device';\nimport { Suffixes } from './suffixes';\nimport { SoapClientInterface } from './Clients';\nimport createSoapClient from './soapclient';\nimport { Mydlink } from './mydlink';\n\nexport class SoapDevice extends Device {\n client: SoapClientInterface;\n\n constructor(adapter : Mydlink, ip: string, pin: string, pinEncrypted: boolean) {\n super(adapter, ip, pin, pinEncrypted);\n\n //does only set up soapClient -> no connection, yet.\n this.client = createSoapClient({\n user: 'Admin',\n password: this.pinDecrypted,\n url: 'http://' + this.ip + '/HNAP1'\n }) as SoapClientInterface;\n }\n\n /**\n * Creates objects for the device.\n */\n async createObjects() : Promise {\n await super.createObjects();\n //create state object, for plug this is writable for sensor not.\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.reboot, {\n type: 'state',\n common: {\n name: 'reboot device',\n type: 'boolean',\n role: 'button',\n read: false,\n write: true\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.reboot);\n }\n\n /**\n * process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour.\n * @param id\n * @param _state\n */\n async handleStateChange(id : string, _state : ioBroker.State) : Promise {\n if (this.loggedIn) {\n await this.login();\n }\n\n if (id.endsWith(Suffixes.reboot)) {\n try {\n await this.client.reboot();\n this.adapter.log.debug(`Send reboot request to ${this.name}`);\n } catch(e: any) {\n await this.handleNetworkError(e);\n }\n }\n }\n\n async identify() : Promise {\n const settings = await this.client.getDeviceSettings();\n let dirty = false;\n this.adapter.log.debug(this.name + ' returned following device settings: ' + JSON.stringify(settings, null, 2));\n if (this.mac && this.mac !== settings.DeviceMacId) {\n throw new WrongMacError(`${this.name} reported mac ${settings.DeviceMacId}, expected ${this.mac}, probably ip ${this.ip} wrong and talking to wrong device?`);\n }\n if (this.mac !== settings.DeviceMacId) {\n this.mac = (settings.DeviceMacId as string).toUpperCase();\n this.idFromMac();\n dirty = true;\n }\n\n if (this.model !== settings.ModelName) {\n const oldModel = this.model;\n this.model = settings.ModelName as string;\n this.adapter.log.warn(`${this.name} model changed from ${oldModel} to ${settings.ModelName}`);\n throw new WrongModelError(`${this.name} model changed from ${oldModel} to ${settings.ModelName}`);\n }\n\n //let canSwitch = this.model.toUpperCase().includes('DSP') ||\n // ((settings.ModuleTypes as Array).find(t => t.indexOf('Plug') >= 0)); //if is socket, probably can switch on/off\n\n if (dirty) {\n await this.createDeviceObject();\n }\n\n return super.identify();\n }\n}\n\nexport class SoapSwitch extends SoapDevice {\n //currently only know DSP-W215 as soap switch which has all those.\n hasTemp = true;\n hasPower = true;\n hasTotalPower = true;\n\n /**\n * Creates objects for the device.\n */\n async createObjects() : Promise {\n await super.createObjects();\n //create state object, for plug this is writable\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.state, {\n type: 'state',\n common: {\n name: 'state of plug',\n type: 'boolean',\n role: 'switch',\n read: true,\n write: true\n },\n native: {}\n });\n await this.adapter.subscribeStatesAsync(this.id + Suffixes.state);\n\n //currently only know DSP-W215 which has Power & Temperature -> so create here every time.\n //if another socket without those measurements is added, need flags here.\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.temperature, {\n type: 'state',\n common: {\n name: 'temperature',\n type: 'number',\n role: 'value.temperature',\n unit: '\u00B0C',\n read: true,\n write: false\n },\n native: {}\n });\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.power, {\n type: 'state',\n common: {\n name: 'currentPowerConsumption',\n type: 'number',\n role: 'value.power',\n unit: 'W',\n read: true,\n write: false\n },\n native: {}\n });\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.totalPower, {\n type: 'state',\n common: {\n name: 'totalPowerConsumption',\n type: 'number',\n role: 'value.energy.consumed',\n unit: 'kWh',\n read: true,\n write: false\n },\n native: {}\n });\n }\n\n /**\n * Do polling here.\n * @returns {Promise}\n */\n async onInterval() : Promise {\n await super.onInterval();\n // if not ready -> communication did fail, will be retried on next poll.\n if (this.ready) {\n //check switch status:\n try {\n const val = await this.client.state() as boolean;\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state, val, true);\n\n if (this.hasTemp) {\n const temp = await this.client.temperature();\n await this.adapter.setStateChangedAsync(this.id + Suffixes.temperature, temp, true);\n }\n if (this.hasPower) {\n const power = await this.client.consumption();\n await this.adapter.setStateChangedAsync(this.id + Suffixes.power, power, true);\n }\n if (this.hasTotalPower) {\n const totalPower = await this.client.totalConsumption();\n await this.adapter.setStateChangedAsync(this.id + Suffixes.power, totalPower, true);\n }\n } catch (e: any) {\n await this.handleNetworkError(e);\n }\n }\n }\n\n /**\n * process a state change. Device will just try to switch plug. Children will have to overwrite this behaviour.\n * @param id\n * @param state\n */\n async handleStateChange(id : string, state : ioBroker.State) : Promise {\n await super.handleStateChange(id, state);\n\n if (typeof state.val === 'boolean') {\n if (id.endsWith(Suffixes.state)) {\n try {\n await this.client.switch(state.val);\n const newVal = (await this.client.state()) as boolean;\n await this.adapter.setStateAsync(id, newVal, true);\n } catch(e: any) {\n await this.handleNetworkError(e);\n }\n }\n } else {\n this.adapter.log.warn('Wrong state type. Only boolean accepted for switch.');\n }\n }\n}\n\nexport class SoapMotionDetector extends SoapDevice {\n /**\n * Do polling here.\n * @returns {Promise}\n */\n async onInterval() : Promise {\n await super.onInterval();\n // if not ready -> communication did fail, will be retried on next poll.\n if (this.ready) {\n try {\n const lastDetection = await this.client.lastDetection();\n //const notChanged = await new Promise((resolve, reject) => this.adapter.setStateChanged(this.id + Suffixes.lastDetected, lastDetection, true, (err: any, _id: string, notChanged: boolean) => err ? reject(err) : resolve(notChanged)));\n const notChanged = await new Promise((resolve, reject) => this.adapter.setStateChanged(this.id + Suffixes.lastDetected, lastDetection, true, (err, _id, notChanged) => err ? reject(err) : resolve(notChanged || false)));\n if (!notChanged) {\n //timestamp did change -> we had a new detection!\n await this.adapter.setStateAsync(this.id + Suffixes.state, true, true);\n } else {\n await this.adapter.setStateChangedAsync(this.id + Suffixes.state, false, true);\n }\n const noMotion = Math.round((Date.now() - lastDetection) / 1000);\n await this.adapter.setStateChangedAsync(this.id + Suffixes.noMotion, noMotion, true);\n } catch (e: any) {\n await this.handleNetworkError(e);\n }\n }\n }\n\n /**\n * Creates objects for the device.\n */\n async createObjects() : Promise {\n await super.createObjects();\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.state, {\n type: 'state',\n common: {\n name: 'state',\n type: 'boolean',\n role: 'sensor.motion',\n read: true,\n write: false\n },\n native: {}\n });\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.noMotion, {\n type: 'state',\n common: {\n name: 'No motion since',\n type: 'number',\n role: 'value.interval',\n unit: 'seconds',\n read: true,\n write: false\n },\n native: {}\n });\n\n await this.adapter.setObjectNotExistsAsync(this.id + Suffixes.lastDetected, {\n type: 'state',\n common: {\n name: 'lastDetected',\n type: 'number',\n role: 'value.time',\n read: true,\n write: false\n },\n native: {}\n });\n }\n}\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I;AAAA,QACjF;AACA,cAAM,WAAW,KAAK,OAAO,KAAK,IAAI,IAAI,iBAAiB,GAAI;AAC/D,cAAM,KAAK,QAAQ,qBAAqB,KAAK,KAAK,yBAAS,UAAU,UAAU,IAAI;AAAA,MACvF,SAAS,GAAQ;AACb,cAAM,KAAK,mBAAmB,CAAC;AAAA,MACnC;AAAA,IACJ;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBAAgC;AAClC,UAAM,MAAM,cAAc;AAC1B,UAAM,KAAK,QAAQ,wBAAwB,KAAK,KAAK,yBAAS,OAAO;AAAA,MACjE,MAAM;AAAA,MACN,QAAQ;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,MACX;AAAA,MACA,QAAQ,CAAC;AAAA,IACb,CAAC;AAED,UAAM,KAAK,QAAQ,wBAAwB,KAAK,KAAK,yBAAS,UAAU;AAAA,MACpE,MAAM;AAAA,MACN,QAAQ;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,MACX;AAAA,MACA,QAAQ,CAAC;AAAA,IACb,CAAC;AAED,UAAM,KAAK,QAAQ,wBAAwB,KAAK,KAAK,yBAAS,cAAc;AAAA,MACxE,MAAM;AAAA,MACN,QAAQ;AAAA,QACJ,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,MAAM;AAAA,QACN,OAAO;AAAA,MACX;AAAA,MACA,QAAQ,CAAC;AAAA,IACb,CAAC;AAAA,EACL;AACJ;", "names": ["createSoapClient", "notChanged"] } diff --git a/build/lib/soapclient.js b/build/lib/soapclient.js index f8c39dd..935271f 100644 --- a/build/lib/soapclient.js +++ b/build/lib/soapclient.js @@ -39,6 +39,9 @@ var import_http = __toESM(require("http")); const HNAP1_XMLNS = "http://purenetworks.com/HNAP1/"; const HNAP_LOGIN_METHOD = "Login"; class HNAP_ERROR extends Error { + errno; + code; + body; constructor(message, errno, body, code = -1) { super(message); this.errno = errno; diff --git a/build/lib/soapclient.js.map b/build/lib/soapclient.js.map index 19f5c18..850ce56 100644 --- a/build/lib/soapclient.js.map +++ b/build/lib/soapclient.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../../src/lib/soapclient.ts"], "sourcesContent": ["/*\n Mostly based on the work of bikerp, see: https://github.com/bikerp/dsp-w215-hnap\n Modifications to fit newer firmware and be used as library by Garfonso.\n\n Control of Sirens possible because of mtfluds work here: https://github.com/mtflud/DCH-S220-Web-Control\n\n The MIT License (MIT)\n\n Copyright (c) 2015 bikerp\n\n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n\n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n*/\n\nimport * as crypto from 'crypto';\nimport axios from 'axios';\nimport {DOMParser} from '@xmldom/xmldom';\nimport http from 'http';\nimport {SoapClientInterface} from './Clients';\n\nconst HNAP1_XMLNS = 'http://purenetworks.com/HNAP1/';\n//const HNAP_METHOD = 'POST';\n//const HNAP_BODY_ENCODING = 'UTF8';\nconst HNAP_LOGIN_METHOD = 'Login';\n\nclass HNAP_ERROR extends Error {\n errno: number;\n code: number;\n body: string;\n constructor(message: string, errno : number, body: string, code = -1) {\n super(message);\n this.errno = errno;\n this.code = code >= 0 ? code : errno;\n this.body = body;\n }\n}\n\n/**\n * Encrypt stuff like we need it with HNAP. No clue, what I am doing here. Ignore name of parameters. ;-)\n * @param key\n * @param challenge\n */\nfunction hmac(key : string, challenge : string): string {\n return crypto.createHmac('md5', key).update(challenge).digest('hex').toUpperCase();\n}\n\n/**\n * Creates a soapClient.\n * @param opt - parameters, must have url, user and password.\n */\nexport const soapClient = function (opt = { url: '', user: '', password: ''}) : SoapClientInterface {\n const HNAP_AUTH = {\n url: opt.url || '',\n user: opt.user || '',\n pwd: opt.password || '',\n result: '',\n challenge: '',\n publicKey: '',\n cookie: '',\n privateKey: ''\n };\n //console.debug('New Soapclient with options ', opt);\n\n const agent = new http.Agent({\n keepAlive: true,\n //maxSockets: 1,\n keepAliveMsecs: 60000,\n timeout: 10000\n });\n\n //extract tokens from login response into HNAP_AUTH object\n function save_login_result(body : string) : void {\n const doc = new DOMParser().parseFromString(body);\n if (doc) {\n HNAP_AUTH.result = doc.getElementsByTagName(HNAP_LOGIN_METHOD + 'Result')!.item(0)!.firstChild!.nodeValue!;\n HNAP_AUTH.challenge = doc.getElementsByTagName('Challenge')!.item(0)!.firstChild!.nodeValue!;\n HNAP_AUTH.publicKey = doc.getElementsByTagName('PublicKey')!.item(0)!.firstChild!.nodeValue!;\n HNAP_AUTH.cookie = doc.getElementsByTagName('Cookie')!.item(0)!.firstChild!.nodeValue!;\n HNAP_AUTH.privateKey = hmac(HNAP_AUTH.publicKey + HNAP_AUTH.pwd, HNAP_AUTH.challenge);\n }\n }\n\n function loginRequest() : string {\n return 'request'\n + '' + HNAP_AUTH.user + ''\n + ''\n + '';\n }\n\n function loginParameters() : string {\n const login_pwd = hmac(HNAP_AUTH.privateKey, HNAP_AUTH.challenge);\n return 'login'\n + '' + HNAP_AUTH.user + ''\n + '' + login_pwd + ''\n + '';\n }\n\n function requestBody(method : string, parameters : string) : string {\n return '' +\n '' +\n '' +\n '<' + method + ' xmlns=\"' + HNAP1_XMLNS + '\">' +\n parameters +\n '' +\n '';\n }\n\n /**\n *\n * @param method\n * @param responseElement\n * @param body\n * @param {boolean} [fullBody] if true will return fullBody xml instead of only result value.\n * @returns {Promise}\n */\n function soapAction(method : string, responseElement : string | Array, body : string, fullBody = false) : Promise | Record> {\n //console.log('Sending Body ' + body);\n return axios.post(HNAP_AUTH.url, body,\n {\n headers: {\n 'Content-Type': 'text/xml; charset=utf-8',\n 'SOAPAction': '\"' + HNAP1_XMLNS + method + '\"',\n 'HNAP_AUTH': getHnapAuth('\"' + HNAP1_XMLNS + method + '\"', HNAP_AUTH.privateKey),\n 'cookie': 'uid=' + HNAP_AUTH.cookie\n },\n timeout: 10000, //timeout in ms\n httpAgent: agent\n }).then(function (response) {\n const incomingBody = response.data;\n if (response.status === 403) {\n throw new HNAP_ERROR('Unauthorized, need to login.', 403, incomingBody);\n }\n console.debug('StatusCode: ' + response.status + ' Body: ' + incomingBody);\n if (fullBody) { //return full body if requested.\n return incomingBody;\n }\n const result = readResponseValue(incomingBody, method + 'Result');\n if (typeof result === 'string' && result.toUpperCase() === 'ERROR') {\n throw new HNAP_ERROR(\n 'Request not successful. Probably need to login again. Status: ' + response.status,\n response.status, incomingBody, response.status < 300 ? 403 : response.status);\n }\n return readResponseValue(incomingBody, responseElement);\n }).catch(function (err) {\n console.log('error during soapaction:', err);\n throw err;\n });\n }\n\n function moduleParameters(module : string | number) : string {\n return '' + module + '';\n }\n\n function controlParameters(module : string | number, status : string | boolean) : string {\n return moduleParameters(module) +\n 'Socket 1Socket 1' +\n '' + status + '1';\n }\n\n /**\n * Create parameters for SetPlaySound request\n * @param [soundnum] should be one of the string from getSounds 1-6\n * @param [volume] 1-100\n * @param [duration] 1-88888 (with 88888 = infinite)\n * @returns {string}\n */\n function soundParameters(soundnum? : number, volume? : number, duration? : number) : string {\n let params = `1\n 1`;\n if (soundnum !== undefined) {\n params += `${soundnum}`;\n }\n if (volume !== undefined) {\n params += `${volume}`;\n }\n if (duration !== undefined) {\n params += `${duration}`;\n }\n return params;\n }\n\n /**\n * Returns an Object of possible sounds with LABELS and the numbers they translate in.\n * @returns {{EMERGENCY: number, DOOR_CHIME: number, BEEP: number, AMBULANCE: number, FIRE: number, POLICE: number}}\n */\n /*function getSounds() : {EMERGENCY: number, DOOR_CHIME: number, BEEP: number, AMBULANCE: number, FIRE: number, POLICE: number} {\n return {\n EMERGENCY: 1,\n FIRE: 2,\n AMBULANCE: 3,\n POLICE: 4,\n DOOR_CHIME: 5,\n BEEP: 6\n };\n }*/\n\n /*\n unused stuff\n function radioParameters(radio : string) : string {\n return '' + radio + '';\n }\n function APClientParameters() : string {\n return 'true' +\n 'RADIO_2.4GHz' +\n 'My_Network' +\n 'XX:XX:XX:XX:XX:XX' +\n '0' +\n '' +\n '' +\n 'WPA2-PSK' +\n '' +\n 'AES' +\n '' +\n '' +\n '' +\n '';//'' + AES.AES_Encrypt128('password', HNAP_AUTH.privateKey) + ''; //TODO: commented out.. do I need that at all??\n }\n\n function groupParameters(group : string | number) : string {\n return '' + group + '';\n }\n function temperatureSettingsParameters(module : string | number) : string {\n return moduleParameters(module) +\n 'TemperatureMonitor 3' +\n 'Temperature Monitor 3' +\n '80' +\n 'Not Available' +\n 'true';\n }\n function powerWarningParameters() : string {\n return '28' +\n '70' +\n 'Weekly' +\n '1';\n }\n */\n\n function getHnapAuth(SoapAction : string, privateKey : string) : string {\n const current_time = new Date();\n const time_stamp = Math.round(current_time.getTime() / 1000);\n const auth = hmac(privateKey,time_stamp + SoapAction);\n return auth + ' ' + time_stamp;\n }\n\n function readResponseValue(body : string, elementName : string | Array) : string | number | boolean | Array | Record | undefined {\n if (typeof elementName === 'object' && typeof elementName.forEach === 'function') { //sloppy isArray check.\n const results = {} as Record;\n elementName.forEach(function (elemName : string): void {\n results[elemName] = readResponseValue(body, elemName) as string;\n });\n return results;\n } else {\n if (body && elementName && typeof elementName === 'string') {\n const doc = new DOMParser().parseFromString(body);\n const node = doc.getElementsByTagName(elementName).item(0);\n // Check that we have children of node.\n //if (elementName === 'ModuleTypes') {\n // console.debug('node: ', node, ' firstChild: ', node.firstChild, ' nodeValue: ', node.firstChild.nodeValue);\n // console.debug('Content: ', node.textContent);\n //}\n const result = (node && node.firstChild) ? node.firstChild.nodeValue : 'ERROR';\n if (result === null) { //array of values requested like Module Types or SOAP Actions:\n const results = [] as Array;\n //console.debug('Have array:', node);\n Object.keys(node!.childNodes).forEach(function (value : string, key : number) {\n const child = node!.childNodes[key];\n //console.debug('Child:', child);\n if (child && child.firstChild) {\n results.push(child.firstChild.nodeValue as string);\n }\n });\n return results;\n } else {\n return result;\n }\n }\n }\n }\n\n function login() : Promise {\n //console.log('Sending Body ' + loginRequest());\n return axios.post(HNAP_AUTH.url,\n requestBody(HNAP_LOGIN_METHOD, loginRequest()),\n { //first request challenge and stuff\n headers: {\n 'Content-Type': 'text/xml; charset=utf-8',\n 'SOAPAction': '\"' + HNAP1_XMLNS + HNAP_LOGIN_METHOD + '\"',\n 'connection': 'keep-alive'\n },\n timeout: 10000,\n httpAgent: agent\n }).then(function (response) { //then log in with the information gathered in first request\n //save keys.\n //console.log('Login request came back: ', response);\n //console.log('Body: ', response.data);\n save_login_result(response.data);\n //console.log('Got results: ', HNAP_AUTH);\n //will return 'success' if worked.\n return soapAction(HNAP_LOGIN_METHOD, 'LoginResult',\n requestBody(HNAP_LOGIN_METHOD, loginParameters()));\n }).then((result) => {\n return result === 'success';\n }).catch(function (err) {\n //throw error here, so we can react to it outside (?)\n console.log('error during HNAP login:', err);\n throw err;\n });\n }\n\n /**\n * Get full device description XMLs -> used to support new devices.\n * @returns {Promise}\n */\n async function getDeviceDescriptionXML() : Promise<{deviceSettingsXML: string, modulesSoapActions: string}> {\n return {\n deviceSettingsXML: await soapAction('GetDeviceSettings',\n 'Result',\n requestBody('GetDeviceSettings', ''), true) as string,\n modulesSoapActions: await soapAction('GetModuleSOAPActions',\n 'SOAPActions',\n requestBody('GetModuleSOAPActions', moduleParameters('0')), true) as string\n }; //get full body of DeviceSettings\n }\n\n //API:\n return {\n login: login,\n\n disconnect: function () {\n agent.destroy();\n },\n\n /**\n * Switches Plug\n * @param {boolean} on target status\n * @returns {Promise<*>}\n */\n switch: function (on : boolean) : Promise {\n return soapAction('SetSocketSettings', 'SetSocketSettingsResult', requestBody('SetSocketSettings', controlParameters(1, on))) as Promise\n },\n\n //polls current state\n state: async function () {\n const val = await soapAction('GetSocketSettings', 'OPStatus', requestBody('GetSocketSettings', moduleParameters(1)));\n return val === 'true';\n },\n\n //polls last detection\n lastDetection: async function () {\n const result = await soapAction('GetLatestDetection', 'LatestDetectTime', requestBody('GetLatestDetection', moduleParameters(1))) as number;\n return result * 1000;\n },\n\n //polls power consumption\n consumption: async function () {\n const result = await soapAction('GetCurrentPowerConsumption', 'CurrentConsumption', requestBody('GetCurrentPowerConsumption', moduleParameters(2)));\n return Number(result);\n },\n\n //polls total power consumption\n totalConsumption: async function () {\n const result = await soapAction('GetPMWarningThreshold', 'TotalConsumption', requestBody('GetPMWarningThreshold', moduleParameters(2)));\n return Number(result);\n },\n\n //polls current temperature\n temperature: async function () {\n const result = await soapAction('GetCurrentTemperature', 'CurrentTemperature', requestBody('GetCurrentTemperature', moduleParameters(3)));\n return Number(result);\n },\n\n //returns model name and firmware version. Could be very interesting for supporting additional devices.\n //also useful to know which states to create for a device (i.e. plug or motion detection)\n getDeviceSettings: function () : Promise> {\n return soapAction('GetDeviceSettings',\n [\n 'GetDeviceSettingsResult',\n 'DeviceMacId',\n 'ModelName',\n 'ModelDescription',\n 'HardwareVersion',\n 'FirmwareVersion',\n 'PresentationURL',\n 'ModuleTypes' //not yet helpfully implemented. Hm\n ],\n requestBody('GetDeviceSettings', '')) as Promise>;\n },\n\n //reboot device\n reboot: function () : Promise {\n return soapAction('Reboot', 'RebootResult', requestBody('Reboot', '')) as Promise;\n },\n\n /**\n * Returns true if device is ready.\n * @returns {Promise}\n */\n isDeviceReady: async function () {\n const result = await soapAction('IsDeviceReady', 'IsDeviceReadyResult', requestBody('IsDeviceReady', ''));\n return result === 'OK';\n },\n\n setSoundPlay: function (sound : number, volume : number, duration : number) : Promise {\n return soapAction('SetSoundPlay', 'SetSoundPlayResult', requestBody('SetSoundPlay', soundParameters(sound, volume, duration))) as Promise;\n },\n\n setAlarmDismissed: function () : Promise {\n return soapAction('SetAlarmDismissed', 'SetAlarmDismissedResult', requestBody('SetAlarmDismissed', soundParameters())) as Promise;\n },\n\n getSoundPlay: async function () {\n const result = await soapAction('GetSirenAlarmSettings', 'IsSounding', requestBody('GetSirenAlarmSettings', soundParameters()));\n return result === 'true';\n },\n\n getDeviceDescriptionXML: getDeviceDescriptionXML,\n\n //getSounds: getSounds\n\n /* unused stuff.\n //gets information about Wi-Fi\n getAPClientSettings: function () {\n return soapAction('GetAPClientSettings', 'GetAPClientSettingsResult', requestBody('GetAPClientSettings', radioParameters('RADIO_2.4GHz')));\n },\n\n //set power warning?\n setPowerWarning: function () {\n return soapAction('SetPMWarningThreshold', 'SetPMWarningThresholdResult', requestBody('SetPMWarningThreshold', powerWarningParameters()));\n },\n\n //poll power warning\n getPowerWarning: function () {\n return soapAction('GetPMWarningThreshold', 'GetPMWarningThresholdResult', requestBody('GetPMWarningThreshold', moduleParameters(2)));\n },\n\n //not very interesting, returns timezone and set locale.\n getDeviceSettings2: function () {\n return soapAction('GetDeviceSettings2', 'GetDeviceSettings2Result', requestBody('GetDeviceSettings2', ''));\n },\n\n getTemperatureSettings: function () {\n return soapAction('GetTempMonitorSettings', 'GetTempMonitorSettingsResult', requestBody('GetTempMonitorSettings', moduleParameters(3)));\n },\n\n setTemperatureSettings: function () {\n return soapAction('SetTempMonitorSettings', 'SetTempMonitorSettingsResult', requestBody('SetTempMonitorSettings', temperatureSettingsParameters(3)));\n },\n\n getSiteSurvey: function () {\n return soapAction('GetSiteSurvey', 'GetSiteSurveyResult', requestBody('GetSiteSurvey', radioParameters('RADIO_2.4GHz')));\n },\n\n triggerWirelessSiteSurvey: function () {\n return soapAction('SetTriggerWirelessSiteSurvey', 'SetTriggerWirelessSiteSurveyResult', requestBody('SetTriggerWirelessSiteSurvey', radioParameters('RADIO_2.4GHz')));\n },\n\n getModuleSchedule: function () {\n return soapAction('GetModuleSchedule', 'GetModuleScheduleResult', requestBody('GetModuleSchedule', moduleParameters(0)));\n },\n\n getModuleEnabled: function () {\n return soapAction('GetModuleEnabled', 'GetModuleEnabledResult', requestBody('GetModuleEnabled', moduleParameters(0)));\n },\n\n getModuleGroup: function () {\n return soapAction('GetModuleGroup', 'GetModuleGroupResult', requestBody('GetModuleGroup', groupParameters(0)));\n },\n\n //get actions supported by module\n getModuleSOAPActions: function (module = 0) {\n return soapAction('GetModuleSOAPActions', 'SOAPActions', requestBody('GetModuleSOAPActions', moduleParameters(module)));\n },\n\n getMotionDetectorSettings: function(module = 1) {\n return soapAction('GetMotionDetectorSettings', 'GetMotionDetectorSettingsResult', requestBody('GetMotionDetectorSettings', moduleParameters(module)));\n },\n\n getScheduleSettings: function () {\n return soapAction('GetScheduleSettings', 'GetScheduleSettingsResult', requestBody('GetScheduleSettings', ''));\n },\n\n setFactoryDefault: function () {\n return soapAction('SetFactoryDefault', 'SetFactoryDefaultResult', requestBody('SetFactoryDefault', ''));\n },\n\n getWLanRadios: function () {\n return soapAction('GetWLanRadios', 'GetWLanRadiosResult', requestBody('GetWLanRadios', ''));\n },\n\n getInternetSettings: function () {\n return soapAction('GetInternetSettings', 'GetInternetSettingsResult', requestBody('GetInternetSettings', ''));\n },\n\n setAPClientSettings: function () {\n return soapAction('SetAPClientSettings', 'SetAPClientSettingsResult', requestBody('SetAPClientSettings', APClientParameters()));\n },\n\n settriggerADIC: function () {\n return soapAction('SettriggerADIC', 'SettriggerADICResult', requestBody('SettriggerADIC', ''));\n },\n */\n };\n};\n\nexport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AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAsFJ;AACJ;AAEA,IAAO,qBAAQ;", "names": ["http", "axios", "module"] } diff --git a/build/main.js b/build/main.js index 5c1ade2..4d6a4fe 100644 --- a/build/main.js +++ b/build/main.js @@ -27,31 +27,31 @@ var import_autoDetect = require("./lib/autoDetect"); var import_TableDevice = require("./lib/TableDevice"); var import_DeviceFactory = require("./lib/DeviceFactory"); class Mydlink extends utils.Adapter { + /** + * Array of devices. + * Device consists of: + * config: which includes IP, PIN, ... set by the user + * client: soapclient for interaction with device + * @type {Array} + */ + devices = []; + /** + * Store devices here, that we only have information from, but can not yet talk to. + * Especially if model is missing, and we currently can not retrieve it (because device not online) + * This will happen. + */ + unidentifiedDevices = []; + /** + * Auto-detected devices. Store here and aggregate until we are sure it is mydlink and have mac + * -> multiple messages. + * @type {{}} + */ + autoDetector = void 0; constructor(options = {}) { super({ ...options, name: "mydlink" }); - /** - * Array of devices. - * Device consists of: - * config: which includes IP, PIN, ... set by the user - * client: soapclient for interaction with device - * @type {Array} - */ - this.devices = []; - /** - * Store devices here, that we only have information from, but can not yet talk to. - * Especially if model is missing, and we currently can not retrieve it (because device not online) - * This will happen. - */ - this.unidentifiedDevices = []; - /** - * Auto-detected devices. Store here and aggregate until we are sure it is mydlink and have mac - * -> multiple messages. - * @type {{}} - */ - this.autoDetector = void 0; this.on("ready", this.onReady.bind(this)); this.on("stateChange", this.onStateChange.bind(this)); this.on("message", this.onMessage.bind(this)); diff --git a/build/main.js.map b/build/main.js.map index c075a5b..b1ed48d 100644 --- a/build/main.js.map +++ b/build/main.js.map @@ -2,6 +2,6 @@ "version": 3, "sources": ["../src/main.ts"], "sourcesContent": ["/*\n * Created with @iobroker/create-adapter v2.2.0\n */\n\n// The adapter-core module gives you access to the core ioBroker functions\n// you need to create an adapter\nimport * as utils from '@iobroker/adapter-core';\n\nimport {Device} from './lib/Device';\nimport { DeviceInfo } from './lib/DeviceInfo';\nimport { AutoDetector } from './lib/autoDetect';\nimport {sanitizeTableDevice, TableDevice} from './lib/TableDevice';\nimport {createFromObject, createFromTable} from './lib/DeviceFactory';\n\n// Load your modules here, e.g.:\n// import * as fs from \"fs\";\n\nclass Mydlink extends utils.Adapter {\n /**\n * Array of devices.\n * Device consists of:\n * config: which includes IP, PIN, ... set by the user\n * client: soapclient for interaction with device\n * @type {Array}\n */\n devices: Array = [];\n\n /**\n * Store devices here, that we only have information from, but can not yet talk to.\n * Especially if model is missing, and we currently can not retrieve it (because device not online)\n * This will happen.\n */\n unidentifiedDevices: Array = [];\n\n /**\n * Auto-detected devices. Store here and aggregate until we are sure it is mydlink and have mac\n * -> multiple messages.\n * @type {{}}\n */\n autoDetector: AutoDetector | undefined = undefined;\n\n public constructor(options: Partial = {}) {\n super({\n ...options,\n name: 'mydlink',\n });\n this.on('ready', this.onReady.bind(this));\n this.on('stateChange', this.onStateChange.bind(this));\n this.on('message', this.onMessage.bind(this));\n this.on('unload', this.onUnload.bind(this));\n }\n\n /**\n * deletes all objects of a device and the device itself (deleteDeviceAsync does not work somehow...?)\n * @param {Device} device\n */\n async deleteDeviceFull(device: Device) : Promise {\n //stop device:\n device.stop();\n\n //check if detected device:\n if (this.autoDetector) {\n for (const ip of Object.keys(this.autoDetector.detectedDevices)) {\n const dectDevice = this.autoDetector.detectedDevices[ip];\n if (dectDevice.mac === device.id) {\n dectDevice.alreadyPresent = false;\n }\n }\n }\n\n try {\n const ids = await this.getObjectListAsync({\n startkey: this.namespace + '.' + device.id,\n endkey: this.namespace + '.' + device.id + '\\u9999'\n });\n if (ids) {\n for (const obj of ids.rows) {\n await this.delObjectAsync(obj.value._id);\n }\n }\n } catch (e: any) {\n this.log.error('Error during deletion of ' + device.id + ': ' + e.stack);\n }\n }\n\n /**\n * Is called when databases are connected and adapter received configuration.\n */\n private async onReady(): Promise {\n // Initialize your adapter here\n\n //get secret for decryption:\n const systemConfig = await this.getForeignObjectAsync('system.config');\n if (systemConfig) {\n DeviceInfo.setSecret(systemConfig.native ? systemConfig.native.secret : 'RJaeBLRPwvPfh5O'); //fallback in case or for old installations without secret.\n }\n\n // Reset the connection indicator during startup\n await this.delObjectAsync('info', {recursive: true});\n\n //start auto detection:\n this.autoDetector = new AutoDetector(this);\n\n //start existing devices:\n const existingDevices = await this.getDevicesAsync();\n const configDevicesToAdd = [].concat(this.config.devices) as TableDevice[];\n this.log.debug('Got existing devices: ' + JSON.stringify(existingDevices, null, 2));\n this.log.debug('Got config devices: ' + JSON.stringify(configDevicesToAdd, null, 2));\n let needUpdateConfig = false;\n for (const existingDevice of existingDevices) {\n let found = false;\n for (const configDevice of this.config.devices as TableDevice[]) {\n sanitizeTableDevice(configDevice);\n needUpdateConfig = !configDevice.mac;\n if ((configDevice.mac && configDevice.mac === existingDevice.native.mac) ||\n (!configDevice.mac && configDevice.ip === existingDevice.native.ip)) {\n found = true;\n\n //copy all data from config, because now only config is changed from config dialog.\n for (const key of Object.keys(configDevice)) {\n existingDevice.native[key] = configDevice[key]; //copy all fields.\n }\n existingDevice.native.pinNotEncrypted = !configDevice.mac;\n\n configDevicesToAdd.splice(configDevicesToAdd.indexOf(configDevice), 1);\n break; //break on first copy -> will remove additional copies later.\n }\n }\n const device = await createFromObject(this, existingDevice);\n await device.createDeviceObject(); //store new config.\n if (existingDevice.native.pinNotEncrypted) {\n needUpdateConfig = true;\n }\n if (found) {\n await device.start();\n //keep config and client for later reference.\n this.devices.push(device);\n } else {\n this.log.debug('Deleting ' + device.name);\n await this.deleteDeviceFull(device);\n }\n }\n\n //add non-existing devices from config:\n for (const configDevice of configDevicesToAdd) {\n sanitizeTableDevice(configDevice);\n const device = await createFromTable(this, configDevice, !configDevice.pinNotEncrypted);\n this.log.debug('Device ' + device.name + ' in config but not in devices -> create and add.');\n const oldDevice = this.devices.find(d => d.mac === device.mac);\n if (oldDevice) {\n this.log.info('Duplicate entry for ' + device.mac + ' in config. Trying to rectify. Restart will happen. Affected devices: ' + device.name + ' === ' + configDevice.name);\n needUpdateConfig = true;\n } else {\n //make sure objects are created:\n await device.createDeviceObject();\n\n await device.start();\n //call this here again, to make sure it happens.\n await device.createDeviceObject(); //store device settings\n //keep config and client for later reference.\n this.devices.push(device);\n }\n }\n\n //try to update config:\n if (needUpdateConfig) {\n const devices = [];\n for (const device of this.devices) {\n const configDevice = {\n ip: device.ip,\n mac: device.mac,\n pin: device.pinEncrypted,\n pollInterval: device.pollInterval,\n enabled: device.enabled,\n name: device.name,\n model: device.model,\n useWebSocket: device.isWebsocket\n };\n devices.push(configDevice);\n }\n await this.extendForeignObjectAsync('system.adapter.' + this.namespace, {\n native: {\n devices: devices\n }\n });\n }\n }\n\n /**\n * Is called when adapter shuts down - callback has to be called under any circumstances!\n */\n private onUnload(callback: () => void): void {\n try {\n this.log.debug('Stop polling');\n for (const device of this.devices) {\n device.stop();\n }\n if (this.autoDetector) {\n this.autoDetector.close();\n }\n\n this.log.info('cleaned everything up...');\n callback();\n } catch (e) {\n callback();\n }\n }\n\n /**\n * Is called if a subscribed state changes\n */\n private async onStateChange(id: string, state: ioBroker.State | null | undefined): Promise {\n if (state) { //ignore delete state\n // The state was changed\n this.log.info(`state ${id} changed: ${state.val} (ack = ${state.ack})`);\n\n //only act if ack = false.\n if (state.ack === false) {\n const deviceId = id.split('.')[2]; //0 = adapter, 1 = instance -> 2 = device id.\n const device = this.devices.find(d => d.id === deviceId);\n if (device) {\n await device.handleStateChange(id, state);\n } else {\n this.log.info(`Unknown device ${deviceId} for ${id}. Can't control anything.`);\n }\n }\n }\n }\n\n // If you need to accept messages in your adapter, uncomment the following block and the corresponding line in the constructor.\n // /**\n // * Some message was sent to this instance over message box. Used by email, pushover, text2speech, ...\n // * Using this method requires \"common.messagebox\" property to be set to true in io-package.json\n // */\n private async onMessage(obj: ioBroker.Message) : Promise {\n if (typeof obj === 'object' && obj.message) {\n switch(obj.command) {\n case 'discovery': {\n // Send response in callback if required\n if (obj.callback) {\n const devices = [];\n if (this.autoDetector) {\n for (const key of Object.keys(this.autoDetector.detectedDevices)) {\n const device = this.autoDetector.detectedDevices[key];\n device.readOnly = true;\n devices.push(device);\n }\n }\n this.sendTo(obj.from, obj.command, devices, obj.callback);\n }\n break;\n }\n case 'getDevices': {\n const tableDevices = [];\n for (const device of this.devices) {\n const tableDevice = {\n name: device.name,\n mac: device.mac,\n ip: device.ip,\n pin: device.pinDecrypted,\n pollInterval: device.pollInterval,\n enabled: device.enabled\n };\n tableDevices.push(tableDevice);\n }\n if (obj.callback) {\n this.sendTo(obj.from, obj.command, tableDevices, obj.callback);\n }\n break;\n }\n case 'identifyDevice': {\n const params = (obj.message) as Record;\n if (params && params.ip && params.pin) {\n let device = await createFromTable(this, {\n ip: params.ip,\n pin: params.pin\n }, false);\n try {\n await device.start();\n if (device.loggedIn && device.identified) { //will be false if ip wrong or duplicate mac.\n const oldDevice = this.devices.find(d => d.mac === device.mac);\n if (oldDevice) {\n device.stop();\n device = oldDevice;\n } else {\n this.devices.push(device);\n }\n const sendDevice = {\n mac: device.mac,\n name: device.name,\n ip: device.ip,\n pollInterval: device.pollInterval,\n pin: device.pinDecrypted,\n enabled: device.loggedIn && device.identified\n };\n if (obj.callback) {\n this.sendTo(obj.from, obj.command, sendDevice, obj.callback);\n }\n } else {\n this.log.info('could not login -> error.');\n this.sendTo(obj.from, obj.command, 'ERROR', obj.callback);\n }\n } catch (e : any) {\n this.log.info('could not login device: ' + e.stack);\n if (obj.callback) {\n this.sendTo(obj.from, obj.command, 'ERROR', obj.callback);\n }\n }\n }\n break;\n }\n default: {\n this.log.debug('Unknown command ' + obj.command);\n break;\n }\n }\n }\n }\n}\n\nif (require.main !== module) {\n // Export the constructor in compact mode\n module.exports = (options: Partial | undefined) => new Mydlink(options);\n} else {\n // otherwise start the instance directly\n (() => new Mydlink())();\n}"], - "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAMA,YAAuB;AAGvB,wBAA2B;AAC3B,wBAA6B;AAC7B,yBAA+C;AAC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Q,KAAK,MAAM;AAAA,gBAC5B;AACA,sBAAM,aAAa;AAAA,kBACf,KAAK,OAAO;AAAA,kBACZ,MAAM,OAAO;AAAA,kBACb,IAAI,OAAO;AAAA,kBACX,cAAc,OAAO;AAAA,kBACrB,KAAK,OAAO;AAAA,kBACZ,SAAS,OAAO,YAAY,OAAO;AAAA,gBACvC;AACA,oBAAI,IAAI,UAAU;AACd,uBAAK,OAAO,IAAI,MAAM,IAAI,SAAS,YAAY,IAAI,QAAQ;AAAA,gBAC/D;AAAA,cACJ,OAAO;AACH,qBAAK,IAAI,KAAK,2BAA2B;AACzC,qBAAK,OAAO,IAAI,MAAM,IAAI,SAAS,SAAS,IAAI,QAAQ;AAAA,cAC5D;AAAA,YACJ,SAAS,GAAS;AACd,mBAAK,IAAI,KAAK,6BAA6B,EAAE,KAAK;AAClD,kBAAI,IAAI,UAAU;AACd,qBAAK,OAAO,IAAI,MAAM,IAAI,SAAS,SAAS,IAAI,QAAQ;AAAA,cAC5D;AAAA,YACJ;AAAA,UACJ;AACA;AAAA,QACJ;AAAA,QACA,SAAS;AACL,eAAK,IAAI,MAAM,qBAAqB,IAAI,OAAO;AAC/C;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AACJ;AAEA,IAAI,QAAQ,SAAS,QAAQ;AAEzB,SAAO,UAAU,CAAC,YAAuD,IAAI,QAAQ,OAAO;AAChG,OAAO;AAEH,GAAC,MAAM,IAAI,QAAQ,GAAG;AAC1B;", "names": [] } diff --git a/package-lock.json b/package-lock.json index 334abc4..5034f60 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.3.6", "license": "MIT", "dependencies": { - "@iobroker/adapter-core": "^3.1.4", + "@iobroker/adapter-core": "^3.1.6", "@xmldom/xmldom": "^0.8.10", "axios": "^1.7.2", "dlink_websocketclient": "^0.5.5", @@ -21,11 +21,11 @@ "@alcalzone/release-script-plugin-license": "^3.7.0", "@iobroker/adapter-dev": "^1.3.0", "@iobroker/testing": "^4.1.3", - "@iobroker/types": "^5.0.19", - "@tsconfig/node16": "^16.1.3", + "@iobroker/types": "^6.0.5", + "@tsconfig/node18": "^18.2.4", "@types/chai": "^4.3.16", "@types/chai-as-promised": "^7.1.8", - "@types/mocha": "^10.0.6", + "@types/mocha": "^10.0.7", "@types/node": "^18.19.33 < 19", "@types/proxyquire": "^1.3.31", "@types/sinon": "^17.0.3", @@ -35,14 +35,14 @@ "chai": "^4.4.1", "chai-as-promised": "^7.1.2", "eslint": "^8.57.0", - "mocha": "^10.4.0", + "mocha": "^10.5.1", "proxyquire": "^2.1.3", "rimraf": "^5.0.7", - "sinon": "^17.0.2", + "sinon": "^18.0.0", "sinon-chai": "^3.7.0", "source-map-support": "^0.5.21", "ts-node": "^10.9.2", - "typescript": "~5.4.5" + "typescript": "~5.5.2" }, "engines": { "node": ">=18.0.0" @@ -974,15 +974,15 @@ "license": "BSD-3-Clause" }, "node_modules/@iobroker/adapter-core": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@iobroker/adapter-core/-/adapter-core-3.1.4.tgz", - "integrity": "sha512-RYDGB8Vk/MEKvMMwo4fLgxY8kjHrCeQmqROo/JxQYiLBEA4/gwFCTpxdD6s7RQ+dh4yZoH16/yTWqdgyR6NAxQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/@iobroker/adapter-core/-/adapter-core-3.1.6.tgz", + "integrity": "sha512-cArv8IzVsP3r8HivsYwO02e5WueboIH9v66PkHSGtadeUQQKUyxV32dzirM6YArWcI6+Iw5USQgVR9E+ryP3xg==", "license": "MIT", "engines": { "npm": ">=7.0.0" }, "peerDependencies": { - "@iobroker/types": "^5.0.11" + "@iobroker/types": "^6.0.0" } }, "node_modules/@iobroker/adapter-dev": { @@ -1082,9 +1082,9 @@ } }, "node_modules/@iobroker/types": { - "version": "5.0.19", - "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-5.0.19.tgz", - "integrity": "sha512-FY+lpPbYVlX/WHzEGVIXZrM6XQXI+GtWb3E/ZR2ZKdSBK4/w7VezUQuqxq1lYW914LxjcynXxYtLxHva/nal6g==", + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-6.0.5.tgz", + "integrity": "sha512-olzFyefudC497Qs6KmVEdjHdudXMV5dCKcxapN2/6JyIbqC2XIt+X3slqvg724vWQIRDstR5bKeKfqyTPwLu9g==", "license": "MIT", "engines": { "node": ">=12.0.0" @@ -1420,10 +1420,10 @@ "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", "dev": true }, - "node_modules/@tsconfig/node16": { - "version": "16.1.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.3.tgz", - "integrity": "sha512-9nTOUBn+EMKO6rtSZJk+DcqsfgtlERGT9XPJ5PRj/HNENPCBY1yu/JEj5wT6GLtbCLBO2k46SeXDaY0pjMqypw==", + "node_modules/@tsconfig/node18": { + "version": "18.2.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-18.2.4.tgz", + "integrity": "sha512-5xxU8vVs9/FNcvm3gE07fPbn9tl6tqGGWA9tSlwsUEkBxtRnTsNmwrV8gasZ9F/EobaSv9+nu8AxUKccw77JpQ==", "dev": true, "license": "MIT" }, @@ -1501,10 +1501,11 @@ "license": "MIT" }, "node_modules/@types/mocha": { - "version": "10.0.6", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", - "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", - "dev": true + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", + "dev": true, + "license": "MIT" }, "node_modules/@types/node": { "version": "18.19.33", @@ -4022,15 +4023,15 @@ } }, "node_modules/mocha": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.4.0.tgz", - "integrity": "sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA==", + "version": "10.5.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.5.1.tgz", + "integrity": "sha512-eq5tEnaz2kM9ade8cuGJBMh5fBb9Ih/TB+ddlmPR+wLQmwLhUwa0ovqDlg7OTfKquW0BI7NUcNWX7DH8sC+3gw==", "dev": true, "license": "MIT", "dependencies": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "chokidar": "3.5.3", + "chokidar": "^3.5.3", "debug": "4.3.4", "diff": "5.0.0", "escape-string-regexp": "4.0.0", @@ -4874,10 +4875,9 @@ "dev": true }, "node_modules/sinon": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-17.0.2.tgz", - "integrity": "sha512-uihLiaB9FhzesElPDFZA7hDcNABzsVHwr3YfmM9sBllVwab3l0ltGlRV1XhpNfIacNDLGD1QRZNLs5nU5+hTuA==", - "deprecated": "There", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.0.tgz", + "integrity": "sha512-+dXDXzD1sBO6HlmZDd7mXZCR/y5ECiEiGCBSGuFD/kZ0bDTofPYc6JaeGmPSF+1j1MejGUWkORbYOLDyvqCWpA==", "dev": true, "license": "BSD-3-Clause", "dependencies": { @@ -4885,7 +4885,7 @@ "@sinonjs/fake-timers": "^11.2.2", "@sinonjs/samsam": "^8.0.0", "diff": "^5.2.0", - "nise": "^5.1.9", + "nise": "^6.0.0", "supports-color": "^7" }, "funding": { @@ -4913,6 +4913,20 @@ "node": ">=0.3.1" } }, + "node_modules/sinon/node_modules/nise": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.0.0.tgz", + "integrity": "sha512-K8ePqo9BFvN31HXwEtTNGzgrPpmvgciDsFz8aztFjt4LqKO/JeFD8tBOeuDiCMXrIl/m1YvfH8auSpxfaD09wg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -5243,9 +5257,9 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "dev": true, "license": "Apache-2.0", "bin": { @@ -6091,9 +6105,9 @@ "dev": true }, "@iobroker/adapter-core": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/@iobroker/adapter-core/-/adapter-core-3.1.4.tgz", - "integrity": "sha512-RYDGB8Vk/MEKvMMwo4fLgxY8kjHrCeQmqROo/JxQYiLBEA4/gwFCTpxdD6s7RQ+dh4yZoH16/yTWqdgyR6NAxQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/@iobroker/adapter-core/-/adapter-core-3.1.6.tgz", + "integrity": "sha512-cArv8IzVsP3r8HivsYwO02e5WueboIH9v66PkHSGtadeUQQKUyxV32dzirM6YArWcI6+Iw5USQgVR9E+ryP3xg==", "requires": {} }, "@iobroker/adapter-dev": { @@ -6173,9 +6187,9 @@ } }, "@iobroker/types": { - "version": "5.0.19", - "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-5.0.19.tgz", - "integrity": "sha512-FY+lpPbYVlX/WHzEGVIXZrM6XQXI+GtWb3E/ZR2ZKdSBK4/w7VezUQuqxq1lYW914LxjcynXxYtLxHva/nal6g==" + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/@iobroker/types/-/types-6.0.5.tgz", + "integrity": "sha512-olzFyefudC497Qs6KmVEdjHdudXMV5dCKcxapN2/6JyIbqC2XIt+X3slqvg724vWQIRDstR5bKeKfqyTPwLu9g==" }, "@isaacs/cliui": { "version": "8.0.2", @@ -6440,10 +6454,10 @@ "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", "dev": true }, - "@tsconfig/node16": { - "version": "16.1.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-16.1.3.tgz", - "integrity": "sha512-9nTOUBn+EMKO6rtSZJk+DcqsfgtlERGT9XPJ5PRj/HNENPCBY1yu/JEj5wT6GLtbCLBO2k46SeXDaY0pjMqypw==", + "@tsconfig/node18": { + "version": "18.2.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node18/-/node18-18.2.4.tgz", + "integrity": "sha512-5xxU8vVs9/FNcvm3gE07fPbn9tl6tqGGWA9tSlwsUEkBxtRnTsNmwrV8gasZ9F/EobaSv9+nu8AxUKccw77JpQ==", "dev": true }, "@types/chai": { @@ -6512,9 +6526,9 @@ "dev": true }, "@types/mocha": { - "version": "10.0.6", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.6.tgz", - "integrity": "sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==", + "version": "10.0.7", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.7.tgz", + "integrity": "sha512-GN8yJ1mNTcFcah/wKEFIJckJx9iJLoMSzWcfRRuxz/Jk+U6KQNnml+etbtxFK8lPjzOw3zp4Ha/kjSst9fsHYw==", "dev": true }, "@types/node": { @@ -8327,14 +8341,14 @@ "dev": true }, "mocha": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.4.0.tgz", - "integrity": "sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA==", + "version": "10.5.1", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.5.1.tgz", + "integrity": "sha512-eq5tEnaz2kM9ade8cuGJBMh5fBb9Ih/TB+ddlmPR+wLQmwLhUwa0ovqDlg7OTfKquW0BI7NUcNWX7DH8sC+3gw==", "dev": true, "requires": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", - "chokidar": "3.5.3", + "chokidar": "^3.5.3", "debug": "4.3.4", "diff": "5.0.0", "escape-string-regexp": "4.0.0", @@ -8925,16 +8939,16 @@ "dev": true }, "sinon": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/sinon/-/sinon-17.0.2.tgz", - "integrity": "sha512-uihLiaB9FhzesElPDFZA7hDcNABzsVHwr3YfmM9sBllVwab3l0ltGlRV1XhpNfIacNDLGD1QRZNLs5nU5+hTuA==", + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-18.0.0.tgz", + "integrity": "sha512-+dXDXzD1sBO6HlmZDd7mXZCR/y5ECiEiGCBSGuFD/kZ0bDTofPYc6JaeGmPSF+1j1MejGUWkORbYOLDyvqCWpA==", "dev": true, "requires": { "@sinonjs/commons": "^3.0.1", "@sinonjs/fake-timers": "^11.2.2", "@sinonjs/samsam": "^8.0.0", "diff": "^5.2.0", - "nise": "^5.1.9", + "nise": "^6.0.0", "supports-color": "^7" }, "dependencies": { @@ -8943,6 +8957,19 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", "dev": true + }, + "nise": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/nise/-/nise-6.0.0.tgz", + "integrity": "sha512-K8ePqo9BFvN31HXwEtTNGzgrPpmvgciDsFz8aztFjt4LqKO/JeFD8tBOeuDiCMXrIl/m1YvfH8auSpxfaD09wg==", + "dev": true, + "requires": { + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" + } } } }, @@ -9186,9 +9213,9 @@ "dev": true }, "typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "dev": true }, "uc.micro": { diff --git a/package.json b/package.json index 37d860c..38cda95 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "node": ">=18.0.0" }, "dependencies": { - "@iobroker/adapter-core": "^3.1.4", + "@iobroker/adapter-core": "^3.1.6", "@xmldom/xmldom": "^0.8.10", "axios": "^1.7.2", "dlink_websocketclient": "^0.5.5", @@ -40,11 +40,11 @@ "@alcalzone/release-script-plugin-license": "^3.7.0", "@iobroker/adapter-dev": "^1.3.0", "@iobroker/testing": "^4.1.3", - "@iobroker/types": "^5.0.19", - "@tsconfig/node16": "^16.1.3", + "@iobroker/types": "^6.0.5", + "@tsconfig/node18": "^18.2.4", "@types/chai": "^4.3.16", "@types/chai-as-promised": "^7.1.8", - "@types/mocha": "^10.0.6", + "@types/mocha": "^10.0.7", "@types/node": "^18.19.33 < 19", "@types/proxyquire": "^1.3.31", "@types/sinon": "^17.0.3", @@ -54,14 +54,14 @@ "chai": "^4.4.1", "chai-as-promised": "^7.1.2", "eslint": "^8.57.0", - "mocha": "^10.4.0", + "mocha": "^10.5.1", "proxyquire": "^2.1.3", "rimraf": "^5.0.7", - "sinon": "^17.0.2", + "sinon": "^18.0.0", "sinon-chai": "^3.7.0", "source-map-support": "^0.5.21", "ts-node": "^10.9.2", - "typescript": "~5.4.5" + "typescript": "~5.5.2" }, "main": "build/main.js", "files": [ diff --git a/tsconfig.json b/tsconfig.json index 46e8289..f50c690 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ { // To update the compilation target, install a different version of @tsconfig/node... and reference it here // https://github.com/tsconfig/bases#node-16-tsconfigjson - "extends": "@tsconfig/node16/tsconfig.json", + "extends": "@tsconfig/node18/tsconfig.json", "compilerOptions": { // do not compile anything, this file is just to configure type checking // the compilation is configured in tsconfig.build.json