UNPKG

lavva.exalushome.extalife

Version:

Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system

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