mini_program_gizwits_sdk 3.2.18 → 3.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var n=t[s]={i:s,l:!1,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(s,n,function(t){return e[t]}.bind(null,n));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=17)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==t&&t.crypto&&(n=t.crypto),!n)try{n=i(35)}catch(e){}var r=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),c={},o=c.lib={},l=o.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=o.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,n=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<n;r++){var a=i[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=a<<24-(s+r)%4*8}else for(var c=0;c<n;c+=4)t[s+c>>>2]=i[c>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new d.init(t,e)}}),u=c.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=o.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,n=s.words,r=s.sigBytes,a=this.blockSize,c=r/(4*a),o=(c=t?e.ceil(c):e.max((0|c)-this._minBufferSize,0))*a,l=e.min(4*o,r);if(o){for(var u=0;u<o;u+=a)this._doProcessBlock(n,u);i=n.splice(0,o),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(o.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),c.algo={});return c}(Math),s)}).call(this,i(34))},function(e,t,i){var s,n,r,a,c,o,l,d,u,h,f,p,v,g,y,_,D,m,S;e.exports=(s=i(0),i(6),void(s.lib.Cipher||(n=s,r=n.lib,a=r.Base,c=r.WordArray,o=r.BufferedBlockAlgorithm,l=n.enc,l.Utf8,d=l.Base64,u=n.algo.EvpKDF,h=r.Cipher=o.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){o.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?S:D}return function(t){return{encrypt:function(i,s,n){return e(s).encrypt(t,i,s,n)},decrypt:function(i,s,n){return e(s).decrypt(t,i,s,n)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=n.mode={},p=r.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,n=this._iv;n?(s=n,this._iv=void 0):s=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=s[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize;t.call(this,e,i,n),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+n)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=e.slice(i,i+n);s.decryptBlock(e,i),t.call(this,e,i,n),this._prevBlock=r}}),e}(),g=(n.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,n=s<<24|s<<16|s<<8|s,r=[],a=0;a<s;a+=4)r.push(n);var o=c.create(r,s);e.concat(o)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(n.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?c.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=c.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},D=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var n=e.createEncryptor(i,s),r=n.finalize(t),a=n.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(n.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=c.random(8));var n=u.create({keySize:t+i}).compute(e,s),r=c.create(n.words.slice(t),4*i);return n.sigBytes=4*t,y.create({key:n,iv:r,salt:s})}},S=r.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var n=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=n.iv;var r=D.encrypt.call(this,e,t,n.key,s);return r.mixIn(n),r},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var n=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=n.iv,D.decrypt.call(this,e,t,n.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=s(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,n=new Array(s).fill(0).join("");return i?e+=n:e=n+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,n=t+2,r=e.substring(t,n);i.push(parseInt(r,16))}return i};const n=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=n;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const r=n(e[s]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),n=i(33);t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),n.default(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:s.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class n{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=s.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=s.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=s.getProtocolLen(i);this.len=n.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=s.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}n.decodeLen=e=>{let t=1,i=0,s=0,n=0;do{s=e[n],i+=(127&s)*t,t*=128,n+=1}while(0!=(128&s));return i},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),i(14),i(15),n=(s=d).lib,r=n.Base,a=n.WordArray,c=s.algo,o=c.MD5,l=c.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:o,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,n=s.hasher.create(),r=a.create(),c=r.words,o=s.keySize,l=s.iterations;c.length<o;){i&&n.update(i),i=n.update(e).finalize(t),n.reset();for(var d=1;d<l;d++)i=n.finalize(i),n.reset();r.concat(i)}return r.sigBytes=4*o,r}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var n=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,c=0;c<4&&r+.75*c<i;c++)n.push(s.charAt(a>>>6*(3-c)&63));var o=s.charAt(64);if(o)for(;n.length%4;)n.push(o);return n.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var r=0;r<i.length;r++)s[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var c=e.indexOf(a);-1!==c&&(t=c)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var c=i[e.charCodeAt(a-1)]<<a%4*2,o=i[e.charCodeAt(a)]>>>6-a%4*2,l=c|o;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,c=[];!function(){for(var t=0;t<64;t++)c[t]=4294967296*e.abs(e.sin(t+1))|0}();var o=a.MD5=r.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,n=e[s];e[s]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var r=this._hash.words,a=e[t+0],o=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],D=e[t+8],m=e[t+9],S=e[t+10],b=e[t+11],w=e[t+12],k=e[t+13],B=e[t+14],I=e[t+15],C=r[0],A=r[1],x=r[2],E=r[3];C=l(C,A,x,E,a,7,c[0]),E=l(E,C,A,x,o,12,c[1]),x=l(x,E,C,A,f,17,c[2]),A=l(A,x,E,C,p,22,c[3]),C=l(C,A,x,E,v,7,c[4]),E=l(E,C,A,x,g,12,c[5]),x=l(x,E,C,A,y,17,c[6]),A=l(A,x,E,C,_,22,c[7]),C=l(C,A,x,E,D,7,c[8]),E=l(E,C,A,x,m,12,c[9]),x=l(x,E,C,A,S,17,c[10]),A=l(A,x,E,C,b,22,c[11]),C=l(C,A,x,E,w,7,c[12]),E=l(E,C,A,x,k,12,c[13]),x=l(x,E,C,A,B,17,c[14]),C=d(C,A=l(A,x,E,C,I,22,c[15]),x,E,o,5,c[16]),E=d(E,C,A,x,y,9,c[17]),x=d(x,E,C,A,b,14,c[18]),A=d(A,x,E,C,a,20,c[19]),C=d(C,A,x,E,g,5,c[20]),E=d(E,C,A,x,S,9,c[21]),x=d(x,E,C,A,I,14,c[22]),A=d(A,x,E,C,v,20,c[23]),C=d(C,A,x,E,m,5,c[24]),E=d(E,C,A,x,B,9,c[25]),x=d(x,E,C,A,p,14,c[26]),A=d(A,x,E,C,D,20,c[27]),C=d(C,A,x,E,k,5,c[28]),E=d(E,C,A,x,f,9,c[29]),x=d(x,E,C,A,_,14,c[30]),C=u(C,A=d(A,x,E,C,w,20,c[31]),x,E,g,4,c[32]),E=u(E,C,A,x,D,11,c[33]),x=u(x,E,C,A,b,16,c[34]),A=u(A,x,E,C,B,23,c[35]),C=u(C,A,x,E,o,4,c[36]),E=u(E,C,A,x,v,11,c[37]),x=u(x,E,C,A,_,16,c[38]),A=u(A,x,E,C,S,23,c[39]),C=u(C,A,x,E,k,4,c[40]),E=u(E,C,A,x,a,11,c[41]),x=u(x,E,C,A,p,16,c[42]),A=u(A,x,E,C,y,23,c[43]),C=u(C,A,x,E,m,4,c[44]),E=u(E,C,A,x,w,11,c[45]),x=u(x,E,C,A,I,16,c[46]),C=h(C,A=u(A,x,E,C,f,23,c[47]),x,E,a,6,c[48]),E=h(E,C,A,x,_,10,c[49]),x=h(x,E,C,A,B,15,c[50]),A=h(A,x,E,C,g,21,c[51]),C=h(C,A,x,E,w,6,c[52]),E=h(E,C,A,x,p,10,c[53]),x=h(x,E,C,A,S,15,c[54]),A=h(A,x,E,C,o,21,c[55]),C=h(C,A,x,E,D,6,c[56]),E=h(E,C,A,x,I,10,c[57]),x=h(x,E,C,A,y,15,c[58]),A=h(A,x,E,C,k,21,c[59]),C=h(C,A,x,E,v,6,c[60]),E=h(E,C,A,x,b,10,c[61]),x=h(x,E,C,A,f,15,c[62]),A=h(A,x,E,C,m,21,c[63]),r[0]=r[0]+C|0,r[1]=r[1]+A|0,r[2]=r[2]+x|0,r[3]=r[3]+E|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;i[n>>>5]|=128<<24-n%32;var r=e.floor(s/4294967296),a=s;i[15+(n+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(n+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var c=this._hash,o=c.words,l=0;l<4;l++){var d=o[l];o[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return c},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,n,r,a){var c=e+(t&i|~t&s)+n+a;return(c<<r|c>>>32-r)+t}function d(e,t,i,s,n,r,a){var c=e+(t&s|i&~s)+n+a;return(c<<r|c>>>32-r)+t}function u(e,t,i,s,n,r,a){var c=e+(t^i^s)+n+a;return(c<<r|c>>>32-r)+t}function h(e,t,i,s,n,r,a){var c=e+(i^(t|~s))+n+a;return(c<<r|c>>>32-r)+t}t.MD5=r._createHelper(o),t.HmacMD5=r._createHmacHelper(o)}(Math),s.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(3);function n(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=n,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),n=Math.max(e.length,t.length);for(;i.length<n;)i.push("0");for(;s.length<n;)s.push("0");for(let i=0;i<n;i++){const s=parseInt(e[i]),n=parseInt(t[i]);if(s>n)return 1;if(s<n)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i};function r(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),s=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:s}}function a(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),s=e.slice(0,e.byteLength-16),r=n(i);if(t.find(e=>e===r)){const e=n(s);return{productKey:r,mac:e}}{i=e.slice(0,16),s=e.slice(16),r=n(i);const t=n(s);return{productKey:r,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,s="",r="",a=1;const c=new Uint8Array(e);for(;!(i>e.byteLength-1);){const o=c[i];if(o<=0||!o)break;if(e.byteLength<o+i+1)break;const l=e.slice(i+1,i+o+1);if(o>=6&&o<=8&&(s=n(l),16==s.length&&(s=s.substring(0,15))),16==o){const e=n(l).toLowerCase();t.find(t=>t===e)&&(r=e)}1==o&&(a=new Uint8Array(l)[0]),i+=1+o}return{bleWorkStatus:a,mac:s,productKey:r}})(e,t):{mac:"",productKey:"",bleWorkStatus:1},t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID,s.connectType=i.connectType,s.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?s.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},c={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{s.default.log("parse BLE_BROADCAST");const t=r(a(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,c.connectType="BLE_BROADCAST"}catch(e){}break;default:n=t.advertisData2PkAndMac(e.advertisData,i)}return c=Object.assign(Object.assign({},c),n),c},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=r,t.ab2numbers=a;let o=0;function l(e,t){let i=1,s=t;return e.map(e=>{const t=65535&(e^s);return s=i-t&65535,i<<=1,c(t,4)})}function d(e,t,i){if(i.length>22)throw new Error("最大长度为22");const n=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),a=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),o=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return s.default.log("明文",c(e,4),c((t<<8)+r,4),o.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...l(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=l,t.convertToServiceUuids=({len:e=null,data:i=null,index:s=0,mac:n})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,c=[147,r,...a],l=d(n,(()=>{const e=o;return o=o+1&255,e})(),c);return[...new Set(l)].length!==l.length?t.convertToServiceUuids({len:r,data:a,index:s++,mac:n}):l},t.convertToUuids=d},function(e,t,i){var s;e.exports=(s=i(0),i(13),i(36),i(37),i(7),i(38),i(8),i(14),i(20),i(39),i(21),i(40),i(41),i(42),i(15),i(43),i(6),i(1),i(44),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),s)},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(22),r=i(18),a=i(5);t.default=(e,t,i=!0)=>s(void 0,void 0,void 0,(function*(){const s=Object.assign({},t),c={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(c["X-Gizwits-User-token"]=r.getGlobalData("token")),s.header=Object.assign(Object.assign({},c),t.headers),delete s.headers;const o=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=yield n.default("https://"+o+e,s);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}))},function(e,t,i){var s,n,r,a,c,o;e.exports=(o=i(0),n=(s=o).lib,r=n.Base,a=n.WordArray,(c=s.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),c.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var n=e[s];i.push(n.high),i.push(n.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),o)},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),n=(s=d).lib,r=n.WordArray,a=n.Hasher,c=s.algo,o=[],l=c.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],l=0;l<80;l++){if(l<16)o[l]=0|e[t+l];else{var d=o[l-3]^o[l-8]^o[l-14]^o[l-16];o[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+c+o[l];u+=l<20?1518500249+(n&r|~n&a):l<40?1859775393+(n^r^a):l<60?(n&r|n&a|r&a)-1894007588:(n^r^a)-899497514,c=a,a=r,r=n<<30|n>>>2,n=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+c|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=a._createHelper(l),s.HmacSHA1=a._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,n,r,a;e.exports=(s=i(0),r=(n=s).lib.Base,a=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var n=this._oKey=t.clone(),r=this._iKey=t.clone(),c=n.words,o=r.words,l=0;l<i;l++)c[l]^=1549556828,o[l]^=909522486;n.sigBytes=r.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>s(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>s(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,s=yield n.default(`${i}`,{method:"GET"});if(!s.success||!(null===(t=s.data)||void 0===t?void 0:t.entities))return null;this.data[e]=s.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>s(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const s=this.data[e].entities[0].attrs[i];if(s.name===t)return s}return null}))}};r.init(),t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(31);const s=i(32),n=i(5);t.errorCode=n.default;const r=i(19);t.BleHandle=r.BleHandle,t.default=s.default},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))},n=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(10),a=i(23),c=i(24),o=i(2),l=i(4),d=i(25),u=i(60),h=i(26),f=i(3),p=i(27),v=i(9);class g extends p.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.boradcastDataCache={},this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{f.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>{const s=this.connectedList.find(e=>i.bleDeviceID==e.deviceId),n=this.connectingDevId===i.bleDeviceID;return!(!s&&!n)||("BLE_BROADCAST"===i.connectType?t-i.ctime<2*e:t-i.ctime<e)});i.length!==this.scanList.length&&(this.scanList=i,this.notifyDevices())},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{f.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>s(this,void 0,void 0,(function*(){if(!e.value)return;const t=r.ab2hex(e.value);try{const i=new l.default(o.hexStrint2byte(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>s(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,f.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){f.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>s(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){f.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>s(this,void 0,void 0,(function*(){f.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,s=n(e,["errMsg","available"]);return{data:Object.assign({},s),err:r.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,n)=>s(this,void 0,void 0,(function*(){const s=yield u.default.pack(t,i,n);return s?yield this.write(e,r.numberArray2Uint8Array(s).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{r.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:s,name:n,localName:a}=e,c=r.ab2hex(i);let o=null;try{o=r.parseBroadcastData(r.ab2numbers(i))}catch(e){}const l=this.scanList.find(e=>e.bleDeviceID===s);if(o&&148===o.cmd){const t=r.ab2hex(i);if(this.boradcastDataCache[s]&&this.boradcastDataCache[s]===t)return!1;if(!l)return!1;this.boradcastDataCache[s]=r.ab2hex(i);const n=h.padBoradcastData(o.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,n)}if(o&&25===o.cmd){this.pks.find(e=>e===o.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(l){const i=r.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,l);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>c.includes(e))){const i=r.BTDevice2GDevice(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3)=>s(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(i=>s(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),f.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:[],powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},t)})))})),this.stopScan=()=>s(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>s(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield v.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>s(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield a.retryConnect(e);this.enableScan(),f.default.debug("connect res",t)}catch(e){if(f.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),s=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!s)return{message:"can not find valid serviceId",success:!1};const n=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:s}).catch(e=>this.notifyError(e)),o=null==n?void 0:n.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:s,characteristicId:o}),yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:s,characteristicId:o,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),this.write(e,r.numberArray2Uint8Array(c.default.pack()).buffer);const l=yield this.handleBindReq(e);if(f.default.log("handleBindReq",l),l.success){this.write(e,r.numberArray2Uint8Array(d.default.pack({passcode:l.data})).buffer);const t=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==t?void 0:t.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}finally{this.connectingDevId=null}})),this.handleBindReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;f.default.log("监听蓝牙特征值发生变化");const r=new c.default(o.hexStrint2byte(n));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;f.default.log("设备回复LoginReq",n);const r=new d.default(o.hexStrint2byte(n));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.watchBleDevice=(e,t)=>s(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:s,errMsg:n}=this.getTargetDevice(e);return n?{success:!1,message:n}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),f.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=r.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{f.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{f.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),f.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return f.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){f.default.log("app => dev:",r.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield a.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>s(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:p}=t;this.serviceUUIDSuffix=p,this.pks=e,this.listenDevOffline(null!=i?i:1e4),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}}t.BleHandle=g},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,c=[],o=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,n=0;n<64;)t(s)&&(n<8&&(c[n]=i(e.pow(s,.5))),o[n]=i(e.pow(s,1/3)),n++),s++}();var l=[],d=a.SHA256=r.extend({_doReset:function(){this._hash=new n.init(c.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var _=s&n^s&r^n&r,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&d^~c&u)+o[f]+l[f];h=u,u=d,d=c,c=a+m|0,a=r,r=n,n=s,s=m+(D+_)|0}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+c|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;return i[n>>>5]|=128<<24-n%32,i[14+(n+64>>>9<<4)]=e.floor(s/4294967296),i[15+(n+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(d),t.HmacSHA256=r._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(){var e=s,t=e.lib.Hasher,i=e.x64,n=i.Word,r=i.WordArray,a=e.algo;function c(){return n.create.apply(n,arguments)}var o=[c(1116352408,3609767458),c(1899447441,602891725),c(3049323471,3964484399),c(3921009573,2173295548),c(961987163,4081628472),c(1508970993,3053834265),c(2453635748,2937671579),c(2870763221,3664609560),c(3624381080,2734883394),c(310598401,1164996542),c(607225278,1323610764),c(1426881987,3590304994),c(1925078388,4068182383),c(2162078206,991336113),c(2614888103,633803317),c(3248222580,3479774868),c(3835390401,2666613458),c(4022224774,944711139),c(264347078,2341262773),c(604807628,2007800933),c(770255983,1495990901),c(1249150122,1856431235),c(1555081692,3175218132),c(1996064986,2198950837),c(2554220882,3999719339),c(2821834349,766784016),c(2952996808,2566594879),c(3210313671,3203337956),c(3336571891,1034457026),c(3584528711,2466948901),c(113926993,3758326383),c(338241895,168717936),c(666307205,1188179964),c(773529912,1546045734),c(1294757372,1522805485),c(1396182291,2643833823),c(1695183700,2343527390),c(1986661051,1014477480),c(2177026350,1206759142),c(2456956037,344077627),c(2730485921,1290863460),c(2820302411,3158454273),c(3259730800,3505952657),c(3345764771,106217008),c(3516065817,3606008344),c(3600352804,1432725776),c(4094571909,1467031594),c(275423344,851169720),c(430227734,3100823752),c(506948616,1363258195),c(659060556,3750685593),c(883997877,3785050280),c(958139571,3318307427),c(1322822218,3812723403),c(1537002063,2003034995),c(1747873779,3602036899),c(1955562222,1575990012),c(2024104815,1125592928),c(2227730452,2716904306),c(2361852424,442776044),c(2428436474,593698344),c(2756734187,3733110249),c(3204031479,2999351573),c(3329325298,3815920427),c(3391569614,3928383900),c(3515267271,566280711),c(3940187606,3454069534),c(4118630271,4000239992),c(116418474,1914138554),c(174292421,2731055270),c(289380356,3203993006),c(460393269,320620315),c(685471733,587496836),c(852142971,1086792851),c(1017036298,365543100),c(1126000580,2618297676),c(1288033470,3409855158),c(1501505948,4234509866),c(1607167915,987167468),c(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=c()}();var d=a.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,v=n.high,g=n.low,y=r.high,_=r.low,D=a.high,m=a.low,S=c.high,b=c.low,w=d.high,k=d.low,B=u.high,I=u.low,C=h.high,A=h.low,x=f,E=p,L=v,T=g,O=y,P=_,H=D,M=m,K=S,N=b,G=w,R=k,U=B,z=I,j=C,W=A,Z=0;Z<80;Z++){var F,V,$=l[Z];if(Z<16)V=$.high=0|e[t+2*Z],F=$.low=0|e[t+2*Z+1];else{var X=l[Z-15],J=X.high,q=X.low,Y=(J>>>1|q<<31)^(J>>>8|q<<24)^J>>>7,Q=(q>>>1|J<<31)^(q>>>8|J<<24)^(q>>>7|J<<25),ee=l[Z-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,ne=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[Z-7],ae=re.high,ce=re.low,oe=l[Z-16],le=oe.high,de=oe.low;V=(V=(V=Y+ae+((F=Q+ce)>>>0<Q>>>0?1:0))+se+((F+=ne)>>>0<ne>>>0?1:0))+le+((F+=de)>>>0<de>>>0?1:0),$.high=V,$.low=F}var ue,he=K&G^~K&U,fe=N&R^~N&z,pe=x&L^x&O^L&O,ve=E&T^E&P^T&P,ge=(x>>>28|E<<4)^(x<<30|E>>>2)^(x<<25|E>>>7),ye=(E>>>28|x<<4)^(E<<30|x>>>2)^(E<<25|x>>>7),_e=(K>>>14|N<<18)^(K>>>18|N<<14)^(K<<23|N>>>9),De=(N>>>14|K<<18)^(N>>>18|K<<14)^(N<<23|K>>>9),me=o[Z],Se=me.high,be=me.low,we=j+_e+((ue=W+De)>>>0<W>>>0?1:0),ke=ye+ve;j=U,W=z,U=G,z=R,G=K,R=N,K=H+(we=(we=(we=we+he+((ue+=fe)>>>0<fe>>>0?1:0))+Se+((ue+=be)>>>0<be>>>0?1:0))+V+((ue+=F)>>>0<F>>>0?1:0))+((N=M+ue|0)>>>0<M>>>0?1:0)|0,H=O,M=P,O=L,P=T,L=x,T=E,x=we+(ge+pe+(ke>>>0<ye>>>0?1:0))+((E=ue+ke|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+E,s.high=f+x+(p>>>0<E>>>0?1:0),g=n.low=g+T,n.high=v+L+(g>>>0<T>>>0?1:0),_=r.low=_+P,r.high=y+O+(_>>>0<P>>>0?1:0),m=a.low=m+M,a.high=D+H+(m>>>0<M>>>0?1:0),b=c.low=b+N,c.high=S+K+(b>>>0<N>>>0?1:0),k=d.low=k+R,d.high=w+G+(k>>>0<R>>>0?1:0),I=u.low=I+z,u.high=B+U+(I>>>0<z>>>0?1:0),A=h.low=A+W,h.high=C+j+(A>>>0<W>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(3),r=i(9);function a(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})}function c(e,t,i,s){return new Promise(n=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:n})})}t.retryConnect=function(e,t=1e4){return s(this,void 0,void 0,(function*(){let i={success:!1};for(let s=0;s<5;s++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield r.default(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((n,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:n,fail:r})})},t.writeBLECharacteristicValue=c,t.unpackWriteBLECharacteristicValue=function(e,t,i,a){if(!a||0===a.byteLength)throw new Error("value is empty");return new Promise((o,l)=>s(this,void 0,void 0,(function*(){let s,d=0,u=a.byteLength;for(;u>0;){yield r.default(30);const o=a.slice(d,d+20);if(d+=20,u-=20,s=yield c(e,t,i,o),n.default.log("unpackWriteBLECharacteristicValue",d/20,s),0!==s.errCode)break}0!==s.errCode?l(s):o(s)})))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(n.arrayToString(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}r.pack=()=>[0,0,0,3,3,0,0,6],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}r.pack=({passcode:e})=>{let t=[0];const i=n.hexStrint2byte(n.fillString(e.length.toString(16),4)),s=n.string2Bytes(e),r=[0].concat([0,8]).concat(i).concat(s);return t=n.hexStrint2byte(r.length.toString(16)),[0,0,0,3].concat(t).concat(r)},t.default=r},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(16),r=i(2),a=e=>-1!==e.indexOf("uint")?"number":e,c=(e,t,i)=>{let s="";switch(e){case"bool":s=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const n=i.enum.findIndex(t=>e===t),a=-1===n?0:n;s=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),s=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const n=r.fillString(e,2*i.position.len,!0);for(let e=0;e<n.length/2;e++){const t=2*e,i=n[t]+n[t+1];s+=r.fillString(parseInt(i,16).toString(2),8)}break}}const n=i.position.len*("byte"===i.position.unit?8:1)-s.length;if(n>0)for(let e=0;e<n;e++)s=`0${s}`;return`${s}`},o=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let s="";for(let e=0;e<t.length/8;e++){const i=8*e,n=t.substring(i,i+8);s+=r.fillString(parseInt(n,2).toString(16),2)}return r.fillString(s,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let s=e;const n=[0,0,0,3],o=[0],l=[0,147],u=[0,0,0,0];let h=[1],f="";const p=[];i||(s=s.filter(e=>"status_writable"===e.type)),s.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],s=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=s[0]}catch(e){}s.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const s=a(e.data_type);return i=c(s,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const s=a(e.data_type),n=c(s,t,e);return i=i.concat(r.completeBlock(n))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=o.concat(l).concat(u).concat(h),_=d(y);return n.push(..._),{data:n.concat(y),raw:{header:[0,0,0,3],flag:o,len:_,headerCmd:l,sn:u,cmd:h}}};function d(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const s=e-7,n=e;let r=t.substring(s,n);r=`${s>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function u(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:s,accumulate:n}){let r=0,a={},c=0;return["status_writable","status_readonly","alert","fault"].map(o=>{const l=e.filter(e=>u(o,e.type)).length,{cmd:d,cmdDataLength:h}=f({type:o,attrs:e.slice(c,c+l),activeAttrs:t,flagString:i.substring(c,c+l),cmdData:s.slice(r,s.length),accumulate:n});return r+=h,a=Object.assign(Object.assign({},a),d),c+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:s,flagString:n,accumulate:c}){let l=0,d=0,h=0;return i.map(t=>{if(u(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?d+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(d/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:s,accumulate:n}){const c={};let l=0;for(let d=0;d<t.length;d++)if(e[d]&&"1"===t[d]){const{data_type:t,position:{len:n}}=e[d];let u="";if("bool"===t||"enum"===t){let e="";s.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;u=e.substring(t-n,t),l+=n}else{const e=i,t=i+n;s.slice(e,t).map(e=>(u+=r.fillString(e.toString(2),8),null)),i+=n}const h=a(t);c[e[d].name]=o(h,u,e[d])}else if(n){const t=e[d]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return c}({attrs:t,flagString:n,boolEnumLength:Math.ceil(d/8),cmdData:s,accumulate:c})}}t.unpack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield n.default.getConfigFile(t);if(i){const s=function({config:e=[],data:t}){let i,s,n="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},c=e;let o=r.checkHeader(t);if(!1===o)return;const l=t.slice(o,t.length),d=r.getProtocolLen(l);if(o+=d,a.len=r.arrayToString(l.slice(0,d)),o+=1,a.flag=r.arrayToString(t.slice(o-1,o)),o+=2,a.cmd=r.arrayToString(t.slice(o-2,o)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(o+=4,a.sn=r.arrayToString(t.slice(o-4,o)),"01"===a.flag)){o+=2,o+=parseInt(r.arrayToString(t.slice(o-2,o)),16)}o+=1,a.action=r.arrayToString(t.slice(o-1,o)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(o,t.length));const u=t.slice(o,t.length);let p=c;1===i&&(p=c.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=u.slice(0,g),_=u.slice(g,u.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=u);let D="";y.map(e=>(D+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===a.cmd||"0093"===a.cmd?(n="App 透传数据到 Dev",s="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(n="Dev 收到控制命令后应答到 App",s="DEV2APP"):(n="非法数据",s="UNKNOW");let m={};switch(i){case 1:n="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return n="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 3:n="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:n="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return n="App 透传数据到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 6:return n="Dev 透传数据到 App",{kvData:null,rawData:a,message:n,messageType:s};case 7:return n="App 下发控制子设备",{kvData:null,rawData:a,message:n,messageType:s};case 8:return n="App 读取子设备数据",{kvData:null,rawData:a,message:n,messageType:s};case 9:return n="Dev 中控回复ACK",{kvData:null,rawData:a,message:n,messageType:s};case 10:return n="子设备上报状态到 App",{kvData:null,rawData:a,message:n,messageType:s};case 11:return n="App 下发添加子设备指令",{kvData:null,rawData:a,message:n,messageType:s};case 12:return n="App 下发删除子设备",{kvData:null,rawData:a,message:n,messageType:s};case 13:return n="App 获取中控子设备列表",{kvData:null,rawData:a,message:n,messageType:s};case 14:return n="中控响应字设备查询到 App",{kvData:null,rawData:a,message:n,messageType:s};case 15:return n="子设备列表变更通知到 App",{kvData:null,rawData:a,message:n,messageType:s};case 16:return n="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:n,messageType:s};case 17:n="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return n="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 19:n="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:n="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return n="App 向网关发送数据",{kvData:null,rawData:a,message:n,messageType:s};case 115:return n="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:n,messageType:s};case 116:return n="App 通知网关删除子设备",{kvData:null,rawData:a,message:n,messageType:s};default:return{kvData:null,rawData:a,message:n,messageType:s}}return 0===c.length?{kvData:null,rawData:a,message:n,messageType:s}:{kvData:m,rawData:a,message:n,messageType:s}}({config:(yield i).entities[0].attrs,data:e});return s.kvData&&(s.kvData=yield p(null==s?void 0:s.kvData,t,"object")),s}return null}));t.pack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield n.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=d(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const r=yield n.default.getAttrItem(t,s);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[s]){const t=r.enum.findIndex(t=>t===e[s]);e[s]=t||0}"string"===i&&"number"==typeof e[s]&&(e[s]=r.enum[e[s]])}}return e}));const p=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const a=yield n.default.getAttrItem(t,s);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[s]&&(e[s]=r.hexStrint2byte(e[s])),"string"===i&&"object"==typeof e[s]&&(e[s]=r.arrayToString(e[s])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e)}}r.pack=(e,t)=>{const i=[],[s,r]=n.formatCodesFromStr(e),[a,c]=n.formatCodesFromStr(t),o=[0].concat([0,1],r,s,c,a);let l=o.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(o),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=r},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(9),r=i(5),a=i(30),c=i(3);t.default=class{constructor(e,t,i,o){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,o)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>s(this,void 0,void 0,(function*(){var s;if(this.hasTimeoutHandler())try{const d=yield a.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(s=d.err)||void 0===s?void 0:s.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void o({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});d.err||0===d.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield n.default(1500),!this.disableSearchDevice&&l()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",d),i({success:!0,data:d.data}))}catch(e){yield n.default(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(c.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>s(this,void 0,void 0,(function*(){const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return a.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=yield Promise.all(s),a=e.filter((e,t)=>{const i=n[t];return i&&i.success});a.length>0?(c.default.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(c.default.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=o}}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12),r=i(63),a=i(64),c=i(11);t.getBindingList=()=>s(void 0,void 0,void 0,(function*(){const e=yield n.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:c}){return s(this,void 0,void 0,(function*(){const s={mac:e,product_key:t,dev_alias:r,set_owner:c},{Signature:o,timestamp:l}=a.psKeySign(i);return yield n.default("/app/bind_mac",{method:"POST",data:s,headers:{"X-Gizwits-Signature":o,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return s(this,void 0,void 0,(function*(){return yield n.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return s(this,void 0,void 0,(function*(){const s=r.default({SSID:e,password:t,pks:i});let a="";return s.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),yield n.default(`/app/device_register?random_codes=${a}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:a,isReset:o}){return s(this,void 0,void 0,(function*(){let s=`is_reset=${o?1:0}&mac=${i}&passcode=${r}`;a&&(s+=`&gw_did=${a}`);const l=c.enc.Hex.parse(t),d=c.enc.Hex.parse(""),u=c.enc.Utf8.parse(s),h=c.AES.encrypt(u,l,{iv:d,mode:c.mode.ECB,padding:c.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=yield n.default(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}))},t.editBindInfo=function({name:e,remark:t,did:i}){return s(this,void 0,void 0,(function*(){const s={};return e&&(s.dev_alias=e),t&&(s.remark=t),yield n.default(`/app/bindings/${i}`,{method:"PUT",data:s},!0)}))}},function(e,t){},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(18),r=i(19),a=i(61),c=i(62),o=i(65),l=i(3),d=i(17),u=i(66),h=i(30),f=i(10),p=i(16),v=i(26),g=i(2),y=i(67),_=i(4),D=i(69),m=i(70),S=i(9),b=i(71);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:a,uid:y,offlineThreshold:w}){this.version="3.1.11-1",this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{l.default.log("handleBleDevices",e),this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield v.unpack(g.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=g.hexStrint2byte(t);switch(new _.default(s).cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);e&&m.uploadP0({device:i,data:[{raw:t,created_at:parseInt(`${Date.now()/1e3}`,10)}],productSecret:e.productSecret}).then(e=>{console.debug("uploadP0 res",e)})}const e=yield v.unpack(g.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0052":{const t=new D.RequestSync(s);if(l.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),l.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.SyncPackage.pack(0)).buffer)):(l.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;l.default.debug("设备上报离线数据");const t=new D.SyncPackage(s),i=D.DeletePackage.pack(t.id);l.default.debug("设备上报离线数据:payload",t.payload),l.default.debug("设备上报离线数据:timestemp",t.timestemp);const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield m.uploadP0({device:this.syncDevice,data:[{raw:g.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});l.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),l.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(l.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.SyncPackage.pack(t.id+1)).buffer)):(l.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new D.CancelSync(s);l.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield v.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);l.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){l.default.error("init lan error",e)}},this.startAutoScan=()=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>s(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,s=!1)=>{const n=this.allDevices.find(t=>t.mac===e.mac);n&&0!==this.allDevices.length&&(e[t]!==i||s)&&(n[t]=i,this.notiDeviceList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=()=>s(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),l.default.debug("init BLE succcess",e),{success:!0}):(l.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:d.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=e=>s(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e)).scanList}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:s}=yield v.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,s.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,f.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield v.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,f.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,f.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,f.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=b.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{l.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=D.RequestSync.pack();return l.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=D.RequestSync.pack();return this.syncDevice=Object.assign({},t),l.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>s(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>s(this,void 0,void 0,(function*(){const t=yield p.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>s(this,void 0,void 0,(function*(){var t,i;const s=yield u.AnonymousLogin({uid:e});return s.success&&(n.setGlobalData("token",null===(t=s.data)||void 0===t?void 0:t.token),n.setGlobalData("uid",null===(i=s.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:s.data.token,uid:s.data.uid})),s})),this.getDeviceStatus=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>s(this,void 0,void 0,(function*(){l.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return l.default.warn("Device Target Not Found"),l.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const s=f.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==s&&(yield this.unSubscribe(i)),s){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:n})=>s(this,void 0,void 0,(function*(){const s=f.getProductInfoThroughPK(t,this.productInfo);if(s){const r=yield h.bindMac({mac:e,productKey:t,productSecret:s.productSecret,alias:i,beOwner:n});return this.getBindingList(),r}return{success:!1,err:d.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.unbindDevice=({devices:e})=>s(this,void 0,void 0,(function*(){const t=yield h.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:n,isBind:r=!0,softAPSSIDPrefix:a})=>s(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:d.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const s=(new Date).getTime();l.default.debug("GIZ_SDK: 配网开始时间:"+s);try{switch(i){case 0:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+o),l.default.debug("GIZ_SDK: 配网用时:"+(o-s)),i}case 3:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const c=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+c),l.default.debug("GIZ_SDK: 配网用时:"+(c-s)),i}}}catch(e){return l.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:d.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});n.setGlobalData("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>s(this,void 0,void 0,(function*(){const s=f.getProductInfoThroughPK(t,this.productInfo);return s?yield h.safeRegister({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:d.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>s(this,void 0,void 0,(function*(){const e=yield h.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>s(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>l.default.setLogLevel(e),this.renameDevice=(e,t)=>s(this,void 0,void 0,(function*(){return t?e.isBind?yield h.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.productInfo=i,n.setGlobalData("appID",e),n.setGlobalData("appSecret",t),n.setGlobalData("productInfo",i),n.setGlobalData("token",a),n.setGlobalData("uid",y),this.setDomain(r),this.offlineThreshold=w,l.default.debug(`init sdk success, current version: ${this.version}`),this.initLan()}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=f.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=f.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const s=t[i];s&&s._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new y.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new a.default({appID:n.getGlobalData("appID"),token:n.getGlobalData("token"),uid:n.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),n=i(22);t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:s.MD5(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var r={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};n.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",r)}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],n=0;n<i;n++)s[n>>>2]|=e[n]<<24-n%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function n(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var r=t[n>>>2]>>>16-n%4*8&65535;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=e.charCodeAt(n)<<16-n%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var a=n(t[r>>>2]>>>16-r%4*8&65535);s.push(String.fromCharCode(a))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=n(e.charCodeAt(r)<<16-r%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,n=t?this._safe_map:this._map;e.clamp();for(var r=[],a=0;a<s;a+=3)for(var c=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,o=0;o<4&&a+.75*o<s;o++)r.push(n.charAt(c>>>6*(3-o)&63));var l=n.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var a=0;a<s.length;a++)r[s.charCodeAt(a)]=a}var c=s.charAt(64);if(c){var o=e.indexOf(c);-1!==o&&(i=o)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var c=i[e.charCodeAt(a-1)]<<a%4*2,o=i[e.charCodeAt(a)]>>>6-a%4*2,l=c|o;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var s,n,r,a,c,o;e.exports=(o=i(0),i(20),n=(s=o).lib.WordArray,r=s.algo,a=r.SHA256,c=r.SHA224=a.extend({_doReset:function(){this._hash=new n.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=a._createHelper(c),s.HmacSHA224=a._createHmacHelper(c),o.SHA224)},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),i(13),i(21),n=(s=d).x64,r=n.Word,a=n.WordArray,c=s.algo,o=c.SHA512,l=c.SHA384=o.extend({_doReset:function(){this._hash=new a.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=o._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=o._createHelper(l),s.HmacSHA384=o._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.x64.Word,c=t.algo,o=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){o[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var n=1,r=0;r<24;r++){for(var c=0,u=0,h=0;h<7;h++){if(1&n){var f=(1<<h)-1;f<32?u^=1<<f:c^=1<<f-32}128&n?n=n<<1^113:n<<=1}d[r]=a.create(c,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=a.create()}();var h=c.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,n=0;n<s;n++){var r=e[t+2*n],a=e[t+2*n+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(A=i[n]).high^=a,A.low^=r}for(var c=0;c<24;c++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(A=i[h+5*v]).high,p^=A.low;var g=u[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=u[(h+4)%5],_=u[(h+1)%5],D=_.high,m=_.low;for(f=y.high^(D<<1|m>>>31),p=y.low^(m<<1|D>>>31),v=0;v<5;v++)(A=i[h+5*v]).high^=f,A.low^=p}for(var S=1;S<25;S++){var b=(A=i[S]).high,w=A.low,k=o[S];k<32?(f=b<<k|w>>>32-k,p=w<<k|b>>>32-k):(f=w<<k-32|b>>>64-k,p=b<<k-32|w>>>64-k);var B=u[l[S]];B.high=f,B.low=p}var I=u[0],C=i[0];for(I.high=C.high,I.low=C.low,h=0;h<5;h++)for(v=0;v<5;v++){var A=i[S=h+5*v],x=u[S],E=u[(h+1)%5+5*v],L=u[(h+2)%5+5*v];A.high=x.high^~E.high&L.high,A.low=x.low^~E.low&L.low}A=i[0];var T=d[c];A.high^=T.high,A.low^=T.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,c=this.cfg.outputLength/8,o=c/8,l=[],d=0;d<o;d++){var u=a[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new n.init(l,c)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
1
+ module.exports=function(e){var t={};function i(s){if(t[s])return t[s].exports;var n=t[s]={i:s,l:!1,exports:{}};return e[s].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=e,i.c=t,i.d=function(e,t,s){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(i.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)i.d(s,n,function(t){return e[t]}.bind(null,n));return s},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=17)}([function(e,t,i){(function(t){var s;e.exports=(s=s||function(e,s){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==t&&t.crypto&&(n=t.crypto),!n)try{n=i(35)}catch(e){}var r=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},a=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),c={},o=c.lib={},l=o.Base={extend:function(e){var t=a(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},d=o.WordArray=l.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||h).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,n=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<n;r++){var a=i[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=a<<24-(s+r)%4*8}else for(var c=0;c<n;c+=4)t[s+c>>>2]=i[c>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=l.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],i=0;i<e;i+=4)t.push(r());return new d.init(t,e)}}),u=c.enc={},h=u.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new d.init(i,t/2)}},f=u.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new d.init(i,t)}},p=u.Utf8={stringify:function(e){try{return decodeURIComponent(escape(f.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return f.parse(unescape(encodeURIComponent(e)))}},v=o.BufferedBlockAlgorithm=l.extend({reset:function(){this._data=new d.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=p.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,n=s.words,r=s.sigBytes,a=this.blockSize,c=r/(4*a),o=(c=t?e.ceil(c):e.max((0|c)-this._minBufferSize,0))*a,l=e.min(4*o,r);if(o){for(var u=0;u<o;u+=a)this._doProcessBlock(n,u);i=n.splice(0,o),s.sigBytes-=l}return new d.init(i,l)},clone:function(){var e=l.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),g=(o.Hasher=v.extend({cfg:l.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){v.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new g.HMAC.init(e,i).finalize(t)}}}),c.algo={});return c}(Math),s)}).call(this,i(34))},function(e,t,i){var s,n,r,a,c,o,l,d,u,h,f,p,v,g,y,_,D,m,S;e.exports=(s=i(0),i(6),void(s.lib.Cipher||(n=s,r=n.lib,a=r.Base,c=r.WordArray,o=r.BufferedBlockAlgorithm,l=n.enc,l.Utf8,d=l.Base64,u=n.algo.EvpKDF,h=r.Cipher=o.extend({cfg:a.extend(),createEncryptor:function(e,t){return this.create(this._ENC_XFORM_MODE,e,t)},createDecryptor:function(e,t){return this.create(this._DEC_XFORM_MODE,e,t)},init:function(e,t,i){this.cfg=this.cfg.extend(i),this._xformMode=e,this._key=t,this.reset()},reset:function(){o.reset.call(this),this._doReset()},process:function(e){return this._append(e),this._process()},finalize:function(e){return e&&this._append(e),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function e(e){return"string"==typeof e?S:D}return function(t){return{encrypt:function(i,s,n){return e(s).encrypt(t,i,s,n)},decrypt:function(i,s,n){return e(s).decrypt(t,i,s,n)}}}}()}),r.StreamCipher=h.extend({_doFinalize:function(){return this._process(!0)},blockSize:1}),f=n.mode={},p=r.BlockCipherMode=a.extend({createEncryptor:function(e,t){return this.Encryptor.create(e,t)},createDecryptor:function(e,t){return this.Decryptor.create(e,t)},init:function(e,t){this._cipher=e,this._iv=t}}),v=f.CBC=function(){var e=p.extend();function t(e,t,i){var s,n=this._iv;n?(s=n,this._iv=void 0):s=this._prevBlock;for(var r=0;r<i;r++)e[t+r]^=s[r]}return e.Encryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize;t.call(this,e,i,n),s.encryptBlock(e,i),this._prevBlock=e.slice(i,i+n)}}),e.Decryptor=e.extend({processBlock:function(e,i){var s=this._cipher,n=s.blockSize,r=e.slice(i,i+n);s.decryptBlock(e,i),t.call(this,e,i,n),this._prevBlock=r}}),e}(),g=(n.pad={}).Pkcs7={pad:function(e,t){for(var i=4*t,s=i-e.sigBytes%i,n=s<<24|s<<16|s<<8|s,r=[],a=0;a<s;a+=4)r.push(n);var o=c.create(r,s);e.concat(o)},unpad:function(e){var t=255&e.words[e.sigBytes-1>>>2];e.sigBytes-=t}},r.BlockCipher=h.extend({cfg:h.cfg.extend({mode:v,padding:g}),reset:function(){var e;h.reset.call(this);var t=this.cfg,i=t.iv,s=t.mode;this._xformMode==this._ENC_XFORM_MODE?e=s.createEncryptor:(e=s.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==e?this._mode.init(this,i&&i.words):(this._mode=e.call(s,this,i&&i.words),this._mode.__creator=e)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e,t=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(t.pad(this._data,this.blockSize),e=this._process(!0)):(e=this._process(!0),t.unpad(e)),e},blockSize:4}),y=r.CipherParams=a.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),_=(n.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext,i=e.salt;return(i?c.create([1398893684,1701076831]).concat(i).concat(t):t).toString(d)},parse:function(e){var t,i=d.parse(e),s=i.words;return 1398893684==s[0]&&1701076831==s[1]&&(t=c.create(s.slice(2,4)),s.splice(0,4),i.sigBytes-=16),y.create({ciphertext:i,salt:t})}},D=r.SerializableCipher=a.extend({cfg:a.extend({format:_}),encrypt:function(e,t,i,s){s=this.cfg.extend(s);var n=e.createEncryptor(i,s),r=n.finalize(t),a=n.cfg;return y.create({ciphertext:r,key:i,iv:a.iv,algorithm:e,mode:a.mode,padding:a.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,i,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(i,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}}),m=(n.kdf={}).OpenSSL={execute:function(e,t,i,s){s||(s=c.random(8));var n=u.create({keySize:t+i}).compute(e,s),r=c.create(n.words.slice(t),4*i);return n.sigBytes=4*t,y.create({key:n,iv:r,salt:s})}},S=r.PasswordBasedCipher=D.extend({cfg:D.cfg.extend({kdf:m}),encrypt:function(e,t,i,s){var n=(s=this.cfg.extend(s)).kdf.execute(i,e.keySize,e.ivSize);s.iv=n.iv;var r=D.encrypt.call(this,e,t,n.key,s);return r.mixIn(n),r},decrypt:function(e,t,i,s){s=this.cfg.extend(s),t=this._parse(t,s.format);var n=s.kdf.execute(i,e.keySize,e.ivSize,t.salt);return s.iv=n.iv,D.decrypt.call(this,e,t,n.key,s)}}))))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.checkHeader=e=>{let t=0;return 0===e[0]&&0===e[1]&&0===e[2]&&3===e[3]&&(t=4,4)},t.completeBlock=e=>{const t=s(e,8*Math.ceil(e.length/8)),i=[];for(let e=0;e<t.length;e+=8)i.push(parseInt(t.substring(e,e+8),2));return i};t.getProtocolLen=e=>{let t=0;for(;t<e.length&&"1"===s(e[t].toString(2),8)[0];t++);return t+1},t.arrayToString=function(e){let t="";return e.map(e=>(t+=s(e.toString(16),2),null)),t};const s=(e,t,i=!1)=>{const s=t-e.length,n=new Array(s).fill(0).join("");return i?e+=n:e=n+e,e};t.fillString=s;t.string2Bytes=e=>{const t=[];for(let i=0;i<e.length;i++)t.push(e.charCodeAt(i));return t};t.hexStrint2byte=e=>{const t=Math.ceil(e.length/2),i=[];for(let s=0;s<t;s++){const t=2*s,n=t+2,r=e.substring(t,n);i.push(parseInt(r,16))}return i};const n=e=>{const t=encodeURI(e);return-1!==t.indexOf("%")&&"%"!==e?t.split("%").filter(e=>""!==e).map(e=>parseInt(e,16)):[t.charCodeAt(0)]};t.formatCode=n;t.formatCodesFromStr=e=>{const t=[0,0];let i=[];for(let s=0;s<e.length;s++){const r=n(e[s]);t[1]+=r.length,i=i.concat(r)}return[i,t]};t.arrayToUint8=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(5),n=i(33);t.default=new class{constructor(){this.logMap=[{id:"debug"},{id:"info"},{id:"warn"},{id:"error"}],this.console=console,this.debug=(...e)=>{this.console.debug(...e)},this.info=(...e)=>{this.console.info(...e)},this.log=(...e)=>{this.console.log(...e)},this.warn=(...e)=>{this.console.warn(...e)},this.error=(e,t)=>{this.console.error(e,t),n.default(t)},this.setLogLevel=e=>{const t=this.logMap.findIndex(t=>t.id===e);return-1!==t?(this.console=Object.assign({},console),this.logMap.map((e,i)=>{i<t&&(this.console[e.id]=()=>{})}),{success:!0,err:null}):{success:!1,err:s.default.GIZ_SDK_LOG_LEVEL_INVALID}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(2);class n{constructor(e){this.header="",this.len=0,this.flag=[0],this.cmd="",this.content=[],this.formatP0=e=>{let t=s.checkHeader(e);if(!1===t)throw new Error("Header Error");this.header=s.arrayToString(e.slice(0,t));const i=e.slice(t,e.length),r=s.getProtocolLen(i);this.len=n.decodeLen(i.slice(0,r)),t+=r,this.flag=e.slice(t,t+1),t+=1,this.cmd=s.arrayToString(e.slice(t,t+2)),t+=2,this.content=e.slice(t,e.length)},e&&e.length>0&&this.formatP0(e)}}n.decodeLen=e=>{let t=1,i=0,s=0,n=0;do{s=e[n],i+=(127&s)*t,t*=128,n+=1}while(0!=(128&s));return i},t.default=n},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default={GIZ_OPENAPI_DEVICE_NOT_BOUND:{errorCode:9017,errorMessage:"not bind"},GIZ_SDK_HTTP_REQUEST_FAILED:{errorCode:8099,errorMessage:"网络请求失败"},GIZ_SDK_SDK_NOT_INITIALIZED:{errorCode:8300,errorMessage:"not init"},CONFIG_TIME_OUT:{errorCode:8023,errorMessage:"Config Timeout"},WECHAT_ERROR:{errorCode:1e4,errorMessage:"wechat error"},GIZ_SDK_ONBOARDING_STOPPED:{errorCode:8318,errorMessage:"配网中断"},GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:{errorCode:8022,errorMessage:"配置正在进行中"},GIZ_OPENAPI_TOKEN_INVALID:{errorCode:9004,errorMessage:"token 失效"},GIZ_SDK_BIND_DEVICE_FAILED:{errorCode:8039,errorMessage:"设备绑定失败"},GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON:{errorCode:8281,errorMessage:"蓝牙未启用"},GIZ_SDK_OTHERWISE:{errorCode:8100,errorMessage:""},GIZ_SDK_DEVICE_NOT_SUBSCRIBED:{errorCode:8029,errorMessage:"设备还未订阅"},GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY:{errorCode:8250,errorMessage:"产品类型不在指定范围内"},GIZ_SDK_LOG_LEVEL_INVALID:{errorCode:8009,errorMessage:"产品类型不在指定范围内"}}},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),i(14),i(15),n=(s=d).lib,r=n.Base,a=n.WordArray,c=s.algo,o=c.MD5,l=c.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:o,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var i,s=this.cfg,n=s.hasher.create(),r=a.create(),c=r.words,o=s.keySize,l=s.iterations;c.length<o;){i&&n.update(i),i=n.update(e).finalize(t),n.reset();for(var d=1;d<l;d++)i=n.finalize(i),n.reset();r.concat(i)}return r.sigBytes=4*o,r}}),s.EvpKDF=function(e,t,i){return l.create(i).compute(e,t)},d.EvpKDF)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64={stringify:function(e){var t=e.words,i=e.sigBytes,s=this._map;e.clamp();for(var n=[],r=0;r<i;r+=3)for(var a=(t[r>>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,c=0;c<4&&r+.75*c<i;c++)n.push(s.charAt(a>>>6*(3-c)&63));var o=s.charAt(64);if(o)for(;n.length%4;)n.push(o);return n.join("")},parse:function(e){var t=e.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var r=0;r<i.length;r++)s[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var c=e.indexOf(a);-1!==c&&(t=c)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var c=i[e.charCodeAt(a-1)]<<a%4*2,o=i[e.charCodeAt(a)]>>>6-a%4*2,l=c|o;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,t,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},r.enc.Base64)},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,c=[];!function(){for(var t=0;t<64;t++)c[t]=4294967296*e.abs(e.sin(t+1))|0}();var o=a.MD5=r.extend({_doReset:function(){this._hash=new n.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,t){for(var i=0;i<16;i++){var s=t+i,n=e[s];e[s]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8)}var r=this._hash.words,a=e[t+0],o=e[t+1],f=e[t+2],p=e[t+3],v=e[t+4],g=e[t+5],y=e[t+6],_=e[t+7],D=e[t+8],m=e[t+9],S=e[t+10],b=e[t+11],w=e[t+12],k=e[t+13],B=e[t+14],I=e[t+15],C=r[0],A=r[1],x=r[2],E=r[3];C=l(C,A,x,E,a,7,c[0]),E=l(E,C,A,x,o,12,c[1]),x=l(x,E,C,A,f,17,c[2]),A=l(A,x,E,C,p,22,c[3]),C=l(C,A,x,E,v,7,c[4]),E=l(E,C,A,x,g,12,c[5]),x=l(x,E,C,A,y,17,c[6]),A=l(A,x,E,C,_,22,c[7]),C=l(C,A,x,E,D,7,c[8]),E=l(E,C,A,x,m,12,c[9]),x=l(x,E,C,A,S,17,c[10]),A=l(A,x,E,C,b,22,c[11]),C=l(C,A,x,E,w,7,c[12]),E=l(E,C,A,x,k,12,c[13]),x=l(x,E,C,A,B,17,c[14]),C=d(C,A=l(A,x,E,C,I,22,c[15]),x,E,o,5,c[16]),E=d(E,C,A,x,y,9,c[17]),x=d(x,E,C,A,b,14,c[18]),A=d(A,x,E,C,a,20,c[19]),C=d(C,A,x,E,g,5,c[20]),E=d(E,C,A,x,S,9,c[21]),x=d(x,E,C,A,I,14,c[22]),A=d(A,x,E,C,v,20,c[23]),C=d(C,A,x,E,m,5,c[24]),E=d(E,C,A,x,B,9,c[25]),x=d(x,E,C,A,p,14,c[26]),A=d(A,x,E,C,D,20,c[27]),C=d(C,A,x,E,k,5,c[28]),E=d(E,C,A,x,f,9,c[29]),x=d(x,E,C,A,_,14,c[30]),C=u(C,A=d(A,x,E,C,w,20,c[31]),x,E,g,4,c[32]),E=u(E,C,A,x,D,11,c[33]),x=u(x,E,C,A,b,16,c[34]),A=u(A,x,E,C,B,23,c[35]),C=u(C,A,x,E,o,4,c[36]),E=u(E,C,A,x,v,11,c[37]),x=u(x,E,C,A,_,16,c[38]),A=u(A,x,E,C,S,23,c[39]),C=u(C,A,x,E,k,4,c[40]),E=u(E,C,A,x,a,11,c[41]),x=u(x,E,C,A,p,16,c[42]),A=u(A,x,E,C,y,23,c[43]),C=u(C,A,x,E,m,4,c[44]),E=u(E,C,A,x,w,11,c[45]),x=u(x,E,C,A,I,16,c[46]),C=h(C,A=u(A,x,E,C,f,23,c[47]),x,E,a,6,c[48]),E=h(E,C,A,x,_,10,c[49]),x=h(x,E,C,A,B,15,c[50]),A=h(A,x,E,C,g,21,c[51]),C=h(C,A,x,E,w,6,c[52]),E=h(E,C,A,x,p,10,c[53]),x=h(x,E,C,A,S,15,c[54]),A=h(A,x,E,C,o,21,c[55]),C=h(C,A,x,E,D,6,c[56]),E=h(E,C,A,x,I,10,c[57]),x=h(x,E,C,A,y,15,c[58]),A=h(A,x,E,C,k,21,c[59]),C=h(C,A,x,E,v,6,c[60]),E=h(E,C,A,x,b,10,c[61]),x=h(x,E,C,A,f,15,c[62]),A=h(A,x,E,C,m,21,c[63]),r[0]=r[0]+C|0,r[1]=r[1]+A|0,r[2]=r[2]+x|0,r[3]=r[3]+E|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;i[n>>>5]|=128<<24-n%32;var r=e.floor(s/4294967296),a=s;i[15+(n+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(n+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var c=this._hash,o=c.words,l=0;l<4;l++){var d=o[l];o[l]=16711935&(d<<8|d>>>24)|4278255360&(d<<24|d>>>8)}return c},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});function l(e,t,i,s,n,r,a){var c=e+(t&i|~t&s)+n+a;return(c<<r|c>>>32-r)+t}function d(e,t,i,s,n,r,a){var c=e+(t&s|i&~s)+n+a;return(c<<r|c>>>32-r)+t}function u(e,t,i,s,n,r,a){var c=e+(t^i^s)+n+a;return(c<<r|c>>>32-r)+t}function h(e,t,i,s,n,r,a){var c=e+(i^(t|~s))+n+a;return(c<<r|c>>>32-r)+t}t.MD5=r._createHelper(o),t.HmacMD5=r._createHmacHelper(o)}(Math),s.MD5)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});t.default=e=>new Promise(t=>setTimeout(()=>t(),e))},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(3);function n(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return("00"+e.toString(16)).slice(-2)})).join("")}t.ab2hex=n,t.compareWXSDKVersion=function(e,t){const i=e.split("."),s=t.split("."),n=Math.max(e.length,t.length);for(;i.length<n;)i.push("0");for(;s.length<n;)s.push("0");for(let i=0;i<n;i++){const s=parseInt(e[i]),n=parseInt(t[i]);if(s>n)return 1;if(s<n)return-1}return 0},t.isError=e=>null!=e&&"symbol"==typeof e.errorCode,t.wrapErrorInfo=e=>({errorCode:e,errorMessage:e}),t.unionBy=(e,t)=>e.reduce((e,i)=>{const s=i[t];return e.some(e=>e[t]===s)||e.push(i),e},[]),t.isWXDevicesResult=function(e){return e.success&&"[object Array]"===Object.prototype.toString.call(e.bleDevices)},t.str2Buf=function(e){var t=e.length,i=new ArrayBuffer(t+2),s=new DataView(i);for(let i=0;i<t;i++)s.setUint8(i,parseInt(e[i],16));return i},t.numberArray2Uint8Array=e=>{const t=new ArrayBuffer(e.length),i=new Uint8Array(t);for(let s=0;s<t.byteLength;s++)i[s]=e[s];return i};function r(e){if(25!=(e=e.slice(0,25)).length)throw new Error("数据不合法");const t=`${c(e[0])}${c(e[1])}`;if(e[2]!==(255&e.slice(3).reduce((e,t)=>e+t,0)))throw new Error("校验和不合法");const i=c(e[3]),s=e.slice(5,5+e[4]).map(e=>c(e));return{mac:t,cmd:parseInt(i,16),data:s}}function a(e){return Array.prototype.map.call(new Uint8Array(e),(function(e){return e}))}function c(e,t=2){return`${new Array(t).fill(0).join("")}${e.toString(16)}`.slice(-t)}t.advertisData2PkAndMac=(e,t)=>e&&e.byteLength>=22&&e.byteLength<=24?Object.assign(Object.assign({},((e,t)=>{let i=e.slice(e.byteLength-16),s=e.slice(0,e.byteLength-16),r=n(i);if(t.find(e=>e===r)){const e=n(s);return{productKey:r,mac:e}}{i=e.slice(0,16),s=e.slice(16),r=n(i);const t=n(s);return{productKey:r,mac:t}}})(e,t)),{bleWorkStatus:1}):e&&e.byteLength>24?((e,t)=>{if(!e||0===e.byteLength)return{bleWorkStatus:0,mac:"",productKey:""};let i=0,s="",r="",a=1;const c=new Uint8Array(e);for(;!(i>e.byteLength-1);){const o=c[i];if(o<=0||!o)break;if(e.byteLength<o+i+1)break;const l=e.slice(i+1,i+o+1);if(o>=6&&o<=8&&(s=n(l),16==s.length&&(s=s.substring(0,15))),16==o){const e=n(l).toLowerCase();t.find(t=>t===e)&&(r=e)}1==o&&(a=new Uint8Array(l)[0]),i+=1+o}return{bleWorkStatus:a,mac:s,productKey:r}})(e,t):{mac:"",productKey:"",bleWorkStatus:1},t.isSameDevice=(e,t)=>e.mac===t.mac&&e.productKey===t.productKey,t.merageBleLocalDevices=(e,i)=>(e.map(e=>{e.isBleOnline=!1,e.bleWorkStatus=0}),i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?(s.isBleOnline=!0,s.bleDeviceID=i.bleDeviceID,s.connectType=i.connectType,s.bleWorkStatus=i.bleWorkStatus):e.push(i)}),e),t.merageLanLocalDevices=(e,i)=>(e.map(e=>{e.isLanOnline=!1}),i.map(i=>{const s=e.find(e=>t.isSameDevice(e,i));s?s.isLanOnline=!0:e.push(i)}),e),t.BTDevice2GDevice=(e,i)=>{let n={productKey:"",mac:"",bleWorkStatus:0},c={did:"",productKey:"",mac:"",bleWorkStatus:0,connectType:"NONE",isBleOnline:!0,isLanOnline:!1,isOnline:!1,name:e.name,isBind:!1,bleDeviceID:e.deviceId,ctime:(new Date).getTime()};switch(e.communicationType){case"BLE_BROADCAST":try{s.default.log("parse BLE_BROADCAST");const t=r(a(e.advertisData));n.productKey=t.data.join(""),n.mac=t.mac,c.connectType="BLE_BROADCAST"}catch(e){}break;default:n=t.advertisData2PkAndMac(e.advertisData,i)}return c=Object.assign(Object.assign({},c),n),c},t.getFirstConnectType=(e,t)=>{if(!t)return e.isLanOnline?"LAN":e.isBleOnline?"BLE":"WAN";if("WAN"===t)return"WAN";switch(t){case"BLE":return e.isBleOnline?"BLE":"NONE";case"LAN":return e.isLanOnline?"LAN":"NONE"}return"WAN"},t.getProductInfoThroughPK=(e,t)=>t.find(t=>t.productKey===e),t.mergeObject=(e,t)=>{for(let i in t)null!=t[i]&&""!==t[i]&&(e[i]=t[i]);return e},t.hex2ab=function(e){const t=[];for(let s=0;s<e.length;s+=2){var i=e.slice(s,s+2);t.push(parseInt(i,16))}return new Uint8Array(t)},t.parseBroadcastData=r,t.ab2numbers=a;let o=0;function l(e,t){let i=1,s=t;return e.map(e=>{const t=65535&(e^s);return s=i-t&65535,i<<=1,c(t,4)})}function d(e,t,i){if(i.length>22)throw new Error("最大长度为22");const n=[...i,...new Array(22-i.length).fill(0)],r=255&i.reduce((e,t)=>e+t,0),a=(t>>4<<12)+(r>>4<<8)+((15&t)<<4)+(15&r),o=Array.from({length:11},(e,t)=>(n[2*t]<<8)+n[2*t+1]);return s.default.log("明文",c(e,4),c((t<<8)+r,4),o.map(e=>c(e,4))),[c(e,4),c((t<<8)+r,4),...l(o,a)].map(e=>`${e.slice(2)}${e.slice(0,2)}`)}t.encrypt=l,t.convertToServiceUuids=({len:e=null,data:i=null,index:s=0,mac:n})=>{const r=null==e?Math.round(18*Math.random())+1:e,a=null==i?Array.from({length:r},e=>Math.round(255*Math.random())):i,c=[147,r,...a],l=d(n,(()=>{const e=o;return o=o+1&255,e})(),c);return[...new Set(l)].length!==l.length?t.convertToServiceUuids({len:r,data:a,index:s++,mac:n}):l},t.convertToUuids=d},function(e,t,i){var s;e.exports=(s=i(0),i(13),i(36),i(37),i(7),i(38),i(8),i(14),i(20),i(39),i(21),i(40),i(41),i(42),i(15),i(43),i(6),i(1),i(44),i(45),i(46),i(47),i(48),i(49),i(50),i(51),i(52),i(53),i(54),i(55),i(56),i(57),i(58),i(59),s)},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(22),r=i(18),a=i(5);t.default=(e,t,i=!0)=>s(void 0,void 0,void 0,(function*(){const s=Object.assign({},t),c={"Content-Type":"application/json","X-Gizwits-Application-Id":r.getGlobalData("appID")};i&&(c["X-Gizwits-User-token"]=r.getGlobalData("token")),s.header=Object.assign(Object.assign({},c),t.headers),delete s.headers;const o=r.getGlobalData("cloudServiceInfo").openAPIInfo,l=yield n.default("https://"+o+e,s);if(l.statusCode>=200&&l.statusCode<300)return{success:!0,data:l.data};let d={success:!1,err:{errorCode:a.default.GIZ_SDK_HTTP_REQUEST_FAILED.errorCode,errorMessage:""}};try{d={success:!1,err:{errorCode:l.data.error_code,errorMessage:l.data.error_message}}}catch(e){}return d}))},function(e,t,i){var s,n,r,a,c,o;e.exports=(o=i(0),n=(s=o).lib,r=n.Base,a=n.WordArray,(c=s.x64={}).Word=r.extend({init:function(e,t){this.high=e,this.low=t}}),c.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:8*e.length},toX32:function(){for(var e=this.words,t=e.length,i=[],s=0;s<t;s++){var n=e[s];i.push(n.high),i.push(n.low)}return a.create(i,this.sigBytes)},clone:function(){for(var e=r.clone.call(this),t=e.words=this.words.slice(0),i=t.length,s=0;s<i;s++)t[s]=t[s].clone();return e}}),o)},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),n=(s=d).lib,r=n.WordArray,a=n.Hasher,c=s.algo,o=[],l=c.SHA1=a.extend({_doReset:function(){this._hash=new r.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],l=0;l<80;l++){if(l<16)o[l]=0|e[t+l];else{var d=o[l-3]^o[l-8]^o[l-14]^o[l-16];o[l]=d<<1|d>>>31}var u=(s<<5|s>>>27)+c+o[l];u+=l<20?1518500249+(n&r|~n&a):l<40?1859775393+(n^r^a):l<60?(n&r|n&a|r&a)-1894007588:(n^r^a)-899497514,c=a,a=r,r=n<<30|n>>>2,n=s,s=u}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+c|0},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[14+(s+64>>>9<<4)]=Math.floor(i/4294967296),t[15+(s+64>>>9<<4)]=i,e.sigBytes=4*t.length,this._process(),this._hash},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),s.SHA1=a._createHelper(l),s.HmacSHA1=a._createHmacHelper(l),d.SHA1)},function(e,t,i){var s,n,r,a;e.exports=(s=i(0),r=(n=s).lib.Base,a=n.enc.Utf8,void(n.algo.HMAC=r.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=a.parse(t));var i=e.blockSize,s=4*i;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var n=this._oKey=t.clone(),r=this._iKey=t.clone(),c=n.words,o=r.words,l=0;l<i;l++)c[l]^=1549556828,o[l]^=909522486;n.sigBytes=r.sigBytes=s,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})))},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12);const r=new class{constructor(){this.data={},this.key="dataPointConfig",this.init=()=>s(this,void 0,void 0,(function*(){const e=(yield wx.getStorageSync(this.key))||"{}";let t={};try{t=JSON.parse(e)}catch(e){}this.data=t})),this.getConfigFile=e=>s(this,void 0,void 0,(function*(){var t;if(!this.data[e]){const i=`/app/datapoint?product_key=${e}`,s=yield n.default(`${i}`,{method:"GET"});if(!s.success||!(null===(t=s.data)||void 0===t?void 0:t.entities))return null;this.data[e]=s.data,wx.setStorageSync(this.key,JSON.stringify(this.data))}return this.data[e]})),this.getAttrItem=(e,t)=>s(this,void 0,void 0,(function*(){this.data[e]||(yield this.getConfigFile(e));for(let i in this.data[e].entities[0].attrs){const s=this.data[e].entities[0].attrs[i];if(s.name===t)return s}return null}))}};r.init(),t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),i(31);const s=i(32),n=i(5);t.errorCode=n.default;const r=i(19);t.BleHandle=r.BleHandle,t.default=s.default},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s={};t.setGlobalData=function(e,t){s[e]=t},t.getGlobalData=function(e){return s[e]}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))},n=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i};Object.defineProperty(t,"__esModule",{value:!0});const r=i(10),a=i(23),c=i(24),o=i(2),l=i(4),d=i(25),u=i(60),h=i(26),f=i(3),p=i(27),v=i(9);class g extends p.default{constructor({pks:e=[],bleHandleParams:t={serviceUUIDSuffix:"abf0",characteristicUUIDSuffix:"abf7"},offlineThreshold:i}){super(),this.connectedList=[],this.connectingDevId=null,this.pks=[],this.listenDevOfflineTimer=null,this.boradcastDataCache={},this.tmpBleData="",this.tmpDataNum=0,this.disableScanFlag=!1,this.peripheralServer=null,this.isActive=!0,this.scanList=[],this.onBluetoothAdapterStateChange=e=>{f.default.debug("onBluetoothAdapterStateChange",e),e.available||(this.scanList=[],this.notifyDevices())},this.onAppShow=()=>{this.isActive=!0,this.scanList.map(e=>{e.ctime=Date.now()})},this.onAppHide=()=>{this.isActive=!1},this.listenDevOffline=e=>{this.listenDevOfflineTimer=setInterval(()=>{if(!this.isActive)return;const t=(new Date).getTime(),i=this.scanList.filter(i=>{const s=this.connectedList.find(e=>i.bleDeviceID==e.deviceId),n=this.connectingDevId===i.bleDeviceID;return!(!s&&!n)||("BLE_BROADCAST"===i.connectType?t-i.ctime<2*e:t-i.ctime<e)});i.length!==this.scanList.length&&(this.scanList=i,this.notifyDevices())},500)},this.openBluetoothAdapter=(e="central")=>new Promise((t,i)=>{wx.openBluetoothAdapter({mode:e,success:()=>{t({success:!0}),wx.onBLECharacteristicValueChange(this.handleOnBLECharacteristicValueChange)},fail:e=>{f.default.error("openBluetoothAdapter fail",new Error(JSON.stringify(e))),this.notifyError({errMsg:e.errMsg,errCode:-1}),i({success:!1,err:e})}})}),this.handleOnBLECharacteristicValueChange=e=>s(this,void 0,void 0,(function*(){if(!e.value)return;const t=r.ab2hex(e.value);try{const i=new l.default(o.hexStrint2byte(t));this.tmpBleData=t,this.tmpDataNum=i.len-e.value.byteLength+4+Math.ceil(i.len.toString(2).length/8)}catch(i){this.tmpBleData&&(this.tmpBleData+=t,this.tmpDataNum-=e.value.byteLength)}this.tmpDataNum>0||!this.tmpBleData||(this.notiDeviceDataToSdk(e,this.tmpBleData),this.tmpBleData="",this.tmpDataNum=0)})),this.notiDeviceDataToSdk=(e,t)=>{this.listenerMap.GizBleDeviceData&&this.listenerMap.GizBleDeviceData.map(i=>{i(e,t)})},this.notifyError=e=>{this.listenerMap.GizBleError&&this.listenerMap.GizBleError.map(t=>{t(e)})},this.notifyDevices=()=>{this.listenerMap.GizBleDeviceList&&this.listenerMap.GizBleDeviceList.map(e=>{e(this.scanList)})},this.listenConnection=()=>{wx.onBLEConnectionStateChange(e=>{if(!1===e.connected){const t=this.connectedList.findIndex(t=>t.deviceId===e.deviceId);-1!==t&&(this.connectedList.splice(t,1),this.notifyDevices())}})},this.init=()=>s(this,void 0,void 0,(function*(){const{platform:e}=wx.getSystemInfoSync();yield this.openBluetoothAdapter(),"ios"===e&&(yield this.openBluetoothAdapter("peripheral"));try{this.peripheralServer=(yield wx.createBLEPeripheralServer()).server,f.default.info("GIZ_SDK: 广播初始化成功",this.peripheralServer)}catch(e){f.default.error("GIZ_SDK: 广播初始化失败",new Error(JSON.stringify(e)))}return yield this.getBluetoothAdapterState()})),this.checkPermission=()=>s(this,void 0,void 0,(function*(){if((yield wx.getSetting()).authSetting["scope.bluetooth"])return yield this.init();try{return yield wx.authorize({scope:"scope.bluetooth"}),yield this.init()}catch(e){f.default.log("授权失败",e),this.openBluetoothAdapter(),this.notifyError({errMsg:e.errMsg,errCode:-1})}})),this.getBluetoothAdapterState=()=>s(this,void 0,void 0,(function*(){f.default.log("getBluetoothAdapterState",yield wx.getBluetoothAdapterState());const e=yield wx.getBluetoothAdapterState(),{errMsg:t,available:i}=e,s=n(e,["errMsg","available"]);return{data:Object.assign({},s),err:r.wrapErrorInfo(t),success:i}})),this.getDeviceStatus=(e,t,i,n)=>s(this,void 0,void 0,(function*(){const s=yield u.default.pack(t,i,n);return s?yield this.write(e,r.numberArray2Uint8Array(s).buffer):{success:!1}})),this.updateDevice=e=>{const t=e.bleDeviceID,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i]=e)},this.updateCtime=e=>{const t=e.deviceId,i=this.scanList.findIndex(e=>t==e.bleDeviceID);-1!==i&&(this.scanList[i].ctime=Date.now())},this.checkDeviceIsChange=(e,t)=>e.bleWorkStatus!==t.bleWorkStatus||e.name!==t.name||e.isBleOnline!==t.isBleOnline||e.isOnline!==t.isOnline,this.handleBluetoothDeviceFound=(e,t)=>{r.unionBy(e.devices,"deviceId").map(e=>{const{advertisData:i,deviceId:s,name:n,localName:a}=e,c=r.ab2hex(i);let o=null;try{o=r.parseBroadcastData(r.ab2numbers(i))}catch(e){}const l=this.scanList.find(e=>e.bleDeviceID===s);if(o&&148===o.cmd){const t=r.ab2hex(i);if(this.boradcastDataCache[s]&&this.boradcastDataCache[s]===t)return!1;if(!l)return!1;this.boradcastDataCache[s]=r.ab2hex(i);const n=h.padBoradcastData(o.data.map(e=>parseInt(e,16)));return this.updateCtime(e),void this.notiDeviceDataToSdk(e,n)}if(o&&25===o.cmd){this.pks.find(e=>e===o.data.join(""))&&(e.communicationType="BLE_BROADCAST")}if(l){const i=r.BTDevice2GDevice(e,this.pks);if(i.productKey&&i.mac){const e=this.checkDeviceIsChange(i,l);i.ctime=Date.now(),this.updateDevice(i),e&&t(this.scanList)}}else{if(this.pks.some(e=>c.includes(e))){const i=r.BTDevice2GDevice(e,this.pks);i.productKey&&i.mac&&(this.scanList.push(i),t(this.scanList))}}})},this.startScan=(e,t=5e3)=>s(this,void 0,void 0,(function*(){return this.disableScanFlag?{scanList:[]}:new Promise(i=>s(this,void 0,void 0,(function*(){wx.onBluetoothDeviceFound(t=>{this.handleBluetoothDeviceFound(t,e)}),f.default.debug("GIZ_SDK: start scan",t),yield wx.startBluetoothDevicesDiscovery({services:[],powerLevel:"high",allowDuplicatesKey:!0,interval:200}),t>0&&setTimeout(()=>{this.stopScan(),i({scanList:this.scanList})},t)})))})),this.stopScan=()=>s(this,void 0,void 0,(function*(){try{return yield wx.stopBluetoothDevicesDiscovery()}catch(e){return e}})),this.disableScan=()=>s(this,void 0,void 0,(function*(){this.disableScanFlag=!0;const e=yield wx.stopBluetoothDevicesDiscovery();return yield v.default(200),e})),this.enableScan=()=>{this.disableScanFlag=!1},this.connectDevice=e=>s(this,void 0,void 0,(function*(){var t;try{this.connectingDevId=e;try{yield this.disableScan();const t=yield a.retryConnect(e);this.enableScan(),f.default.debug("connect res",t)}catch(e){if(f.default.error("GIZ_SDK: createBLEConnection error",new Error(JSON.stringify(e))),"createBLEConnection:fail:already connect"!==(null==e?void 0:e.errMsg))return this.notifyError(e),{success:!1,message:null==e?void 0:e.errMsg}}const i=yield wx.getBLEDeviceServices({deviceId:e}).catch(e=>this.notifyError(e)),s=null===(t=null==i?void 0:i.services.find(e=>e.isPrimary&&e.uuid.toLowerCase().includes(this.serviceUUIDSuffix)))||void 0===t?void 0:t.uuid;if(!s)return{message:"can not find valid serviceId",success:!1};const n=yield wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:s}).catch(e=>this.notifyError(e)),o=null==n?void 0:n.characteristics[0].uuid;this.connectedList.every(t=>t.deviceId!==e)&&this.connectedList.push({deviceId:e,serviceId:s,characteristicId:o}),yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:s,characteristicId:o,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),this.write(e,r.numberArray2Uint8Array(c.default.pack()).buffer);const l=yield this.handleBindReq(e);if(f.default.log("handleBindReq",l),l.success){this.write(e,r.numberArray2Uint8Array(d.default.pack({passcode:l.data})).buffer);const t=yield this.handleLoginReq(e).catch(e=>this.notifyError(e));if(null==t?void 0:t.success)return{success:!0,message:"ok"}}return yield wx.closeBLEConnection({deviceId:e}),{success:!1,message:"ok"}}finally{this.connectingDevId=null}})),this.handleBindReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;f.default.log("监听蓝牙特征值发生变化");const r=new c.default(o.hexStrint2byte(n));this.removeEventListener("GizBleDeviceData",i),r.passcode?t({success:!0,data:r.passcode}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.handleLoginReq=e=>new Promise(t=>{const i=(s,n)=>{if(s.deviceId!==e)return;f.default.log("设备回复LoginReq",n);const r=new d.default(o.hexStrint2byte(n));this.removeEventListener("GizBleDeviceData",i),!0===r.result?t({success:!0,data:r.did}):t({success:!1,data:""})};this.watchBleDevice(e,i)}),this.watchBleDevice=(e,t)=>s(this,void 0,void 0,(function*(){const{serviceId:i,characteristicId:s,errMsg:n}=this.getTargetDevice(e);return n?{success:!1,message:n}:(yield wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,type:"notification"}).catch(e=>this.notifyError(e)),f.default.log(`监听设备 ${e} 成功!`),this.addEventListener("GizBleDeviceData",t),{message:"ok",success:!0})})),this.writeBoradcast=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.scanList.find(t=>t.bleDeviceID===e);if(!i)return{success:!1,message:"not found device"};this.boradcastTimer&&clearTimeout(this.boradcastTimer);try{this.peripheralServer.stopAdvertising({});const e=r.convertToServiceUuids({mac:i.mac,index:0,data:t,len:t.length});return this.peripheralServer.startAdvertising({advertiseRequest:{connectable:!0,serviceUuids:e},powerLevel:"high",success:e=>{f.default.debug("GIZ_SDK: startAdvertising success",e)},fail:e=>{f.default.error("GIZ_SDK: startAdvertising error",new Error(JSON.stringify(e)))}}),f.default.debug("GIZ_SDK: start adv",e),this.boradcastTimer=setTimeout(()=>{this.peripheralServer.stopAdvertising({}),this.boradcastTimer=null},1e3),{success:!0}}catch(e){return f.default.log("GIZ_SDK:",e),clearTimeout(this.boradcastTimer),{success:!1,message:"send cmd error"}}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){f.default.log("app => dev:",r.ab2hex(t));const i=this.getTargetDevice(e);if(i.serviceId&&i.characteristicId){return yield a.unpackWriteBLECharacteristicValue(e,i.serviceId,i.characteristicId,t)}return{success:!1,message:"send cmd error"}})),this.disConnectDevice=e=>s(this,void 0,void 0,(function*(){this.removeDevById(e);const{errMsg:t}=yield wx.closeBLEConnection({deviceId:e}),i=this.scanList.find(t=>t.bleDeviceID===e);return i&&(i.ctime=Date.now(),this.updateDevice(i)),"closeBLEConnection:ok"===t?{err:t,success:!0}:{err:t,success:!1}})),this.removeDevById=e=>{const t=this.connectedList.findIndex(t=>t.deviceId===e);-1!==t&&this.connectedList.splice(t,1)},this.getTargetDevice=e=>{const t=this.connectedList.find(t=>e===t.deviceId);return t||{errMsg:"Unable get this device,maybe you forgot to connect it."}},this.destory=()=>{this.listenDevOfflineTimer&&clearInterval(this.listenDevOfflineTimer),wx.offAppShow(this.onAppShow),wx.offAppHide(this.onAppHide),wx.offBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)};const{serviceUUIDSuffix:p}=t;this.serviceUUIDSuffix=p,this.pks=e,this.listenDevOffline(null!=i?i:1e4),this.listenConnection(),wx.onAppShow(this.onAppShow),wx.onAppHide(this.onAppHide),wx.onBluetoothAdapterStateChange(this.onBluetoothAdapterStateChange)}}t.BleHandle=g},function(e,t,i){var s;e.exports=(s=i(0),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.algo,c=[],o=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,n=0;n<64;)t(s)&&(n<8&&(c[n]=i(e.pow(s,.5))),o[n]=i(e.pow(s,1/3)),n++),s++}();var l=[],d=a.SHA256=r.extend({_doReset:function(){this._hash=new n.init(c.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],d=i[5],u=i[6],h=i[7],f=0;f<64;f++){if(f<16)l[f]=0|e[t+f];else{var p=l[f-15],v=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,g=l[f-2],y=(g<<15|g>>>17)^(g<<13|g>>>19)^g>>>10;l[f]=v+l[f-7]+y+l[f-16]}var _=s&n^s&r^n&r,D=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),m=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&d^~c&u)+o[f]+l[f];h=u,u=d,d=c,c=a+m|0,a=r,r=n,n=s,s=m+(D+_)|0}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+a|0,i[4]=i[4]+c|0,i[5]=i[5]+d|0,i[6]=i[6]+u|0,i[7]=i[7]+h|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;return i[n>>>5]|=128<<24-n%32,i[14+(n+64>>>9<<4)]=e.floor(s/4294967296),i[15+(n+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(d),t.HmacSHA256=r._createHmacHelper(d)}(Math),s.SHA256)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(){var e=s,t=e.lib.Hasher,i=e.x64,n=i.Word,r=i.WordArray,a=e.algo;function c(){return n.create.apply(n,arguments)}var o=[c(1116352408,3609767458),c(1899447441,602891725),c(3049323471,3964484399),c(3921009573,2173295548),c(961987163,4081628472),c(1508970993,3053834265),c(2453635748,2937671579),c(2870763221,3664609560),c(3624381080,2734883394),c(310598401,1164996542),c(607225278,1323610764),c(1426881987,3590304994),c(1925078388,4068182383),c(2162078206,991336113),c(2614888103,633803317),c(3248222580,3479774868),c(3835390401,2666613458),c(4022224774,944711139),c(264347078,2341262773),c(604807628,2007800933),c(770255983,1495990901),c(1249150122,1856431235),c(1555081692,3175218132),c(1996064986,2198950837),c(2554220882,3999719339),c(2821834349,766784016),c(2952996808,2566594879),c(3210313671,3203337956),c(3336571891,1034457026),c(3584528711,2466948901),c(113926993,3758326383),c(338241895,168717936),c(666307205,1188179964),c(773529912,1546045734),c(1294757372,1522805485),c(1396182291,2643833823),c(1695183700,2343527390),c(1986661051,1014477480),c(2177026350,1206759142),c(2456956037,344077627),c(2730485921,1290863460),c(2820302411,3158454273),c(3259730800,3505952657),c(3345764771,106217008),c(3516065817,3606008344),c(3600352804,1432725776),c(4094571909,1467031594),c(275423344,851169720),c(430227734,3100823752),c(506948616,1363258195),c(659060556,3750685593),c(883997877,3785050280),c(958139571,3318307427),c(1322822218,3812723403),c(1537002063,2003034995),c(1747873779,3602036899),c(1955562222,1575990012),c(2024104815,1125592928),c(2227730452,2716904306),c(2361852424,442776044),c(2428436474,593698344),c(2756734187,3733110249),c(3204031479,2999351573),c(3329325298,3815920427),c(3391569614,3928383900),c(3515267271,566280711),c(3940187606,3454069534),c(4118630271,4000239992),c(116418474,1914138554),c(174292421,2731055270),c(289380356,3203993006),c(460393269,320620315),c(685471733,587496836),c(852142971,1086792851),c(1017036298,365543100),c(1126000580,2618297676),c(1288033470,3409855158),c(1501505948,4234509866),c(1607167915,987167468),c(1816402316,1246189591)],l=[];!function(){for(var e=0;e<80;e++)l[e]=c()}();var d=a.SHA512=t.extend({_doReset:function(){this._hash=new r.init([new n.init(1779033703,4089235720),new n.init(3144134277,2227873595),new n.init(1013904242,4271175723),new n.init(2773480762,1595750129),new n.init(1359893119,2917565137),new n.init(2600822924,725511199),new n.init(528734635,4215389547),new n.init(1541459225,327033209)])},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],a=i[3],c=i[4],d=i[5],u=i[6],h=i[7],f=s.high,p=s.low,v=n.high,g=n.low,y=r.high,_=r.low,D=a.high,m=a.low,S=c.high,b=c.low,w=d.high,k=d.low,B=u.high,I=u.low,C=h.high,A=h.low,x=f,E=p,L=v,T=g,O=y,P=_,H=D,M=m,K=S,N=b,G=w,R=k,U=B,z=I,j=C,W=A,Z=0;Z<80;Z++){var F,V,$=l[Z];if(Z<16)V=$.high=0|e[t+2*Z],F=$.low=0|e[t+2*Z+1];else{var X=l[Z-15],J=X.high,q=X.low,Y=(J>>>1|q<<31)^(J>>>8|q<<24)^J>>>7,Q=(q>>>1|J<<31)^(q>>>8|J<<24)^(q>>>7|J<<25),ee=l[Z-2],te=ee.high,ie=ee.low,se=(te>>>19|ie<<13)^(te<<3|ie>>>29)^te>>>6,ne=(ie>>>19|te<<13)^(ie<<3|te>>>29)^(ie>>>6|te<<26),re=l[Z-7],ae=re.high,ce=re.low,oe=l[Z-16],le=oe.high,de=oe.low;V=(V=(V=Y+ae+((F=Q+ce)>>>0<Q>>>0?1:0))+se+((F+=ne)>>>0<ne>>>0?1:0))+le+((F+=de)>>>0<de>>>0?1:0),$.high=V,$.low=F}var ue,he=K&G^~K&U,fe=N&R^~N&z,pe=x&L^x&O^L&O,ve=E&T^E&P^T&P,ge=(x>>>28|E<<4)^(x<<30|E>>>2)^(x<<25|E>>>7),ye=(E>>>28|x<<4)^(E<<30|x>>>2)^(E<<25|x>>>7),_e=(K>>>14|N<<18)^(K>>>18|N<<14)^(K<<23|N>>>9),De=(N>>>14|K<<18)^(N>>>18|K<<14)^(N<<23|K>>>9),me=o[Z],Se=me.high,be=me.low,we=j+_e+((ue=W+De)>>>0<W>>>0?1:0),ke=ye+ve;j=U,W=z,U=G,z=R,G=K,R=N,K=H+(we=(we=(we=we+he+((ue+=fe)>>>0<fe>>>0?1:0))+Se+((ue+=be)>>>0<be>>>0?1:0))+V+((ue+=F)>>>0<F>>>0?1:0))+((N=M+ue|0)>>>0<M>>>0?1:0)|0,H=O,M=P,O=L,P=T,L=x,T=E,x=we+(ge+pe+(ke>>>0<ye>>>0?1:0))+((E=ue+ke|0)>>>0<ue>>>0?1:0)|0}p=s.low=p+E,s.high=f+x+(p>>>0<E>>>0?1:0),g=n.low=g+T,n.high=v+L+(g>>>0<T>>>0?1:0),_=r.low=_+P,r.high=y+O+(_>>>0<P>>>0?1:0),m=a.low=m+M,a.high=D+H+(m>>>0<M>>>0?1:0),b=c.low=b+N,c.high=S+K+(b>>>0<N>>>0?1:0),k=d.low=k+R,d.high=w+G+(k>>>0<R>>>0?1:0),I=u.low=I+z,u.high=B+U+(I>>>0<z>>>0?1:0),A=h.low=A+W,h.high=C+j+(A>>>0<W>>>0?1:0)},_doFinalize:function(){var e=this._data,t=e.words,i=8*this._nDataBytes,s=8*e.sigBytes;return t[s>>>5]|=128<<24-s%32,t[30+(s+128>>>10<<5)]=Math.floor(i/4294967296),t[31+(s+128>>>10<<5)]=i,e.sigBytes=4*t.length,this._process(),this._hash.toX32()},clone:function(){var e=t.clone.call(this);return e._hash=this._hash.clone(),e},blockSize:32});e.SHA512=t._createHelper(d),e.HmacSHA512=t._createHmacHelper(d)}(),s.SHA512)},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){return new Promise((i,s)=>{wx.request(Object.assign(Object.assign({url:e,timeout:3e3},t),{success:e=>{i(e)},fail:e=>{s(e)}}))})}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(3),r=i(9);function a(e,t){return new Promise((i,s)=>{wx.createBLEConnection({deviceId:e,timeout:t,success:e=>i(e),fail:e=>{-1===e.errCode?i(e):s(e)}})})}function c(e,t,i,s){return new Promise(n=>{wx.writeBLECharacteristicValue({deviceId:e,serviceId:t,characteristicId:i,value:s,complete:n})})}t.retryConnect=function(e,t=1e4){return s(this,void 0,void 0,(function*(){let i={success:!1};for(let s=0;s<5;s++)try{return console.debug("start createBLEConnection"),yield a(e,t)}catch(e){i=e,console.debug("createBLEConnection error retry"),yield r.default(1e3)}return i}))},t.openBluetoothAdapter=function(){return new Promise((e,t)=>{wx.openBluetoothAdapter({success:e,fail:t})})},t.closeBluetoothAdapter=function(){return new Promise((e,t)=>{wx.closeBluetoothAdapter({success:e,fail:t})})},t.getBluetoothAdapterState=function(){return new Promise((e,t)=>{wx.getBluetoothAdapterState({success:e,fail:t})})},t.startBluetoothDevicesDiscovery=function(e=!0){return new Promise((t,i)=>{wx.startBluetoothDevicesDiscovery({success:t,fail:i,allowDuplicatesKey:e,powerLevel:"high",interval:200})})},t.getBluetoothDevices=function(){return new Promise((e,t)=>{wx.getBluetoothDevices({success:({devices:t})=>e(t),fail:t})})},t.createBLEConnection=a,t.getBLEDeviceServices=function(e){return new Promise((t,i)=>{wx.getBLEDeviceServices({deviceId:e,success:({services:e})=>t(e),fail:i})})},t.getBLEDeviceCharacteristics=function(e,t){return new Promise((i,s)=>{wx.getBLEDeviceCharacteristics({deviceId:e,serviceId:t,success:({characteristics:e})=>i(e),fail:s})})},t.notifyBLECharacteristicValueChange=function(e,t,i,s=!0){return new Promise((n,r)=>{wx.notifyBLECharacteristicValueChange({deviceId:e,serviceId:t,characteristicId:i,state:s,success:n,fail:r})})},t.writeBLECharacteristicValue=c,t.unpackWriteBLECharacteristicValue=function(e,t,i,a){if(!a||0===a.byteLength)throw new Error("value is empty");return new Promise((o,l)=>s(this,void 0,void 0,(function*(){let s,d=0,u=a.byteLength;for(;u>0;){yield r.default(30);const o=a.slice(d,d+20);if(d+=20,u-=20,s=yield c(e,t,i,o),n.default.log("unpackWriteBLECharacteristicValue",d/20,s),0!==s.errCode)break}0!==s.errCode?l(s):o(s)})))}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.passcode="";let t=0;const i=parseInt(n.arrayToString(this.content.slice(t,t+2)),16);t+=2;let s="";this.content.slice(t,t+i).map(e=>{s+=String.fromCharCode(e)}),this.passcode=s}}r.pack=()=>[0,0,0,3,3,0,0,6],t.default=r},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e),this.result=!1,this.didLength=0,this.did="";let t=0;if(this.result=0===this.content[0],t++,1===this.flag[0]){this.didLength=parseInt(n.arrayToString(this.content.slice(t,t+2)),16),t+=2;let e="";this.content.slice(t,this.content.length).map(t=>{e+=String.fromCharCode(t)}),this.did=e}}}r.pack=({passcode:e})=>{let t=[0];const i=n.hexStrint2byte(n.fillString(e.length.toString(16),4)),s=n.string2Bytes(e),r=[0].concat([0,8]).concat(i).concat(s);return t=n.hexStrint2byte(r.length.toString(16)),[0,0,0,3].concat(t).concat(r)},t.default=r},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(16),r=i(2),a=e=>-1!==e.indexOf("uint")?"number":e,c=(e,t,i)=>{let s="";switch(e){case"bool":s=`${!0===t[i.name]?1:0}`;break;case"enum":{let e=t[i.name];"number"==typeof e&&(e=i.enum[e]);const n=i.enum.findIndex(t=>e===t),a=-1===n?0:n;s=r.fillString(a.toString(2),i.position.len);break}case"number":{let e=0;null!=t[i.name]&&(e=Math.round((t[i.name]-i.uint_spec.addition)/i.uint_spec.ratio)),s=r.fillString(e.toString(2),8*i.position.len);break}case"binary":{let e=t[i.name]||"";e instanceof Array&&(e=r.arrayToString(e));const n=r.fillString(e,2*i.position.len,!0);for(let e=0;e<n.length/2;e++){const t=2*e,i=n[t]+n[t+1];s+=r.fillString(parseInt(i,16).toString(2),8)}break}}const n=i.position.len*("byte"===i.position.unit?8:1)-s.length;if(n>0)for(let e=0;e<n;e++)s=`0${s}`;return`${s}`},o=(e,t,i)=>{switch(e){case"bool":return"1"===t;case"enum":return parseInt(t,2);case"binary":{const e=i.position.len;let s="";for(let e=0;e<t.length/8;e++){const i=8*e,n=t.substring(i,i+8);s+=r.fillString(parseInt(n,2).toString(16),2)}return r.fillString(s,2*e,!0)}case"number":return parseInt(t,2)/(1/i.uint_spec.ratio)+i.uint_spec.addition;default:return""}},l=({config:e,data:t,isAdaptiveDatapoint:i})=>{let s=e;const n=[0,0,0,3],o=[0],l=[0,147],u=[0,0,0,0];let h=[1],f="";const p=[];i||(s=s.filter(e=>"status_writable"===e.type)),s.map(e=>{void 0!==t[e.name]?(f=`1${f}`,p.push(e)):f=`0${f}`}),i&&(h=[17],s=p),f=r.fillString(f,8*Math.ceil(f.length/8));for(let e=0;e<f.length/8;e++)h.push(parseInt(f.substring(8*e,8*(e+1)),2));let v,g="";try{v=s[0]}catch(e){}s.map(e=>{"bool"===e.data_type||"enum"===e.data_type?(v.type!==e.type&&(h=h.concat(r.completeBlock(g)),g=""),g=((e,i)=>{const s=a(e.data_type);return i=c(s,t,e)+i})(e,g)):(g.length>0&&(h=h.concat(r.completeBlock(g)),g=""),h=((e,i)=>{const s=a(e.data_type),n=c(s,t,e);return i=i.concat(r.completeBlock(n))})(e,h)),v=e}),g.length>0&&(h=h.concat(r.completeBlock(g)),g="");const y=o.concat(l).concat(u).concat(h),_=d(y);return n.push(..._),{data:n.concat(y),raw:{header:[0,0,0,3],flag:o,len:_,headerCmd:l,sn:u,cmd:h}}};function d(e){const t=e.length.toString(2),i=[];for(let e=t.length;e>0;e-=7){const s=e-7,n=e;let r=t.substring(s,n);r=`${s>0?"1":"0"}${r}`,i.push(parseInt(r,2))}return i}function u(e,t){return e===t||"ALL"===e}function h({attrs:e,activeAttrs:t,flagString:i,cmdData:s,accumulate:n}){let r=0,a={},c=0;return["status_writable","status_readonly","alert","fault"].map(o=>{const l=e.filter(e=>u(o,e.type)).length,{cmd:d,cmdDataLength:h}=f({type:o,attrs:e.slice(c,c+l),activeAttrs:t,flagString:i.substring(c,c+l),cmdData:s.slice(r,s.length),accumulate:n});return r+=h,a=Object.assign(Object.assign({},a),d),c+=l,null}),a}function f({type:e,attrs:t,activeAttrs:i,cmdData:s,flagString:n,accumulate:c}){let l=0,d=0,h=0;return i.map(t=>{if(u(e,t.type)){const e=t.position.len*("bit"===t.position.unit?1:8);"bool"===t.data_type||"enum"===t.data_type?d+=e:h+=e}return null}),l=Math.ceil(h/8)+Math.ceil(d/8),{cmdDataLength:l,cmd:function({attrs:e,flagString:t,boolEnumLength:i,cmdData:s,accumulate:n}){const c={};let l=0;for(let d=0;d<t.length;d++)if(e[d]&&"1"===t[d]){const{data_type:t,position:{len:n}}=e[d];let u="";if("bool"===t||"enum"===t){let e="";s.slice(0,i).map(t=>(e+=r.fillString(t.toString(2),8),null));const t=e.length-l;u=e.substring(t-n,t),l+=n}else{const e=i,t=i+n;s.slice(e,t).map(e=>(u+=r.fillString(e.toString(2),8),null)),i+=n}const h=a(t);c[e[d].name]=o(h,u,e[d])}else if(n){const t=e[d]||{position:{len:0}};"byte"===t.position.unit?i+=t.position.len:l+=t.position.len}return c}({attrs:t,flagString:n,boolEnumLength:Math.ceil(d/8),cmdData:s,accumulate:c})}}t.unpack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield n.default.getConfigFile(t);if(i){const s=function({config:e=[],data:t}){let i,s,n="";const a={header:r.arrayToString(t.slice(0,4)),flag:"",len:"",cmd:"",sn:"",action:"",payload:""},c=e;let o=r.checkHeader(t);if(!1===o)return;const l=t.slice(o,t.length),d=r.getProtocolLen(l);if(o+=d,a.len=r.arrayToString(l.slice(0,d)),o+=1,a.flag=r.arrayToString(t.slice(o-1,o)),o+=2,a.cmd=r.arrayToString(t.slice(o-2,o)),a.sn="",("0093"===a.cmd||"0094"===a.cmd)&&(o+=4,a.sn=r.arrayToString(t.slice(o-4,o)),"01"===a.flag)){o+=2,o+=parseInt(r.arrayToString(t.slice(o-2,o)),16)}o+=1,a.action=r.arrayToString(t.slice(o-1,o)),i=parseInt(a.action,16),a.payload=r.arrayToString(t.slice(o,t.length));const u=t.slice(o,t.length);let p=c;1===i&&(p=c.filter(e=>"status_writable"===e.type));const v=JSON.parse(JSON.stringify(p)),g=Math.ceil(p.length/8);let y=u.slice(0,g),_=u.slice(g,u.length);3!==i&&4!==i||(y=new Array(g).fill(255),_=u);let D="";y.map(e=>(D+=r.fillString(e.toString(2),8),null)),i>=17&&i<=20&&(p=p.filter((e,t)=>{const i=D.length-1-t;return"1"===D[i]})),"0090"===a.cmd||"0093"===a.cmd?(n="App 透传数据到 Dev",s="APP2DEV"):"0091"===a.cmd||"0094"===a.cmd?(n="Dev 收到控制命令后应答到 App",s="DEV2APP"):(n="非法数据",s="UNKNOW");let m={};switch(i){case 1:n="App 下发数据到 Dev",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 2:return n="App 下发查询指令到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 3:n="Dev 回复查询指令到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 4:n="Dev 上报状态到 App",m=h({attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_,accumulate:!0});break;case 5:return n="App 透传数据到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 6:return n="Dev 透传数据到 App",{kvData:null,rawData:a,message:n,messageType:s};case 7:return n="App 下发控制子设备",{kvData:null,rawData:a,message:n,messageType:s};case 8:return n="App 读取子设备数据",{kvData:null,rawData:a,message:n,messageType:s};case 9:return n="Dev 中控回复ACK",{kvData:null,rawData:a,message:n,messageType:s};case 10:return n="子设备上报状态到 App",{kvData:null,rawData:a,message:n,messageType:s};case 11:return n="App 下发添加子设备指令",{kvData:null,rawData:a,message:n,messageType:s};case 12:return n="App 下发删除子设备",{kvData:null,rawData:a,message:n,messageType:s};case 13:return n="App 获取中控子设备列表",{kvData:null,rawData:a,message:n,messageType:s};case 14:return n="中控响应字设备查询到 App",{kvData:null,rawData:a,message:n,messageType:s};case 15:return n="子设备列表变更通知到 App",{kvData:null,rawData:a,message:n,messageType:s};case 16:return n="Dev 子设备上下线状态变更通知",{kvData:null,rawData:a,message:n,messageType:s};case 17:n="App 下发变长数据到 Dev",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 18:return n="App 下发变长查询到 Dev",{kvData:null,rawData:a,message:n,messageType:s};case 19:n="Dev 变长回复查询指令到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 20:n="Dev 变长上报状态到 App",m=f({type:"ALL",attrs:v,activeAttrs:p,flagString:D.split("").reverse().join(""),cmdData:_}).cmd;break;case 114:return n="App 向网关发送数据",{kvData:null,rawData:a,message:n,messageType:s};case 115:return n="Dev 网关上报数据到 App",{kvData:null,rawData:a,message:n,messageType:s};case 116:return n="App 通知网关删除子设备",{kvData:null,rawData:a,message:n,messageType:s};default:return{kvData:null,rawData:a,message:n,messageType:s}}return 0===c.length?{kvData:null,rawData:a,message:n,messageType:s}:{kvData:m,rawData:a,message:n,messageType:s}}({config:(yield i).entities[0].attrs,data:e});return s.kvData&&(s.kvData=yield p(null==s?void 0:s.kvData,t,"object")),s}return null}));t.pack=(e,t)=>s(void 0,void 0,void 0,(function*(){const i=yield n.default.getConfigFile(t);if(i){const t="var_len"===i.protocolType;return l({data:e,config:(yield i).entities[0].attrs,isAdaptiveDatapoint:t})}return null}));t.padBoradcastData=e=>{const t=[0].concat([0,147]).concat([0,0,0,0]).concat(e),i=d(t);return r.arrayToString([0,0,0,3].concat(i).concat(t))};t.formatEnum=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const r=yield n.default.getAttrItem(t,s);if(r&&"enum"===r.data_type){if("int"===i&&"string"==typeof e[s]){const t=r.enum.findIndex(t=>t===e[s]);e[s]=t||0}"string"===i&&"number"==typeof e[s]&&(e[s]=r.enum[e[s]])}}return e}));const p=(e,t,i)=>s(void 0,void 0,void 0,(function*(){for(let s in e){const a=yield n.default.getAttrItem(t,s);a&&"binary"===a.data_type&&("object"===i&&"string"==typeof e[s]&&(e[s]=r.hexStrint2byte(e[s])),"string"===i&&"object"==typeof e[s]&&(e[s]=r.arrayToString(e[s])))}return e}));t.formatBinary=p},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});t.default=class{constructor(){this.listenerMap={},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}}}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(4),n=i(2);class r extends s.default{constructor(e){super(e)}}r.pack=(e,t)=>{const i=[],[s,r]=n.formatCodesFromStr(e),[a,c]=n.formatCodesFromStr(t),o=[0].concat([0,1],r,s,c,a);let l=o.length;for(;l>0;)i.push(l),l-=255;const d=[0,0,0,3].concat(i).concat(o),u=new ArrayBuffer(d.length),h=new Uint8Array(u);for(let e=0;e<u.byteLength;e++)h[e]=d[e];return h},t.default=r},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(9),r=i(5),a=i(30),c=i(3);t.default=class{constructor(e,t,i,o){this.ssid="",this.password="",this.specialProductKeys=[],this.disableSearchDevice=!1,this.specialProductKeySecrets=[],this.timeoutHandler=null,this.setDeviceOnboardingDeployRej=()=>{},this.cleanTimeout=()=>{this.disableSearchDevice=!0,this.timeoutHandler&&clearTimeout(this.timeoutHandler),this.timeoutHandler=null},this.stopDeviceOnboardingDeploy=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:r.default.GIZ_SDK_ONBOARDING_STOPPED}),this.cleanTimeout()},this.hasTimeoutHandler=e=>!!this.timeoutHandler&&(e&&e({success:!1,err:r.default.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING}),!0),this.handleTimeout=()=>{this.setDeviceOnboardingDeployRej&&this.setDeviceOnboardingDeployRej({success:!1,err:{errorCode:r.default.CONFIG_TIME_OUT,errorMessage:"time out"}}),this.timeoutHandler=null},this.searchDevice=({ssid:e,password:t})=>new Promise((i,o)=>{c.default.debug("GIZ_SDK: 开始大循环搜索设备");const l=()=>s(this,void 0,void 0,(function*(){var s;if(this.hasTimeoutHandler())try{const d=yield a.checkDeviceRegister({SSID:e,password:t,productKeys:this.specialProductKeys});if((null===(s=d.err)||void 0===s?void 0:s.errorCode)===r.default.GIZ_OPENAPI_TOKEN_INVALID.errorCode)return void o({success:!1,err:r.default.GIZ_OPENAPI_TOKEN_INVALID});d.err||0===d.data.length?(c.default.debug("GIZ_SDK: 大循环没有发现设备"),yield n.default(1500),!this.disableSearchDevice&&l()):(c.default.debug("GIZ_SDK: 大循环搜索到设备",d),i({success:!0,data:d.data}))}catch(e){yield n.default(3e3),!this.disableSearchDevice&&l()}}));l()}),this.initDeviceOnboardingDeploy=(e,t)=>{this.setDeviceOnboardingDeployRej=e,this.disableSearchDevice=!1},this.startTimeoutTimer=e=>{this.timeoutHandler=setTimeout(this.handleTimeout,1e3*e)},this.bindDevices=e=>(c.default.log("GIZ_SDK: start bind device"),new Promise((t,i)=>s(this,void 0,void 0,(function*(){const s=e.map(e=>{const t=this.specialProductKeys.findIndex(t=>e.productKey===t);if(-1===t)return;const i=this.specialProductKeySecrets[t];return a.bindMac({mac:e.mac,productKey:e.productKey,productSecret:i})});try{const n=yield Promise.all(s),a=e.filter((e,t)=>{const i=n[t];return i&&i.success});a.length>0?(c.default.log("GIZ_SDK: bind device success",a),t({success:!0,data:a})):(c.default.log("GIZ_SDK: bind device error",n),i({success:!1,data:e,err:r.default.GIZ_SDK_BIND_DEVICE_FAILED}))}catch(e){i(e)}})))),this.ssid=e,this.password=t,this.specialProductKeys=i,this.specialProductKeySecrets=o}}},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(12),r=i(63),a=i(64),c=i(11);t.getBindingList=()=>s(void 0,void 0,void 0,(function*(){const e=yield n.default("/app/bindings?show_disabled=0&limit=1000&skip=0",{method:"GET"});if(e.success){return{success:!0,data:e.data.devices.map(e=>({productKey:e.product_key,mac:e.mac,did:e.did,host:e.host,port_s:e.port_s,port:e.port,ws_port:e.ws_port,wss_port:e.wss_port,passcode:e.passcode,isBleOnline:!1,isLanOnline:!1,connectType:"NONE",name:e.dev_alias,isBind:!0,isOnline:e.is_online}))}}return{success:!1,err:e.err}})),t.bindMac=function({mac:e,productKey:t,productSecret:i,alias:r,beOwner:c}){return s(this,void 0,void 0,(function*(){const s={mac:e,product_key:t,dev_alias:r,set_owner:c},{Signature:o,timestamp:l}=a.psKeySign(i);return yield n.default("/app/bind_mac",{method:"POST",data:s,headers:{"X-Gizwits-Signature":o,"X-Gizwits-Timestamp":l}})}))},t.unbindDevice=function({devices:e}){return s(this,void 0,void 0,(function*(){return yield n.default("/app/bindings",{method:"DELETE",data:{devices:e.map(e=>({did:e.did}))}})}))},t.checkDeviceRegister=function({SSID:e,password:t,productKeys:i}){return s(this,void 0,void 0,(function*(){const s=r.default({SSID:e,password:t,pks:i});let a="";return s.map(e=>{a+=`${e},`}),a=a.substring(0,a.length-1),yield n.default(`/app/device_register?random_codes=${a}`,{method:"get"})}))},t.safeRegister=function({productKey:e,productSecret:t,mac:i,passcode:r,gwDid:a,isReset:o}){return s(this,void 0,void 0,(function*(){let s=`is_reset=${o?1:0}&mac=${i}&passcode=${r}`;a&&(s+=`&gw_did=${a}`);const l=c.enc.Hex.parse(t),d=c.enc.Hex.parse(""),u=c.enc.Utf8.parse(s),h=c.AES.encrypt(u,l,{iv:d,mode:c.mode.ECB,padding:c.pad.Pkcs7}).ciphertext.toString().toUpperCase(),f=yield n.default(`/dev/${e}/device`,{method:"POST",data:{data:h},headers:{"content-type":"application/x-www-form-urlencoded"}},!1);return f.success?{success:!0,data:{successDevices:[],failedDevices:[]}}:{success:!1,err:f.err}}))},t.editBindInfo=function({name:e,remark:t,did:i}){return s(this,void 0,void 0,(function*(){const s={};return e&&(s.dev_alias=e),t&&(s.remark=t),yield n.default(`/app/bindings/${i}`,{method:"PUT",data:s},!0)}))}},function(e,t){},function(e,t,i){"use strict";var s=this&&this.__awaiter||function(e,t,i,s){return new(i||(i=Promise))((function(n,r){function a(e){try{o(s.next(e))}catch(e){r(e)}}function c(e){try{o(s.throw(e))}catch(e){r(e)}}function o(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,c)}o((s=s.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const n=i(18),r=i(19),a=i(61),c=i(62),o=i(65),l=i(3),d=i(17),u=i(66),h=i(30),f=i(10),p=i(16),v=i(26),g=i(2),y=i(67),_=i(4),D=i(69),m=i(70),S=i(9),b=i(71);t.default=class{constructor({appID:e,appSecret:t,productInfo:i,cloudServiceInfo:r,token:a,uid:y,offlineThreshold:w}){this.version="3.1.11-1",this.listenerMap={},this.keepScanTimer=null,this._deviceList=[],this._bleDevices=[],this._lanDevices=[],this.productInfo=[],this.syncDataCallBack=null,this.syncTotalNum=0,this.syncCurrnetNum=0,this.syncDataTimoutTimer=null,this.SYNC_TIMEOUT=24e4,this.handleBleError=e=>{this.listenerMap.onBleHandleError&&this.listenerMap.onBleHandleError.map(t=>{t(e)})},this.handleBleDevices=e=>{this.bleDevices=e},this.handleLanDevices=e=>{this.lanDevices=e},this.handleLanDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.mac===e);if(i){const e=yield v.unpack(g.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})})}})),this.handleBleDeviceData=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>t.bleDeviceID===e.deviceId);if(i){const s=g.hexStrint2byte(t);switch(new _.default(s).cmd){case"0093":case"0094":case"0090":case"0091":{if(console.debug("handleBleDeviceData",t,i),i.passcode){const e=this.productInfo.find(e=>e.productKey===i.productKey);if(e){const s=parseInt(`${Date.now()/1e3}`,10);m.uploadP0({device:i,data:[{raw:t,created_at:s}],productSecret:e.productSecret}).then(e=>{l.default.debug("设备上报数据:timestemp",new Date(1e3*s).toLocaleString(),e)})}}const e=yield v.unpack(g.hexStrint2byte(t),i.productKey);(null==e?void 0:e.kvData)&&this.listenerMap.GizDeviceAttrsNotifications&&this.listenerMap.GizDeviceAttrsNotifications.map(t=>{t({device:i,data:null==e?void 0:e.kvData})});break}case"0052":{const t=new D.RequestSync(s);if(l.default.debug("设备回复是否允许同步, state:",t.state),this.syncDataLengthCallback&&this.syncDataLengthCallback({success:0==t.state,data:t.len}),!this.syncDataCallBack)break;0===t.state?(this.syncCurrnetNum=0,this.syncTotalNum=t.len,this.syncDataCallBack({event:"SYNC_START",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),l.default.debug("查询第一条离线数据"),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.SyncPackage.pack(0)).buffer)):(l.default.debug("设备返回状态为1,同步失败"),this.syncDataCallBack({event:"SYNC_FAIL"}));break}case"0054":{if(!this.syncDataCallBack)break;l.default.debug("设备上报离线数据");const t=new D.SyncPackage(s),i=D.DeletePackage.pack(t.id);l.default.debug("设备上报离线数据:payload",t.payload);try{l.default.debug("设备上报离线数据:timestemp",t.timestemp,new Date(1e3*t.timestemp).toLocaleString())}catch(e){}const n=this.productInfo.find(e=>e.productKey===this.syncDevice.productKey);if(n){const e=yield m.uploadP0({device:this.syncDevice,data:[{raw:g.arrayToString(t.payload),created_at:t.timestemp}],productSecret:n.productSecret});l.default.debug("上传离线数据结果",e)}this.syncCurrnetNum+=1,this.syncDataCallBack({event:"SYNC_PROGRESS",totalNum:this.syncTotalNum,currentNum:this.syncCurrnetNum}),l.default.debug("通知设备删除:",t.id),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(i).buffer),yield S.default(100),t.id<this.syncTotalNum-1?(l.default.debug("查询新数据:",t.id+1),yield this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.SyncPackage.pack(t.id+1)).buffer)):(l.default.debug("send cancel sync to device"),this.bleHandle.write(e.deviceId,f.numberArray2Uint8Array(D.CancelSync.pack()).buffer),this.syncDataCallBack({event:"SYNC_END"}),this.cleanSyncDeviceData());break}case"0058":{if(!this.syncDataCallBack)break;const e=new D.CancelSync(s);l.default.debug("设备上报停止同步 state:",e.state),0===e.state?this.syncDataCallBack({event:"SYNC_END"}):this.syncDataCallBack({event:"SYNC_FAIL"}),this.cleanSyncDeviceData();break}}}})),this.handleSocketDeviceData=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>t.did===e.did);if(t){if(e.attrs&&null!=e.attrs.is_online){const i=e.attrs.is_online;this.setDeviceMeta(t,"isOnline",i)}this.listenerMap.GizDeviceAttrsNotifications&&(e.attrs&&(e.attrs=yield v.formatEnum(e.attrs,t.productKey,"int")),this.listenerMap.GizDeviceAttrsNotifications.map(i=>{i(Object.assign({device:t},"attrs"in e?{data:e.attrs}:{raw:e.raw}))}))}})),this.handleSocketStatus=(e,t)=>{const i=this.allDevices.filter(t=>e.includes(t.did)&&"WAN"===t.connectType);l.default.log("handleSocketStatus",e,t),i.forEach(e=>{this.setDeviceMeta(e,"connectType",t?"WAN":"NONE")})},this.notiDeviceList=()=>{var e,t;null===(e=this.listenerMap.GizDeviceListNotifications)||void 0===e||e.map(e=>{e(this.allDevices)}),null===(t=this.listenerMap.onScanListChange)||void 0===t||t.map(e=>{e(this.bleScanDevice)})},this.initLan=()=>{try{this.lanHandle.init(),this.lanHandle.addEventListener("GizLanDeviceList",this.handleLanDevices),this.lanHandle.addEventListener("GizLanDeviceData",this.handleLanDeviceData)}catch(e){l.default.error("init lan error",e)}},this.startAutoScan=()=>{this.keepScanTimer||(this.keepScanTimer=setInterval(()=>s(this,void 0,void 0,(function*(){this.bleHandle.startScan(e=>{this.bleDevices=e},-1)})),9e3),this.bleHandle.startScan(e=>{this.bleDevices=e},-1))},this.stopAutoScan=()=>{this.keepScanTimer&&clearInterval(this.keepScanTimer),this.bleHandle.stopScan()},this.setDeviceMeta=(e,t,i,s=!1)=>{const n=this.allDevices.find(t=>t.mac===e.mac);n&&0!==this.allDevices.length&&(e[t]!==i||s)&&(n[t]=i,this.notiDeviceList())},this.getVersion=()=>({success:!0,data:this.version}),this.initBle=()=>s(this,void 0,void 0,(function*(){const e=yield this.bleHandle.checkPermission();return e.success?(this.bleHandle.addEventListener("GizBleDeviceData",this.handleBleDeviceData),this.bleHandle.addEventListener("GizBleDeviceList",this.handleBleDevices),this.bleHandle.addEventListener("GizBleError",this.handleBleError),l.default.debug("init BLE succcess",e),{success:!0}):(l.default.error("init BLE Error",new Error(JSON.stringify(e))),{success:!1,err:d.errorCode.GIZ_SDK_BLE_BLUETOOTH_FUNCTION_NOT_TURNED_ON})})),this.scanBleDevice=e=>s(this,void 0,void 0,(function*(){return this.bleHandle.scanList=[],{success:!0,data:(yield this.bleHandle.startScan(e=>{this.bleDevices=e},e)).scanList}})),this.write=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType){const{data:e,raw:s}=yield v.pack(t,i.productKey);switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,s.cmd);case"BLE":return e?yield this.bleHandle.write(i.bleDeviceID,f.numberArray2Uint8Array(e).buffer):{success:!1};case"WAN":{const e=yield v.formatEnum(t,i.productKey,"string");return this.socketHandle.writeData(i,e)}case"LAN":return this.lanHandle.write(i,f.numberArray2Uint8Array(e).buffer)}}return{success:!1}})),this.writeRaw=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if("NONE"!==i.connectType)switch(i.connectType){case"BLE_BROADCAST":return yield this.bleHandle.writeBoradcast(i.bleDeviceID,t);case"BLE":return t?yield this.bleHandle.write(i.bleDeviceID,f.numberArray2Uint8Array(t).buffer):{success:!1};case"WAN":return this.socketHandle.send(i.did,t);case"LAN":return this.lanHandle.write(i,f.numberArray2Uint8Array(t).buffer)}return{success:!1}})),this.setDeviceTimeStamp=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};const i=b.default.pack();switch(t.connectType){case"BLE":return this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer)}return{success:!1,message:"the connectType not support set timestamp"}})),this.syncDeviceData=(e,t=(()=>{}))=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};if(!i.isBind)return{success:!1,message:"Only the bound devices are supported"};if(this.syncDevice)return{success:!1,message:"Synchronizing"};switch(this.syncDevice=Object.assign({},i),i.connectType){case"BLE":{l.default.debug("start syncDeviceData",e),this.syncDataCallBack=t,this.syncDataTimoutTimer=setTimeout(()=>{this.syncDataCallBack({event:"SYNC_FAIL",message:"sync timeout"}),this.cleanSyncDeviceData()},this.SYNC_TIMEOUT);const i=D.RequestSync.pack();return l.default.debug("sent RequestSync data"),this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer)}}return{success:!1,message:"the connectType not support sync data"}})),this.queryNeedSyncDataLength=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));if(!t)return{success:!1,message:"target is undefind"};if(!t.isBind)return{success:!1,message:"Only the bound devices are supported"};switch(t.connectType){case"BLE":{const i=D.RequestSync.pack();return this.syncDevice=Object.assign({},t),l.default.debug("sent RequestSync data len"),this.bleHandle.write(e.bleDeviceID,f.numberArray2Uint8Array(i).buffer),new Promise(e=>{this.syncDataLengthCallback=e,setTimeout(()=>{try{e({success:!1,message:"timeout"})}catch(e){}},3e3)})}}return{success:!1,message:"the connectType not support sync data"}})),this.cancelSyncDeviceData=()=>s(this,void 0,void 0,(function*(){this.cleanSyncDeviceData()})),this.cleanSyncDeviceData=()=>{this.syncDataCallBack&&(this.syncDataCallBack({event:"SYNC_CANCEL"}),this.syncDataCallBack=null),this.syncCurrnetNum=0,this.syncTotalNum=0,this.syncDevice=null,this.syncDataTimoutTimer&&clearTimeout(this.syncDataTimoutTimer)},this.getProductConfig=e=>s(this,void 0,void 0,(function*(){const t=yield p.default.getConfigFile(e);return t?{success:!0,data:t}:{success:!1}})),this.stopScanBleDevice=()=>{this.bleHandle.stopScan()},this.login=e=>s(this,void 0,void 0,(function*(){var t,i;const s=yield u.AnonymousLogin({uid:e});return s.success&&(n.setGlobalData("token",null===(t=s.data)||void 0===t?void 0:t.token),n.setGlobalData("uid",null===(i=s.data)||void 0===i?void 0:i.uid),this.socketHandle.updateToken({token:s.data.token,uid:s.data.uid})),s})),this.getDeviceStatus=(e,t)=>s(this,void 0,void 0,(function*(){const i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return{success:!1,message:"target is undefind"};switch(i.connectType){case"BLE":return yield this.bleHandle.getDeviceStatus(i.bleDeviceID,i.productKey,i.rootDeviceId,t);case"WAN":return this.socketHandle.readStatus(i,t);default:return{success:!1,message:"Device connectType is unsupported"}}})),this.subscribe=(e,t,i=!0)=>s(this,void 0,void 0,(function*(){l.default.debug("subscribe device:",e);let i=this.allDevices.find(t=>f.isSameDevice(t,e));if(!i)return l.default.warn("Device Target Not Found"),l.default.warn("current devices ",this.allDevices),{success:!1,message:"device not found"};if("BLE_BROADCAST"===i.connectType)return{success:!0};const s=f.getFirstConnectType(i,t);switch("NONE"!==i.connectType&&i.connectType!==s&&(yield this.unSubscribe(i)),s){case"BLE":{const e=yield this.bleHandle.connectDevice(i.bleDeviceID);return e.success&&(this.setDeviceMeta(i,"connectType","BLE",!0),setTimeout(()=>{this.setDeviceTimeStamp(i)},250),setTimeout(()=>{this.getDeviceStatus(i)},500)),e}case"WAN":{const t=this.socketHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","WAN",!0),t}case"LAN":{const t=yield this.lanHandle.connectDevice(i);return t.success&&this.setDeviceMeta(e,"connectType","LAN",!0),t}}return{success:!1}})),this.unSubscribe=e=>s(this,void 0,void 0,(function*(){const t=this.allDevices.find(t=>f.isSameDevice(t,e));switch(t.connectType){case"BLE":{const e=yield this.bleHandle.disConnectDevice(t.bleDeviceID);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"WAN":{const e=this.socketHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}case"LAN":{const e=this.lanHandle.disConnectDevice(t);return e.success&&this.setDeviceMeta(t,"connectType","NONE",!0),e}}return{success:!1}})),this.bindRemoteDevice=({mac:e,productKey:t,alias:i,beOwner:n})=>s(this,void 0,void 0,(function*(){const s=f.getProductInfoThroughPK(t,this.productInfo);if(s){const r=yield h.bindMac({mac:e,productKey:t,productSecret:s.productSecret,alias:i,beOwner:n});return this.getBindingList(),r}return{success:!1,err:d.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.unbindDevice=({devices:e})=>s(this,void 0,void 0,(function*(){const t=yield h.unbindDevice({devices:e});return t.success&&this.getBindingList(),t})),this.deviceSafetyRegister=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!1})})),this.deviceSafetyUnbind=({mac:e,productKey:t})=>s(this,void 0,void 0,(function*(){return yield this.deviceSafetyApi({mac:e,productKey:t,isReset:!0})})),this.setDeviceOnboardingDeploy=({ssid:e,password:t,mode:i=0,timeout:n,isBind:r=!0,softAPSSIDPrefix:a})=>s(this,void 0,void 0,(function*(){if(this.currentWifiConfigHandle)return{success:!1,err:d.errorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING};const s=(new Date).getTime();l.default.debug("GIZ_SDK: 配网开始时间:"+s);try{switch(i){case 0:{this.currentWifiConfigHandle=new c.default(e,t,this.specialProductKeys,this.specialProductKeySecrets);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const o=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+o),l.default.debug("GIZ_SDK: 配网用时:"+(o-s)),i}case 3:{this.currentWifiConfigHandle=new o.default(e,t,this.specialProductKeys,this.specialProductKeySecrets,this.bleHandle);const i=yield this.currentWifiConfigHandle.setDeviceOnboardingDeploy({timeout:n,isBind:r,softAPSSIDPrefix:a});this.currentWifiConfigHandle=null;const c=(new Date).getTime();return l.default.debug("GIZ_SDK: 配网结束时间:"+c),l.default.debug("GIZ_SDK: 配网用时:"+(c-s)),i}}}catch(e){return l.default.error("GIZ_SDK: setDeviceOnboardingDeploy",new Error(JSON.stringify(e))),e.err&&e.err.errorCode?e:{success:!1,err:d.errorCode.GIZ_SDK_OTHERWISE}}finally{this.currentWifiConfigHandle=null}})),this.setDomain=e=>{const t=e&&e.openAPIInfo||"api.gizwits.com",i=Object.assign(Object.assign({},e||{}),{openAPIInfo:t});n.setGlobalData("cloudServiceInfo",i)},this.deviceSafetyApi=({mac:e,productKey:t,isReset:i})=>s(this,void 0,void 0,(function*(){const s=f.getProductInfoThroughPK(t,this.productInfo);return s?yield h.safeRegister({productKey:t,productSecret:s.productSecret,mac:e,isReset:i,passcode:"1234567890"}):{success:!1,err:d.errorCode.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIFY}})),this.getBindingList=()=>s(this,void 0,void 0,(function*(){const e=yield h.getBindingList();return this.deviceList=e.data||[],e})),this.getDevices=()=>s(this,void 0,void 0,(function*(){return yield this.getBindingList(),{success:!0,data:this.allDevices}})),this.stopDeviceOnboardingDeploy=()=>{this.currentWifiConfigHandle&&(this.currentWifiConfigHandle.stopDeviceOnboardingDeploy(),this.currentWifiConfigHandle=null)},this.setLogLevel=e=>l.default.setLogLevel(e),this.renameDevice=(e,t)=>s(this,void 0,void 0,(function*(){return t?e.isBind?yield h.editBindInfo({did:e.did,name:t}):{success:!1,message:"device not bind"}:{success:!1,message:"please input device name"}})),this.removeEventListener=(e,t)=>{if(this.listenerMap[e]){const i=this.listenerMap[e].indexOf(t);if(-1!==i)return this.listenerMap[e].splice(i,1),{success:!0}}return{success:!1}},this.addEventListener=(e,t)=>s(this,void 0,void 0,(function*(){return this.listenerMap[e]||(this.listenerMap[e]=[]),-1===this.listenerMap[e].indexOf(t)&&this.listenerMap[e].push(t),{success:!0}})),this.destory=()=>{this.bleHandle.destory(),this.lanHandle.destory(),this.socketHandle.destory(),this.keepScanTimer&&clearInterval(this.keepScanTimer)},this.productInfo=i,n.setGlobalData("appID",e),n.setGlobalData("appSecret",t),n.setGlobalData("productInfo",i),n.setGlobalData("token",a),n.setGlobalData("uid",y),this.setDomain(r),this.offlineThreshold=w,l.default.debug(`init sdk success, current version: ${this.version}`),this.initLan()}get deviceList(){return this._deviceList}set deviceList(e){this._deviceList=e,this.notiDeviceList()}get bleDevices(){return this._bleDevices}set bleDevices(e){this._bleDevices=e,this.notiDeviceList()}get lanDevices(){return this._lanDevices}set lanDevices(e){this._lanDevices=e,this.notiDeviceList()}get allDevices(){let e=f.merageBleLocalDevices([...this.deviceList],this.bleDevices);e=f.merageLanLocalDevices(e,this.lanDevices),this.bleHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.bleDeviceID===t.deviceId);-1!==i&&(e[i].connectType="BLE")});const t=this.socketHandle._connections;return Object.keys(t).forEach(i=>{const s=t[i];s&&s._subDids.forEach(t=>{const i=e.findIndex(e=>e.did===t);-1!==i&&(e[i].connectType="WAN")})}),this.lanHandle.connectedList.map(t=>{const i=e.findIndex(e=>e.mac===t.mac&&e.productKey===t.productKey);-1!==i&&(e[i].connectType="LAN")}),e}get bleScanDevice(){return this.bleDevices.filter(e=>!0===e.isBleOnline)}get bleHandle(){return this._bleHandle||(this._bleHandle=new r.BleHandle({pks:this.specialProductKeys,offlineThreshold:this.offlineThreshold})),this._bleHandle}get lanHandle(){return this._lanHandle||(this._lanHandle=new y.LanHandle({pks:this.specialProductKeys})),this._lanHandle}get socketHandle(){return this._gizSocket||(this._gizSocket=new a.default({appID:n.getGlobalData("appID"),token:n.getGlobalData("token"),uid:n.getGlobalData("uid")}),this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData),this._gizSocket.subscribeBindingChanged(this.getBindingList),this._gizSocket.subscribeSocketStatus(this.handleSocketStatus)),this._gizSocket}get specialProductKeys(){return this.productInfo.map(e=>{var t;return null!==(t=e.productKey)&&void 0!==t?t:""})}get specialProductKeySecrets(){return this.productInfo.map(e=>{var t;return null!==(t=e.productSecret)&&void 0!==t?t:""})}}},function(e,t,i){"use strict";Object.defineProperty(t,"__esModule",{value:!0});const s=i(11),n=i(22);t.default=e=>{const t=wx.getSystemInfoSync(),i={exception:{values:[{type:"Error",value:e.stack,stacktrace:{},mechanism:{type:"generic",handled:!0}}]},level:"error",event_id:s.MD5(`${(new Date).getTime()}`).toString(),platform:"javascript",sdk:{},timestamp:(new Date).getTime()/1e3,environment:"production",contexts:{device:{},os:{name:t.platform,version:t.version},extra:{}},extra:{message:e.message}};var r={method:"POST",headers:{Connection:"keep-alive","User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/","content-type":"application/json",Accept:"*/*","Sec-Fetch-Site":"cross-site","Sec-Fetch-Mode":"cors","Sec-Fetch-Dest":"empty",Referer:"https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html",Cookie:"__org="},data:JSON.stringify(i)};n.default("https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7",r)}},function(e,t){var i;i=function(){return this}();try{i=i||new Function("return this")()}catch(e){"object"==typeof window&&(i=window)}e.exports=i},function(e,t){},function(e,t,i){var s;e.exports=(s=i(0),function(){if("function"==typeof ArrayBuffer){var e=s.lib.WordArray,t=e.init;(e.init=function(e){if(e instanceof ArrayBuffer&&(e=new Uint8Array(e)),(e instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array)&&(e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),e instanceof Uint8Array){for(var i=e.byteLength,s=[],n=0;n<i;n++)s[n>>>2]|=e[n]<<24-n%4*8;t.call(this,s,i)}else t.apply(this,arguments)}).prototype=e}}(),s.lib.WordArray)},function(e,t,i){var s;e.exports=(s=i(0),function(){var e=s,t=e.lib.WordArray,i=e.enc;function n(e){return e<<8&4278255360|e>>>8&16711935}i.Utf16=i.Utf16BE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n+=2){var r=t[n>>>2]>>>16-n%4*8&65535;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var i=e.length,s=[],n=0;n<i;n++)s[n>>>1]|=e.charCodeAt(n)<<16-n%2*16;return t.create(s,2*i)}},i.Utf16LE={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],r=0;r<i;r+=2){var a=n(t[r>>>2]>>>16-r%4*8&65535);s.push(String.fromCharCode(a))}return s.join("")},parse:function(e){for(var i=e.length,s=[],r=0;r<i;r++)s[r>>>1]|=n(e.charCodeAt(r)<<16-r%2*16);return t.create(s,2*i)}}}(),s.enc.Utf16)},function(e,t,i){var s,n,r;e.exports=(r=i(0),n=(s=r).lib.WordArray,s.enc.Base64url={stringify:function(e,t=!0){var i=e.words,s=e.sigBytes,n=t?this._safe_map:this._map;e.clamp();for(var r=[],a=0;a<s;a+=3)for(var c=(i[a>>>2]>>>24-a%4*8&255)<<16|(i[a+1>>>2]>>>24-(a+1)%4*8&255)<<8|i[a+2>>>2]>>>24-(a+2)%4*8&255,o=0;o<4&&a+.75*o<s;o++)r.push(n.charAt(c>>>6*(3-o)&63));var l=n.charAt(64);if(l)for(;r.length%4;)r.push(l);return r.join("")},parse:function(e,t=!0){var i=e.length,s=t?this._safe_map:this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var a=0;a<s.length;a++)r[s.charCodeAt(a)]=a}var c=s.charAt(64);if(c){var o=e.indexOf(c);-1!==o&&(i=o)}return function(e,t,i){for(var s=[],r=0,a=0;a<t;a++)if(a%4){var c=i[e.charCodeAt(a-1)]<<a%4*2,o=i[e.charCodeAt(a)]>>>6-a%4*2,l=c|o;s[r>>>2]|=l<<24-r%4*8,r++}return n.create(s,r)}(e,i,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",_safe_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"},r.enc.Base64url)},function(e,t,i){var s,n,r,a,c,o;e.exports=(o=i(0),i(20),n=(s=o).lib.WordArray,r=s.algo,a=r.SHA256,c=r.SHA224=a.extend({_doReset:function(){this._hash=new n.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var e=a._doFinalize.call(this);return e.sigBytes-=4,e}}),s.SHA224=a._createHelper(c),s.HmacSHA224=a._createHmacHelper(c),o.SHA224)},function(e,t,i){var s,n,r,a,c,o,l,d;e.exports=(d=i(0),i(13),i(21),n=(s=d).x64,r=n.Word,a=n.WordArray,c=s.algo,o=c.SHA512,l=c.SHA384=o.extend({_doReset:function(){this._hash=new a.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var e=o._doFinalize.call(this);return e.sigBytes-=16,e}}),s.SHA384=o._createHelper(l),s.HmacSHA384=o._createHmacHelper(l),d.SHA384)},function(e,t,i){var s;e.exports=(s=i(0),i(13),function(e){var t=s,i=t.lib,n=i.WordArray,r=i.Hasher,a=t.x64.Word,c=t.algo,o=[],l=[],d=[];!function(){for(var e=1,t=0,i=0;i<24;i++){o[e+5*t]=(i+1)*(i+2)/2%64;var s=(2*e+3*t)%5;e=t%5,t=s}for(e=0;e<5;e++)for(t=0;t<5;t++)l[e+5*t]=t+(2*e+3*t)%5*5;for(var n=1,r=0;r<24;r++){for(var c=0,u=0,h=0;h<7;h++){if(1&n){var f=(1<<h)-1;f<32?u^=1<<f:c^=1<<f-32}128&n?n=n<<1^113:n<<=1}d[r]=a.create(c,u)}}();var u=[];!function(){for(var e=0;e<25;e++)u[e]=a.create()}();var h=c.SHA3=r.extend({cfg:r.cfg.extend({outputLength:512}),_doReset:function(){for(var e=this._state=[],t=0;t<25;t++)e[t]=new a.init;this.blockSize=(1600-2*this.cfg.outputLength)/32},_doProcessBlock:function(e,t){for(var i=this._state,s=this.blockSize/2,n=0;n<s;n++){var r=e[t+2*n],a=e[t+2*n+1];r=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),a=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),(A=i[n]).high^=a,A.low^=r}for(var c=0;c<24;c++){for(var h=0;h<5;h++){for(var f=0,p=0,v=0;v<5;v++)f^=(A=i[h+5*v]).high,p^=A.low;var g=u[h];g.high=f,g.low=p}for(h=0;h<5;h++){var y=u[(h+4)%5],_=u[(h+1)%5],D=_.high,m=_.low;for(f=y.high^(D<<1|m>>>31),p=y.low^(m<<1|D>>>31),v=0;v<5;v++)(A=i[h+5*v]).high^=f,A.low^=p}for(var S=1;S<25;S++){var b=(A=i[S]).high,w=A.low,k=o[S];k<32?(f=b<<k|w>>>32-k,p=w<<k|b>>>32-k):(f=w<<k-32|b>>>64-k,p=b<<k-32|w>>>64-k);var B=u[l[S]];B.high=f,B.low=p}var I=u[0],C=i[0];for(I.high=C.high,I.low=C.low,h=0;h<5;h++)for(v=0;v<5;v++){var A=i[S=h+5*v],x=u[S],E=u[(h+1)%5+5*v],L=u[(h+2)%5+5*v];A.high=x.high^~E.high&L.high,A.low=x.low^~E.low&L.low}A=i[0];var T=d[c];A.high^=T.high,A.low^=T.low}},_doFinalize:function(){var t=this._data,i=t.words,s=(this._nDataBytes,8*t.sigBytes),r=32*this.blockSize;i[s>>>5]|=1<<24-s%32,i[(e.ceil((s+1)/r)*r>>>5)-1]|=128,t.sigBytes=4*i.length,this._process();for(var a=this._state,c=this.cfg.outputLength/8,o=c/8,l=[],d=0;d<o;d++){var u=a[d],h=u.high,f=u.low;h=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8),f=16711935&(f<<8|f>>>24)|4278255360&(f<<24|f>>>8),l.push(f),l.push(h)}return new n.init(l,c)},clone:function(){for(var e=r.clone.call(this),t=e._state=this._state.slice(0),i=0;i<25;i++)t[i]=t[i].clone();return e}});t.SHA3=r._createHelper(h),t.HmacSHA3=r._createHmacHelper(h)}(Math),s.SHA3)},function(e,t,i){var s;e.exports=(s=i(0),
2
2
  /** @preserve
3
3
  (c) 2012 by Cédric Mesnil. All rights reserved.
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini_program_gizwits_sdk",
3
- "version": "3.2.18",
3
+ "version": "3.2.19",
4
4
  "description": "修正socket的返回机制",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
package/src/sdk.ts CHANGED
@@ -366,7 +366,6 @@ class GizwitsMiniSDK {
366
366
  };
367
367
 
368
368
  private handleBleDevices = (devices: IDevice[]) => {
369
- GizLog.log('handleBleDevices', devices);
370
369
  this.bleDevices = devices;
371
370
  // this.notiDeviceList();
372
371
  };
@@ -412,17 +411,18 @@ class GizwitsMiniSDK {
412
411
  if (target.passcode) {
413
412
  const productConfig = this.productInfo.find(item => item.productKey === target.productKey)
414
413
  if (productConfig) {
414
+ const uploadTime = parseInt(`${Date.now() / 1000}`, 10)
415
415
  uploadP0({
416
416
  device: target,
417
417
  data: [
418
418
  {
419
419
  raw: hexString,
420
- created_at: parseInt(`${Date.now() / 1000}`, 10)
420
+ created_at: uploadTime
421
421
  }
422
422
  ],
423
423
  productSecret: productConfig.productSecret,
424
424
  }).then(data => {
425
- console.debug('uploadP0 res', data)
425
+ GizLog.debug("设备上报数据:timestemp", new Date(uploadTime * 1000).toLocaleString(), data)
426
426
  })
427
427
  }
428
428
 
@@ -477,7 +477,11 @@ class GizwitsMiniSDK {
477
477
  const syncPackageData = new SyncPackage(bleBytesData)
478
478
  const deletePackageCmd = DeletePackage.pack(syncPackageData.id)
479
479
  GizLog.debug("设备上报离线数据:payload", syncPackageData.payload)
480
- GizLog.debug("设备上报离线数据:timestemp", syncPackageData.timestemp)
480
+ try {
481
+ GizLog.debug("设备上报离线数据:timestemp", syncPackageData.timestemp, new Date(syncPackageData.timestemp * 1000).toLocaleString())
482
+ } catch (error) {
483
+
484
+ }
481
485
 
482
486
  const productConfig = this.productInfo.find(item => item.productKey === this.syncDevice.productKey)
483
487
  if(productConfig) {