lavva.exalushome.extalife
Version:
Library implementing communication and abstraction layers for ExtaLife API in ExalusHome system
2 lines • 12.8 kB
JavaScript
"use strict";(self.webpackChunklavva_exalushome_extalife=self.webpackChunklavva_exalushome_extalife||[]).push([[647],{6532:(t,e,n)=>{n.d(e,{W:()=>o,_:()=>r});class r{constructor(t){this.DeviceGuid="",this.DeviceGuid=t}}class o{constructor(t,e){this.DeviceGuid="",this.Channel=0,this.DeviceGuid=t,this.Channel=e}}},9899:(t,e,n)=>{n.d(e,{KR:()=>o,M5:()=>s,NL:()=>i,OL:()=>u,Qk:()=>a,qp:()=>r});class r{constructor(){this._hours=0,this._minutes=0,this._seconds=0,this._raw=0}get Raw(){return this._raw}get Hours(){return this._hours}set Hours(t){this._hours=t}get Minutes(){return this._minutes}set Minutes(t){this._minutes=t}get Seconds(){return this._seconds}set Seconds(t){this._seconds=t}}class o{constructor(){this.Channel=0,this.State=a.Disabled}}var a,i,s;!function(t){t[t.Disabled=0]="Disabled",t[t.Enabled=1]="Enabled",t[t.PreviousState=2]="PreviousState"}(a||(a={}));class u{constructor(){this.Channel=0,this.Time=new r}}!function(t){t[t.Monostable=0]="Monostable",t[t.Bistable=1]="Bistable"}(i||(i={})),function(t){t[t.None=0]="None",t[t.Off=1]="Off",t[t.On=2]="On",t[t.Time=3]="Time",t[t.Mono=4]="Mono",t[t.Bi=5]="Bi",t[t.OnOff=6]="OnOff"}(s||(s={}))},9647:(t,e,n)=>{n.d(e,{c:()=>d,w:()=>r});var r,o=n(5046),a=n(6440),i=n(6895),s=n(624),u=n(5564),l=n(6532),c=n(9899),h=function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function i(t){try{u(r.next(t))}catch(t){a(t)}}function s(t){try{u(r.throw(t))}catch(t){a(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(i,s)}u((r=r.apply(t,e||[])).next())}))};class d{constructor(){this._connection=null,this._connection=o.V.Get(i.c.ServiceName),this._logger=o.V.Get(u.m.ServiceName)}GetTurnOnBehaviourAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{if(!t.Channels.any((t=>t.Number===e)))return new s.tp(r.InvalidChannelNumber,`Cannot get turn on behaviour - invalid channel number, channel: ${e}`);const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new p(new l.W(t.Guid,e)),8e3,!1);if(null==o||null==o.Status)return new s.tp(r.OtherError,"Cannot get turn on behaviour - unknown error.");if(o.Status!==a.qb.OK)return new s.tp(r.OtherError,`Cannot get turn on behaviour - controller responded with error code: ${o.Status}.`);if(null==o.Data)return new s.tp(r.NoData,"Cannot get turn on behaviour - no data in response.");const i=new c.KR;return i.Channel=o.Data.Channel,i.State=o.Data.State,16===i.State&&(i.State=c.Qk.Disabled),i}catch(t){return new s.tp(r.OtherError,"Failed to retrieve turn on behaviour - unknown error.")}}))}SetTurnOnBehaviourAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{const r=new m;r.DeviceGuid=t.Guid,r.Channel=e.Channel,r.State=e.State;const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new v(r),8e3,!1);return null==o||null==o.Status?(this._logger.Error(d.ServiceName,"Failed to set turn on behaviour - unknow error."),a.qb.FatalError):(o.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set turn on behaviour, response status: ${o.Status}`),o.Status)}catch(t){return a.qb.FatalError}}))}GetGlobalTimeSettingsAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{if(!t.Channels.any((t=>t.Number===e)))return new s.tp(r.InvalidChannelNumber,`Cannot get global time settings - invalid channel number, channel: ${e}`);const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new S(new l.W(t.Guid,e)),8e3,!1);if(null==o||null==o.Status)return new s.tp(r.OtherError,"Cannot get global time settings - unknown error.");if(o.Status!==a.qb.OK)return new s.tp(r.OtherError,`Cannot get global time settings - controller responded with error code: ${o.Status}.`);if(null==o.Data)return new s.tp(r.NoData,"Cannot get global time settings - no data in response.");const i=new c.OL;return i.Channel=o.Data.Channel,i.Time=this.ParseNumberToTime(o.Data.Time),i}catch(t){return new s.tp(r.OtherError,"Cannot get global time settings - unknown error.")}}))}SetGlobalTimeSettingsAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{const r=3600*e.Time.Hours+60*e.Time.Minutes+e.Time.Seconds,o=new w;o.Channel=e.Channel,o.DeviceGuid=t.Guid,o.Time=r;const i=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new g(o),8e3,!1);return null==i||null==i.Status?(this._logger.Error(d.ServiceName,"Failed to set global time settings - unknow error."),a.qb.FatalError):(i.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set global time settings, response status: ${i.Status}`),i.Status)}catch(t){return a.qb.FatalError}}))}GetTurnOnTimeAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{if(!t.Channels.any((t=>t.Number===e)))return new s.tp(r.InvalidChannelNumber,`Cannot get turn on time - invalid channel number, channel: ${e}`);const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new C(new l.W(t.Guid,e)),8e3,!1);if(null==o||null==o.Status)return new s.tp(r.OtherError,"Cannot get turn on time - unknown error.");if(o.Status!==a.qb.OK)return new s.tp(r.OtherError,`Cannot get turn on time - controller responded with error code: ${o.Status}.`);if(null==o.Data)return new s.tp(r.NoData,"Cannot get turn on time - no data in response.");const i=new c.OL;return i.Channel=o.Data.Channel,i.Time=this.ParseNumberToTime(o.Data.Time),i}catch(t){return new s.tp(r.OtherError,"Cannot get turn on time - unknown error.")}}))}SetTurnOnTimeAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{const r=3600*e.Time.Hours+60*e.Time.Minutes+e.Time.Seconds,o=new w;o.Channel=e.Channel,o.DeviceGuid=t.Guid,o.Time=r;const i=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new f(o),8e3,!1);return null==i||null==i.Status?(this._logger.Error(d.ServiceName,"Failed to set turn on time settings - unknow error."),a.qb.FatalError):(i.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set turn on time settings, response status: ${i.Status}`),i.Status)}catch(t){return a.qb.FatalError}}))}GetSwitchInputOutputParamAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{if(!t.Channels.any((t=>t.Number===e)))return new s.tp(r.InvalidChannelNumber,`Cannot get input/output parameters - invalid channel number, channel: ${e}`);const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new I(new l.W(t.Guid,e)),8e3,!1);return null==o||null==o.Status?new s.tp(r.OtherError,"Cannot get input/output parameters - unknown error."):o.Status!==a.qb.OK?new s.tp(r.OtherError,`Cannot get input/output parameters - controller responded with error code: ${o.Status}.`):null==o.Data?new s.tp(r.NoData,"Cannot get input/output parameter - no data in response."):o.Data.map((t=>{const e=new N;return e.Channel=t.Channel,e.InputMode=t.InputMode,e.InputsNumber=t.InputsNumber,e.ReactionToInput=t.ReactionToInput,e.InputChannel=t.InputChannel,e}))}catch(t){return new s.tp(r.OtherError,"Cannot get input/output parameters - unknown error.")}}))}SetSwitchInputOutputParamAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{if(e.InputMode==c.NL.Bistable&&e.ReactionToInput==c.M5.Bi)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - reaction to input cannot be 'bistable' when mode is set to 'bistable', switch mode to 'monostable' and call fucntion again."),a.qb.WrongData;const r=new _;r.DeviceGuid=t.Guid,r.Channel=e.Channel,r.InputChannel=e.InputChannel,r.ReactionToInput=e.ReactionToInput,r.InputMode=e.InputMode;const o=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new E(r),8e3,!1);return null==o||null==o.Status?(this._logger.Error(d.ServiceName,"Failed to set input/output parameters - unknow error."),a.qb.FatalError):(o.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set input/output parameters, response status: ${o.Status}`),o.Status)}catch(t){return a.qb.FatalError}}))}SetSwitchInputOutputInputModeParamAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{const r=yield this.GetSwitchInputOutputParamAsync(t,e.Channel);if(null!=r.Type)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - cannot get current configuration."),a.qb.Error;const o=r.firstOrDefault((t=>t.Channel==e.Channel&&t.InputChannel==e.InputChannel));if(null==o)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - channel or inputChannel params may be incorrect."),a.qb.WrongData;const i=new _;i.DeviceGuid=t.Guid,i.Channel=e.Channel,i.InputChannel=e.InputChannel,i.InputMode=e.InputMode,i.ReactionToInput=o.ReactionToInput;const s=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new E(i),8e3,!1);return null==s||null==s.Status?(this._logger.Error(d.ServiceName,"Failed to set input/output parameters - unknow error."),a.qb.FatalError):(s.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set input/output parameters, response status: ${s.Status}`),s.Status)}catch(t){return a.qb.FatalError}}))}SetSwitchInputOutputReactionToInputParamAsync(t,e){var n;return h(this,void 0,void 0,(function*(){try{const r=yield this.GetSwitchInputOutputParamAsync(t,e.Channel);if(null!=r.Type)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - cannot get current configuration."),a.qb.Error;const o=r.firstOrDefault((t=>t.Channel==e.Channel&&t.InputChannel==e.InputChannel));if(null==o)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - channel or inputChannel params may be incorrect."),a.qb.WrongData;if(o.InputMode==c.NL.Bistable&&e.ReactionToInput==c.M5.Bi)return this._logger.Error(d.ServiceName,"Failed to set input/output parameters - reaction to input cannot be 'bistable' when mode is set to 'bistable', switch mode to 'monostable' and call fucntion again."),a.qb.WrongData;const i=new _;i.DeviceGuid=t.Guid,i.Channel=e.Channel,i.InputChannel=e.InputChannel,i.ReactionToInput=e.ReactionToInput,i.InputMode=o.InputMode;const s=yield null===(n=this._connection)||void 0===n?void 0:n.SendAndWaitForResponseAsync(new E(i),8e3,!1);return null==s||null==s.Status?(this._logger.Error(d.ServiceName,"Failed to set input/output parameters - unknow error."),a.qb.FatalError):(s.Status!==a.qb.OK&&this._logger.Error(d.ServiceName,`Failed to set input/output parameters, response status: ${s.Status}`),s.Status)}catch(t){return a.qb.FatalError}}))}ParseNumberToTime(t){const e=new b;return e.Hours=Math.floor(t/3600),e.Minutes=Math.floor(t%3600/60),e.Seconds=Math.floor(t%3600%60),e.Raw=t,e}}d.ServiceName="OnOffSwitchService",function(t){t.InvalidChannelNumber="InvalidChannelNumber",t.OtherError="OtherError",t.NoData="NoData"}(r||(r={}));class p extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/state/turnon",this.Method=a.n$.Get,this.Data=t}}class m extends c.KR{constructor(){super(...arguments),this.DeviceGuid=""}}class v extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/state/turnon",this.Method=a.n$.Put,this.Data=t}}class b extends c.qp{set Raw(t){this._raw=t}}class S extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/global/time",this.Method=a.n$.Get,this.Data=t}}class g extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/global/time",this.Method=a.n$.Put,this.Data=t}}class w{constructor(){this.Channel=0,this.DeviceGuid="",this.Time=0}}class C extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/device/on/time",this.Method=a.n$.Get,this.Data=t}}class f extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/device/on/time",this.Method=a.n$.Put,this.Data=t}}class N{constructor(){this._channel=0,this._inputsNumber=0,this._inputMode=c.NL.Monostable,this._reactionToInput=c.M5.None,this._inputChannel=0}get Channel(){return this._channel}set Channel(t){this._channel=t}get InputsNumber(){return this._inputsNumber}set InputsNumber(t){this._inputsNumber=t}get InputMode(){return this._inputMode}set InputMode(t){this._inputMode=t}get ReactionToInput(){return this._reactionToInput}set ReactionToInput(t){this._reactionToInput=t}get InputChannel(){return this._inputChannel}set InputChannel(t){this._inputChannel=t}}class _{constructor(){this.DeviceGuid="",this.Channel=0,this.InputChannel=0,this.InputMode=c.NL.Bistable,this.ReactionToInput=c.M5.None}}class I extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/input/output",this.Method=a.n$.Get,this.Data=t}}class E extends a.NE{constructor(t){super(),this.Resource="/extalife/device/parameters/input/output",this.Method=a.n$.Put,this.Data=t}}}}]);
//# sourceMappingURL=647-exalushome-extalife.bundle.js.map