lavva.exalushome.extalife
Version:
Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system
2 lines • 9.97 kB
JavaScript
"use strict";(self.webpackChunklavva_exalushome_extalife=self.webpackChunklavva_exalushome_extalife||[]).push([[484],{8484:(e,t,n)=>{n.r(t),n.d(t,{SbrConfigService:()=>f});var o=n(6823),r=n(6030);class i{constructor(){this.DeviceGuid="",this.TimeInMiliseconds=0,this.ResetOnCrossToOn=!1}}class s{constructor(){this.DeviceGuid="",this.LightDelayInMiliseconds=0}}class a{constructor(){this.DeviceGuid="",this.LightDurationInMiliseconds=0}}var l,c=n(5443),u=n(9595),d=n(4907),h=n(3386),v=n(4756),g=n(4824),y=n(8883),m=function(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{l(o.next(e))}catch(e){i(e)}}function a(e){try{l(o.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}l((o=o.apply(e,t||[])).next())}))};class f{constructor(){this._connection=c.j.Get(u.G.ServiceName),this._logger=c.j.Get(d.g.ServiceName),this._controllerConfigurationService=c.j.Get(h.u.ServiceName)}GetServiceName(){return f.ServiceName}SetAutoCloseTimeAsync(e,t,n){return m(this,void 0,void 0,(function*(){var r;let i=!1;try{if(t<6e4||t>36e5)return new o.ZR(o.Ao.WrongData,"Cannot set auto close time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.");yield this._controllerConfigurationService.EnterConfigurationModeAsync(),i=!0;const s=yield null===(r=this._connection)||void 0===r?void 0:r.SendAndWaitForResponseAsync(new A(e,t,n),8e3,!1);return null==s||null==s.Status?new o.ZR(o.Ao.UnknownError,"Cannot set auto close time - unknown error."):s.Status!==v.nW.OK?new o.ZR(o.Ao.UnknownError,`Cannot set auto close time - controller responded with error code: ${s.Status}.`):new o.ZR(o.Ao.Changed,"Auto close time set successfully.")}catch(e){return new o.ZR(o.Ao.UnknownError,"Cannot get auto close time - unknown error.")}finally{i&&(this._logger.Error(f.ServiceName,"EXIT CONFIGURATION MODE WILL BE FIRED! SetAutoCloseTimeAsync()"),yield this._controllerConfigurationService.ExitConfigurationModeAsync())}}))}GetAutoCloseTimeAsync(e){return m(this,void 0,void 0,(function*(){var t;try{const n=yield null===(t=this._connection)||void 0===t?void 0:t.SendAndWaitForResponseAsync(new w(e),8e3,!1);return(null==n?void 0:n.Status)===v.nW.OK?n.Data:new o.ZR(r.m.UnknownError,"Cannot get auto close time")}catch(e){return new o.ZR(r.m.UnknownError,`Cannot get auto close time error: ${e}`)}}))}SetAlarmLightDelayAsync(e,t){return m(this,void 0,void 0,(function*(){var n;let r=!1;try{if(t<0||t>12e4)return new o.ZR(o.Ao.WrongData,"Cannot set light delay time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.");yield this._controllerConfigurationService.EnterConfigurationModeAsync(),r=!0;const i=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new S(e,t),8e3,!1);return null==i||null==i.Status?new o.ZR(o.Ao.UnknownError,"Cannot set light delay time - unknown error."):i.Status!==v.nW.OK?new o.ZR(o.Ao.UnknownError,`Cannot set light delay time - controller responded with error code: ${i.Status}.`):new o.ZR(o.Ao.Changed,"Light delay set successfully.")}catch(e){return new o.ZR(o.Ao.UnknownError,"Cannot get light delay time - unknown error.")}finally{r&&(this._logger.Error(f.ServiceName,"EXIT CONFIGURATION MODE WILL BE FIRED! SetAlarmLightDelayAsync()"),yield this._controllerConfigurationService.ExitConfigurationModeAsync())}}))}GetAlarmLightDelayAsync(e){return m(this,void 0,void 0,(function*(){var t;try{const n=yield null===(t=this._connection)||void 0===t?void 0:t.SendAndWaitForResponseAsync(new C(e),8e3,!1);return(null==n?void 0:n.Status)===v.nW.OK?n.Data:new o.ZR(r.m.UnknownError,"Cannot get light delay time")}catch(e){return new o.ZR(r.m.UnknownError,`Cannot get auto light delay error: ${e}`)}}))}SetAlarmLightDurationAsync(e,t){return m(this,void 0,void 0,(function*(){var n;let r=!1;try{if(t<0||t>36e5)return new o.ZR(o.Ao.WrongData,"Cannot set alarm light duration time - invalid value. Time must be in range from 60_000 to 3_600_000 ms.");yield this._controllerConfigurationService.EnterConfigurationModeAsync(),r=!0;const i=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new D(e,t),8e3,!1);return null==i||null==i.Status?new o.ZR(o.Ao.UnknownError,"Cannot set alarm light duration time - unknown error."):i.Status!==v.nW.OK?new o.ZR(o.Ao.UnknownError,`Cannot set alarm light duration time - controller responded with error code: ${i.Status}.`):new o.ZR(o.Ao.Changed,"Alarm light duration set successfully.")}catch(e){return new o.ZR(o.Ao.UnknownError,"Cannot get alarm light duration time - unknown error.")}finally{r&&(this._logger.Error(f.ServiceName,"EXIT CONFIGURATION MODE WILL BE FIRED! SetAlarmLightDurationAsync()"),yield this._controllerConfigurationService.ExitConfigurationModeAsync())}}))}GetAlarmLightDurationAsync(e){return m(this,void 0,void 0,(function*(){var t;try{const n=yield null===(t=this._connection)||void 0===t?void 0:t.SendAndWaitForResponseAsync(new p(e),8e3,!1);return(null==n?void 0:n.Status)===v.nW.OK?n.Data:new o.ZR(r.m.UnknownError,"Cannot get light delay time")}catch(e){return new o.ZR(r.m.UnknownError,`Cannot get auto light delay error: ${e}`)}}))}GetServiceInfoAsync(e){return m(this,void 0,void 0,(function*(){var t;try{const n=yield null===(t=this._connection)||void 0===t?void 0:t.SendAndWaitForResponseAsync(new R(e),8e3,!1);return(null==n?void 0:n.Status)===v.nW.OK?n.Data:new o.ZR(r.m.UnknownError,`Cannot get service info, response status: ${null==n?void 0:n.Status}`)}catch(e){return new o.ZR(r.m.UnknownError,`Cannot get service info error: ${e}`)}}))}IsPinSecureSupportedAsync(e){return m(this,void 0,void 0,(function*(){const t=yield c.j.Get(g.OA.ServiceName).GetSoftwareRuntimeInfoAsync(),[n,o]=t.SoftwareVersion.split(".").map((e=>parseInt(e)));return n>=7&&o>=42&&1==e.Number}))}SetPinSecureAsync(e,t,n){return m(this,void 0,void 0,(function*(){try{const r=c.j.Get(y.N7.ServiceName).GetDeviceChannelByChannelId(e.ChannelId);if(null==r)return new o.ZR(o.Ao.WrongData,`Cannot set pin secure - channel with id ${e.ChannelId} not found.`);let i=[];if(i.push({dataId:l.IsEnabledBool.toString(),data:"true"}),t){if(null==n||n.length<4||!/^\d+$/.test(n))return new o.ZR(o.Ao.WrongData,"Cannot set pin secure - invalid pin code, pin code must be at least 4 digits long and contain only digits.");i.push({dataId:l.IsEnabledBool.toString(),data:"true"}),i.push({dataId:l.PinHash.toString(),data:yield this.CreatePinHashAsync(n)})}else i.push({dataId:l.IsEnabledBool.toString(),data:"false"}),i.push({dataId:l.PinHash.toString(),data:""});for(const e of i)yield r.SetCustomDataAsync(e.dataId,e.data);return new o.ZR(o.Ao.Changed,`Pin secure ${t?"enabled":"disabled"}.`)}catch(e){return new o.ZR(o.Ao.UnknownError,"Cannot set pin secure - unknown error.")}}))}GetPinSecureStatusAsync(e){return m(this,void 0,void 0,(function*(){var t,n,i;try{const s=c.j.Get(y.N7.ServiceName).GetDeviceChannelByChannelId(e.ChannelId);return null==s?new o.ZR(r.m.UnknownError,`Cannot get pin secure status - channel with id ${e.ChannelId} not found.`):"true"===(null===(t=s.CustomData)||void 0===t?void 0:t[l.IsEnabledBool.toString()])&&(null!==(i=null===(n=s.CustomData)||void 0===n?void 0:n[l.PinHash.toString()])&&void 0!==i?i:"").length>0}catch(e){return new o.ZR(r.m.UnknownError,"Cannot get pin secure status - unknown error.")}}))}CreatePinHashAsync(e){return m(this,void 0,void 0,(function*(){const t=this.getRandomBytes(16),n=(new TextEncoder).encode(e),o=new Uint8Array(t.length+n.length);o.set(t,0),o.set(n,t.length);const r=yield this.sha256(o);return`${this.bytesToBase64(t)}:${this.bytesToBase64(r)}`}))}getRandomBytes(e){if("undefined"!=typeof globalThis&&globalThis.crypto&&"function"==typeof globalThis.crypto.getRandomValues){const t=new Uint8Array(e);return globalThis.crypto.getRandomValues(t),t}const t=new Uint8Array(e);for(let n=0;n<e;n++)t[n]=Math.floor(256*Math.random());return t}sha256(e){return m(this,void 0,void 0,(function*(){if("undefined"!=typeof globalThis&&globalThis.crypto&&globalThis.crypto.subtle){const t=yield globalThis.crypto.subtle.digest("SHA-256",e);return new Uint8Array(t)}throw new Error("Crypto.subtle not available for SHA-256 hashing")}))}bytesToBase64(e){const t=globalThis.Buffer;if(void 0!==t&&"function"==typeof t.from)return t.from(e).toString("base64");let n="";for(let t=0;t<e.length;t+=32768){const o=e.subarray(t,t+32768);n+=String.fromCharCode.apply(null,Array.from(o))}return btoa(n)}}f.ServiceName="SbrConfigService",function(e){e.IsEnabledBool="IsEnabledBool",e.PinHash="PinHash"}(l||(l={}));class w extends v.CP{constructor(e){super(),this.Resource="/extalife/device/parameters/sbr/autoclosetime",this.Method=v.IT.Get,this.Data=e.GetDevice().Guid}}class A extends v.CP{constructor(e,t,n){super(),this.Resource="/extalife/device/parameters/sbr/autoclosetime",this.Method=v.IT.Put,this.Data=new i,this.Data.DeviceGuid=e.GetDevice().Guid,this.Data.TimeInMiliseconds=t,this.Data.ResetOnCrossToOn=n}}class C extends v.CP{constructor(e){super(),this.Resource="/extalife/device/parameters/sbr/alarmlightdelay",this.Method=v.IT.Get,this.Data=e.GetDevice().Guid}}class S extends v.CP{constructor(e,t){super(),this.Resource="/extalife/device/parameters/sbr/alarmlightdelay",this.Method=v.IT.Put,this.Data=new s,this.Data.DeviceGuid=e.GetDevice().Guid,this.Data.LightDelayInMiliseconds=t}}class p extends v.CP{constructor(e){super(),this.Resource="/extalife/device/parameters/sbr/lightduration",this.Method=v.IT.Get,this.Data=e.GetDevice().Guid}}class D extends v.CP{constructor(e,t){super(),this.Resource="/extalife/device/parameters/sbr/lightduration",this.Method=v.IT.Put,this.Data=new a,this.Data.DeviceGuid=e.GetDevice().Guid,this.Data.LightDurationInMiliseconds=t}}class R extends v.CP{constructor(e){super(),this.Resource="/extalife/device/parameters/sbr/serviceinfo",this.Method=v.IT.Get,this.Data=e.GetDevice().Guid}}}}]);
//# sourceMappingURL=484-exalushome-extalife.bundle.js.map