freeathome-local-api-client 1.0.1 → 1.1.2

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.
Files changed (43) hide show
  1. package/README.md +8 -1
  2. package/dist/bundle.js +1 -1
  3. package/dist/bundle.js.map +1 -1
  4. package/dist/src/model/channel.d.ts +10 -5
  5. package/dist/src/model/channel.d.ts.map +1 -1
  6. package/dist/src/model/configuration.d.ts +2 -5
  7. package/dist/src/model/configuration.d.ts.map +1 -1
  8. package/dist/src/model/device-list.d.ts +3 -1
  9. package/dist/src/model/device-list.d.ts.map +1 -1
  10. package/dist/src/model/device-response.d.ts +4 -5
  11. package/dist/src/model/device-response.d.ts.map +1 -1
  12. package/dist/src/model/device.d.ts +8 -5
  13. package/dist/src/model/device.d.ts.map +1 -1
  14. package/dist/src/model/devices.d.ts +4 -5
  15. package/dist/src/model/devices.d.ts.map +1 -1
  16. package/dist/src/model/error.d.ts +13 -5
  17. package/dist/src/model/error.d.ts.map +1 -1
  18. package/dist/src/model/floors.d.ts +4 -5
  19. package/dist/src/model/floors.d.ts.map +1 -1
  20. package/dist/src/model/get-data-point-response.d.ts +3 -5
  21. package/dist/src/model/get-data-point-response.d.ts.map +1 -1
  22. package/dist/src/model/in-out-put.d.ts +3 -5
  23. package/dist/src/model/in-out-put.d.ts.map +1 -1
  24. package/dist/src/model/rooms.d.ts +3 -5
  25. package/dist/src/model/rooms.d.ts.map +1 -1
  26. package/dist/src/model/scenes-triggered.d.ts +9 -3
  27. package/dist/src/model/scenes-triggered.d.ts.map +1 -1
  28. package/dist/src/model/set-data-point-response.d.ts +3 -5
  29. package/dist/src/model/set-data-point-response.d.ts.map +1 -1
  30. package/dist/src/model/sys-ap.d.ts +6 -5
  31. package/dist/src/model/sys-ap.d.ts.map +1 -1
  32. package/dist/src/model/users.d.ts +9 -5
  33. package/dist/src/model/users.d.ts.map +1 -1
  34. package/dist/src/model/validator.d.ts +21 -21
  35. package/dist/src/model/virtual-device-response.d.ts +5 -5
  36. package/dist/src/model/virtual-device-response.d.ts.map +1 -1
  37. package/dist/src/model/virtual-device.d.ts +44 -10
  38. package/dist/src/model/virtual-device.d.ts.map +1 -1
  39. package/dist/src/model/websocket-message.d.ts +8 -2
  40. package/dist/src/model/websocket-message.d.ts.map +1 -1
  41. package/dist/src/system-access-point.d.ts +49 -38
  42. package/dist/src/system-access-point.d.ts.map +1 -1
  43. package/package.json +7 -2
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  A client library for the BUSCH-JAEGER free@home local API implemented in TypeScript.
4
4
 
5
+ ![CI](https://img.shields.io/github/workflow/status/pgerke/freeathome-local-api-client/Continuous%20Integration?style=flat-square)
6
+ [![codecov](https://codecov.io/gh/pgerke/freeathome-local-api-client/branch/main/graph/badge.svg?token=UJQVXZ5PPM)](https://codecov.io/gh/pgerke/freeathome-local-api-client)
7
+ ![Dependencies](https://img.shields.io/librariesio/release/npm/freeathome-local-api-client?style=flat-square)
8
+ ![npm](https://img.shields.io/npm/v/freeathome-local-api-client?style=flat-square)
9
+ ![License](https://img.shields.io/github/license/pgerke/freeathome-local-api-client?style=flat-square)
10
+
5
11
  ## Installation
6
12
 
7
13
  You can install the package from npmjs.com:
@@ -25,7 +31,8 @@ npm install --save freeathome-local-api-client
25
31
 
26
32
  ## Documentation
27
33
 
28
- A sample project illustrating the use of the library can be found at https://github.com/pgerke/freeathome-local-api-sample.
34
+ The client library is documented using JSDoc, the generated documentation is available at https://pgerke.github.io/freeathome-local-api-client/.
35
+ There is also a sample project illustrating the use of the library can be found at https://github.com/pgerke/freeathome-local-api-sample.
29
36
 
30
37
  ## I found a bug, what do I do?
31
38
 
package/dist/bundle.js CHANGED
@@ -1,2 +1,2 @@
1
- import*as e from"ts-interface-checker";import*as t from"ws";var r={d:(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},n={};r.d(n,{ns:()=>De,LB:()=>T,s:()=>K,L$:()=>M,LT:()=>$,iH:()=>Q,W0:()=>j,DO:()=>W});const i=(P={array:()=>e.array,createCheckers:()=>e.createCheckers,iface:()=>e.iface,indexKey:()=>e.indexKey,opt:()=>e.opt},R={},r.d(R,P),R),o={Channel:(0,i.iface)([],{displayName:(0,i.opt)("string"),functionID:(0,i.opt)("string"),room:(0,i.opt)("string"),floor:(0,i.opt)("string"),inputs:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"InOutPut"})),outputs:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"InOutPut"})),type:(0,i.opt)("string")})},s={Configuration:(0,i.iface)([],{[i.indexKey]:"SysAP"})},a={Device:(0,i.iface)([],{displayName:(0,i.opt)("string"),room:(0,i.opt)("string"),floor:(0,i.opt)("string"),interface:(0,i.opt)("string"),nativeId:(0,i.opt)("string"),channels:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"Channel"}))})},c={DeviceList:(0,i.iface)([],{[i.indexKey]:(0,i.array)("string")})},u={DeviceResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{devices:"Devices"})})},l={Devices:(0,i.iface)([],{[i.indexKey]:"Device"})},f={Error:(0,i.iface)([],{code:"string",detail:"string",title:"string"})},p={Floors:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{name:"string",rooms:"Rooms"})})},h={GetDataPointResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{values:(0,i.array)("string")})})},d={InOutPut:(0,i.iface)([],{value:(0,i.opt)("string"),pairingID:(0,i.opt)("number")})},y={Rooms:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{name:"string"})})},v={ScenesTriggered:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{channels:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{outputs:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{value:"string",pairingID:"number"})})})})})})},b={SetDataPointResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{[i.indexKey]:"string"})})},g={SysAP:(0,i.iface)([],{devices:"Devices",floorplan:(0,i.iface)([],{floors:"Floors"}),sysapName:"string",users:"Users",error:(0,i.opt)("Error")})},S={Users:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{enabled:"boolean",flags:(0,i.array)("string"),grantedPermissions:(0,i.array)("string"),jid:"string",name:"string",requestedPermissions:(0,i.array)("string"),role:"string"})})},m={VirtualDeviceResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{devices:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{serial:"string"})})})})},w={WebSocketMessage:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{datapoints:(0,i.iface)([],{[i.indexKey]:"string"}),devices:(0,i.iface)([],{[i.indexKey]:"Devices"}),devicesAdded:(0,i.array)("string"),devicesRemoved:(0,i.array)("string"),scenesTriggered:"ScenesTriggered"})})},{Configuration:x}=(0,i.createCheckers)(s,l,a,o,d,p,y,g,S,f),{DeviceList:A}=(0,i.createCheckers)(c),{DeviceResponse:E}=(0,i.createCheckers)(u,l,a,o,d),{GetDataPointResponse:_}=(0,i.createCheckers)(h),{SetDataPointResponse:O}=(0,i.createCheckers)(b),{VirtualDeviceResponse:k}=(0,i.createCheckers)(m),{WebSocketMessage:D}=(0,i.createCheckers)(w,l,a,o,d,v);var P,R,T;function C(e,t,r){if(r)try{return t.check(e),!0}catch(e){return console.error("Object validation failed!",e),!1}return t.test(e)}function W(e,t=!1){return C(e,D,t)}function K(e,t=!1){return C(e,x,t)}function M(e,t=!1){return C(e,A,t)}function $(e,t=!1){return C(e,E,t)}function Q(e,t=!1){return C(e,_,t)}function j(e,t=!1){return C(e,O,t)}function B(e,t=!1){return C(e,k,t)}!function(e){e.BinarySensor="BinarySensor",e.BlindActuator="BlindActuator",e.SwitchingActuator="SwitchingActuator",e.CeilingFanActuator="CeilingFanActuator",e.RTC="RTC",e.DimActuator="DimActuator",e.EVCharging="evcharging",e.WindowSensor="WindowSensor",e.SimpleDoorlock="simple_doorlock",e.ShutterActuator="ShutterActuator",e.WeatherStation="WeatherStation",e.WeatherTemperatureSensor="Weather-TemperatureSensor",e.WeatherWindSensor="Weather-WindSensor",e.WeatherBrightnessSensor="Weather-BrightnessSensor",e.WeatherRainSensor="Weather-RainSensor",e.WindowActuator="WindowActuator",e.CODetector="CODetector",e.FireDetector="FireDetector",e.KNXSwitchSensor="KNX-SwitchSensor",e.MediaPlayer="MediaPlayer",e.EnergyBattery="EnergyBattery",e.EnergyInverter="EnergyInverter",e.EnergyMeter="EnergyMeter",e.EnergyInverterBattery="EnergyInverterBattery",e.EnergyInverterMeter="EnergyInverterMeter",e.EnergyInverterMeterBattery="EnergyInverterMeterBattery",e.EnergyMeterBattery="EnergyMeterBattery",e.AirQualityCO2="AirQualityCO2",e.AirQualityCO="AirQualityCO",e.AirQualityFull="AirQualityFull",e.AirQualityHumidity="AirQualityHumidity",e.AirQualityNO2="AirQualityNO2",e.AirQualityO3="AirQualityO3",e.AirQualityPM10="AirQualityPM10",e.AirQualityPM25="AirQualityPM25",e.AirQualityPressure="AirQualityPressure",e.AirQualityTemperature="AirQualityTemperature",e.AirQualityVOC="AirQualityVOC"}(T||(T={}));var I=function(e,t){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},I(e,t)};function N(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}I(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function V(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function z(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function F(e){return"function"==typeof e}function U(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}Object.create,Object.create;var G=U((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function H(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var q=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=V(o),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var c=this.initialTeardown;if(F(c))try{c()}catch(e){i=e instanceof G?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var l=V(u),f=l.next();!f.done;f=l.next()){var p=f.value;try{Y(p)}catch(e){i=null!=i?i:[],e instanceof G?i=z(z([],L(i)),L(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}}if(i)throw new G(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Y(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&H(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&H(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}(),J=q.EMPTY;function X(e){return e instanceof q||e&&"closed"in e&&F(e.remove)&&F(e.add)&&F(e.unsubscribe)}function Y(e){F(e)?e():e.unsubscribe()}var Z=null,ee=null,te=void 0,re=!1,ne=!1,ie={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ie.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,z([e,t],L(r))):setTimeout.apply(void 0,z([e,t],L(r)))},clearTimeout:function(e){var t=ie.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function oe(){}var se=ae("C",void 0,void 0);function ae(e,t,r){return{kind:e,value:t,error:r}}var ce=null;function ue(e){if(re){var t=!ce;if(t&&(ce={errorThrown:!1,error:null}),e(),t){var r=ce,n=r.errorThrown,i=r.error;if(ce=null,n)throw i}}else e()}var le=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,X(t)&&t.add(r)):r.destination=be,r}return N(t,e),t.create=function(e,t,r){return new de(e,t,r)},t.prototype.next=function(e){this.isStopped?ve(function(e){return ae("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ve(ae("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ve(se,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(q),fe=Function.prototype.bind;function pe(e,t){return fe.call(e,t)}var he=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){ye(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){ye(e)}else ye(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){ye(e)}},e}(),de=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;return F(t)||!t?i={next:null!=t?t:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:s&&ne?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&pe(t.next,o),error:t.error&&pe(t.error,o),complete:t.complete&&pe(t.complete,o)}):i=t,s.destination=new he(i),s}return N(t,e),t}(le);function ye(e){var t;re?(t=e,re&&ce&&(ce.errorThrown=!0,ce.error=t)):function(e){ie.setTimeout((function(){if(!Z)throw e;Z(e)}))}(e)}function ve(e,t){var r=ee;r&&ie.setTimeout((function(){return r(e,t)}))}var be={closed:!0,next:oe,error:function(e){throw e},complete:oe},ge="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}function me(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce((function(e,t){return t(e)}),t)}}var we=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n,i=this,o=(n=e)&&n instanceof le||function(e){return e&&F(e.next)&&F(e.error)&&F(e.complete)}(n)&&X(n)?e:new de(e,t,r);return ue((function(){var e=i,t=e.operator,r=e.source;o.add(t?t.call(o,r):r?i._subscribe(o):i._trySubscribe(o))})),o},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var r=this;return new(t=xe(t))((function(t,n){var i=new de({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ge]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return me(e)(this)},e.prototype.toPromise=function(e){var t=this;return new(e=xe(e))((function(e,r){var n;t.subscribe((function(e){return n=e}),(function(e){return r(e)}),(function(){return e(n)}))}))},e.create=function(t){return new e(t)},e}();function xe(e){var t;return null!==(t=null!=e?e:te)&&void 0!==t?t:Promise}var Ae=U((function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),Ee=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return N(t,e),t.prototype.lift=function(e){var t=new _e(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ae},t.prototype.next=function(e){var t=this;ue((function(){var r,n;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var i=V(t.currentObservers),o=i.next();!o.done;o=i.next())o.value.next(e)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}}}))},t.prototype.error=function(e){var t=this;ue((function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var r=t.observers;r.length;)r.shift().error(e)}}))},t.prototype.complete=function(){var e=this;ue((function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}}))},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,r=this,n=r.hasError,i=r.isStopped,o=r.observers;return n||i?J:(this.currentObservers=null,o.push(e),new q((function(){t.currentObservers=null,H(o,e)})))},t.prototype._checkFinalizedStatuses=function(e){var t=this,r=t.hasError,n=t.thrownError,i=t.isStopped;r?e.error(n):i&&e.complete()},t.prototype.asObservable=function(){var e=new we;return e.source=this,e},t.create=function(e,t){return new _e(e,t)},t}(we),_e=function(e){function t(t,r){var n=e.call(this)||this;return n.destination=t,n.source=r,n}return N(t,e),t.prototype.next=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===r||r.call(t,e)},t.prototype.error=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===r||r.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,r;return null!==(r=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==r?r:J},t}(Ee);const Oe=(e=>{var t={};return r.d(t,e),t})({WebSocket:()=>t.WebSocket});var ke=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))};class De{constructor(e,t,r,n=!0,i=!1){this.webSocketMessageSubject=new Ee,this.basicAuthKey=Buffer.from(`${t}:${r}`,"utf8").toString("base64"),this.hostName=e,this.tlsEnabled=n,this.verboseErrors=i}connectWebSocket(e=!0){if(this.webSocket&&this.webSocket.readyState===Oe.WebSocket.OPEN)throw new Error("Web socket is already connected");this.webSocket=this.createWebSocket(e)}createVirtualDevice(e,t,r){return ke(this,void 0,void 0,(function*(){const n=yield this.fetchDataViaRest("PUT",`virtualdevice/${e}/${t}`,JSON.stringify(r));return this.processRestResponse(n,B)}))}createWebSocket(e){this.tlsEnabled&&!e&&console.warn("TLS certificate verification is disabled! This poses a security risk, activating certificate verification is strictly recommended.");const t=`${this.tlsEnabled?"wss":"ws"}://${this.hostName}/fhapi/v1/api/ws`,r={rejectUnauthorized:this.tlsEnabled&&e,headers:{Authorization:`Basic ${this.basicAuthKey}`}},n=new Oe.WebSocket(t,r);return n.on("error",(e=>console.error("Error received",e))),n.on("ping",(e=>console.debug("Ping received",e.toString("ascii")))),n.on("pong",(e=>console.debug("Pong received",e.toString("ascii")))),n.on("unexpected-response",(()=>console.error("Unexpected response received"))),n.on("upgrade",(()=>console.debug("Upgrade request received"))),n.on("open",(()=>console.log("Connection opened"))),n.on("close",(()=>console.log("Connection closed"))),n.on("message",((e,t)=>this.processWebSocketMessage(e,t))),n}disconnectWebSocket(e=!1){if(!this.webSocket||this.webSocket.readyState===Oe.WebSocket.CLOSED)throw new Error("Web socket is not open");e?this.webSocket.terminate():this.webSocket.close()}getConfiguration(){return ke(this,void 0,void 0,(function*(){const e=yield this.fetchDataViaRest("GET","configuration");return this.processRestResponse(e,K)}))}getDeviceList(){return ke(this,void 0,void 0,(function*(){const e=yield this.fetchDataViaRest("GET","devicelist");return this.processRestResponse(e,M)}))}getDevice(e,t){return ke(this,void 0,void 0,(function*(){const r=yield this.fetchDataViaRest("GET",`device/${e}/${t}`);return this.processRestResponse(r,$)}))}getDatapoint(e,t,r,n){return ke(this,void 0,void 0,(function*(){const i=yield this.fetchDataViaRest("GET",`datapoint/${e}/${t}.${r}.${n}`);return this.processRestResponse(i,Q)}))}getWebSocketMessages(){return this.webSocketMessageSubject.asObservable()}setDatapoint(e,t,r,n,i){return ke(this,void 0,void 0,(function*(){const o=yield this.fetchDataViaRest("PUT",`datapoint/${e}/${t}.${r}.${n}`,i);return this.processRestResponse(o,j)}))}fetchDataViaRest(e,t,r){return ke(this,void 0,void 0,(function*(){const n=`${this.tlsEnabled?"https":"http"}://${this.hostName}/fhapi/v1/api/rest/${t}`,i={method:e,headers:{Authorization:`Basic ${this.basicAuthKey}`},body:r};return fetch(n,i)}))}processRestResponse(e,t){return ke(this,void 0,void 0,(function*(){let r,n;switch(e.status){case 200:if(r=yield e.json(),!t(r,this.verboseErrors))throw n="Received message has an unexpected type!",console.error(n,r),new Error(n);return r;case 401:throw n="Authentication information is missing or invalid.",console.error(n),new Error(n);case 502:throw n=yield e.text(),console.error(n),new Error(n);default:throw n=`Received HTTP ${e.status} status code unexpectedly: ${yield e.text()}`,console.error(n),new Error(n)}}))}processWebSocketMessage(e,t){if(t)return void console.warn("Binary message received. Binary messages are not processed.");console.debug("Message received");const r=e.toString(),n=JSON.parse(r);W(n,this.verboseErrors)?this.webSocketMessageSubject.next(n):console.error("Received message has an unexpected type!",r)}}var Pe=n.ns,Re=n.LB,Te=n.s,Ce=n.L$,We=n.LT,Ke=n.iH,Me=n.W0,$e=n.DO;export{Pe as SystemAccessPoint,Re as VirtualDeviceType,Te as isConfiguration,Ce as isDeviceList,We as isDeviceResponse,Ke as isGetDataPointResponse,Me as isSetDataPointResponse,$e as isWebSocketMessage};
1
+ import*as e from"ts-interface-checker";import*as t from"ws";var r={d:(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},n={};r.d(n,{ns:()=>Re,LB:()=>T,s:()=>$,L$:()=>K,LT:()=>M,iH:()=>Q,W0:()=>j,DO:()=>W});const i=(P={array:()=>e.array,createCheckers:()=>e.createCheckers,iface:()=>e.iface,indexKey:()=>e.indexKey,opt:()=>e.opt},k={},r.d(k,P),k),o={Channel:(0,i.iface)([],{displayName:(0,i.opt)("string"),functionID:(0,i.opt)("string"),room:(0,i.opt)("string"),floor:(0,i.opt)("string"),inputs:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"InOutPut"})),outputs:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"InOutPut"})),type:(0,i.opt)("string")})},s={Configuration:(0,i.iface)([],{[i.indexKey]:"SysAP"})},a={Device:(0,i.iface)([],{displayName:(0,i.opt)("string"),room:(0,i.opt)("string"),floor:(0,i.opt)("string"),interface:(0,i.opt)("string"),nativeId:(0,i.opt)("string"),channels:(0,i.opt)((0,i.iface)([],{[i.indexKey]:"Channel"}))})},c={DeviceList:(0,i.iface)([],{[i.indexKey]:(0,i.array)("string")})},u={DeviceResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{devices:"Devices"})})},l={Devices:(0,i.iface)([],{[i.indexKey]:"Device"})},f={Error:(0,i.iface)([],{code:"string",detail:"string",title:"string"})},p={Floors:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{name:"string",rooms:"Rooms"})})},h={GetDataPointResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{values:(0,i.array)("string")})})},d={InOutPut:(0,i.iface)([],{value:(0,i.opt)("string"),pairingID:(0,i.opt)("number")})},y={Rooms:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{name:"string"})})},v={ScenesTriggered:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{channels:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{outputs:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{value:"string",pairingID:"number"})})})})})})},b={SetDataPointResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{[i.indexKey]:"string"})})},g={SysAP:(0,i.iface)([],{devices:"Devices",floorplan:(0,i.iface)([],{floors:"Floors"}),sysapName:"string",users:"Users",error:(0,i.opt)("Error")})},S={Users:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{enabled:"boolean",flags:(0,i.array)("string"),grantedPermissions:(0,i.array)("string"),jid:"string",name:"string",requestedPermissions:(0,i.array)("string"),role:"string"})})},m={VirtualDeviceResponse:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{devices:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{serial:"string"})})})})},w={WebSocketMessage:(0,i.iface)([],{[i.indexKey]:(0,i.iface)([],{datapoints:(0,i.iface)([],{[i.indexKey]:"string"}),devices:(0,i.iface)([],{[i.indexKey]:"Devices"}),devicesAdded:(0,i.array)("string"),devicesRemoved:(0,i.array)("string"),scenesTriggered:"ScenesTriggered"})})},{Configuration:x}=(0,i.createCheckers)(s,l,a,o,d,p,y,g,S,f),{DeviceList:E}=(0,i.createCheckers)(c),{DeviceResponse:A}=(0,i.createCheckers)(u,l,a,o,d),{GetDataPointResponse:_}=(0,i.createCheckers)(h),{SetDataPointResponse:O}=(0,i.createCheckers)(b),{VirtualDeviceResponse:D}=(0,i.createCheckers)(m),{WebSocketMessage:R}=(0,i.createCheckers)(w,l,a,o,d,v);var P,k,T;function C(e,t,r){if(r)try{return t.check(e),!0}catch(e){return console.error("Object validation failed!",e),!1}return t.test(e)}function W(e,t=!1){return C(e,R,t)}function $(e,t=!1){return C(e,x,t)}function K(e,t=!1){return C(e,E,t)}function M(e,t=!1){return C(e,A,t)}function Q(e,t=!1){return C(e,_,t)}function j(e,t=!1){return C(e,O,t)}function B(e,t=!1){return C(e,D,t)}!function(e){e.BinarySensor="BinarySensor",e.BlindActuator="BlindActuator",e.SwitchingActuator="SwitchingActuator",e.CeilingFanActuator="CeilingFanActuator",e.RTC="RTC",e.DimActuator="DimActuator",e.EVCharging="evcharging",e.WindowSensor="WindowSensor",e.SimpleDoorlock="simple_doorlock",e.ShutterActuator="ShutterActuator",e.WeatherStation="WeatherStation",e.WeatherTemperatureSensor="Weather-TemperatureSensor",e.WeatherWindSensor="Weather-WindSensor",e.WeatherBrightnessSensor="Weather-BrightnessSensor",e.WeatherRainSensor="Weather-RainSensor",e.WindowActuator="WindowActuator",e.CODetector="CODetector",e.FireDetector="FireDetector",e.KNXSwitchSensor="KNX-SwitchSensor",e.MediaPlayer="MediaPlayer",e.EnergyBattery="EnergyBattery",e.EnergyInverter="EnergyInverter",e.EnergyMeter="EnergyMeter",e.EnergyInverterBattery="EnergyInverterBattery",e.EnergyInverterMeter="EnergyInverterMeter",e.EnergyInverterMeterBattery="EnergyInverterMeterBattery",e.EnergyMeterBattery="EnergyMeterBattery",e.AirQualityCO2="AirQualityCO2",e.AirQualityCO="AirQualityCO",e.AirQualityFull="AirQualityFull",e.AirQualityHumidity="AirQualityHumidity",e.AirQualityNO2="AirQualityNO2",e.AirQualityO3="AirQualityO3",e.AirQualityPM10="AirQualityPM10",e.AirQualityPM25="AirQualityPM25",e.AirQualityPressure="AirQualityPressure",e.AirQualityTemperature="AirQualityTemperature",e.AirQualityVOC="AirQualityVOC"}(T||(T={}));var I=function(e,t){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},I(e,t)};function V(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}I(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function N(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function L(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}function z(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function F(e){return"function"==typeof e}function U(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}Object.create,Object.create;var G=U((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function H(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var q=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}var t;return e.prototype.unsubscribe=function(){var e,t,r,n,i;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var s=N(o),a=s.next();!a.done;a=s.next())a.value.remove(this)}catch(t){e={error:t}}finally{try{a&&!a.done&&(t=s.return)&&t.call(s)}finally{if(e)throw e.error}}else o.remove(this);var c=this.initialTeardown;if(F(c))try{c()}catch(e){i=e instanceof G?e.errors:[e]}var u=this._finalizers;if(u){this._finalizers=null;try{for(var l=N(u),f=l.next();!f.done;f=l.next()){var p=f.value;try{Y(p)}catch(e){i=null!=i?i:[],e instanceof G?i=z(z([],L(i)),L(e.errors)):i.push(e)}}}catch(e){r={error:e}}finally{try{f&&!f.done&&(n=l.return)&&n.call(l)}finally{if(r)throw r.error}}}if(i)throw new G(i)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)Y(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=null!==(r=this._finalizers)&&void 0!==r?r:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&H(t,e)},e.prototype.remove=function(t){var r=this._finalizers;r&&H(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}(),J=q.EMPTY;function X(e){return e instanceof q||e&&"closed"in e&&F(e.remove)&&F(e.add)&&F(e.unsubscribe)}function Y(e){F(e)?e():e.unsubscribe()}var Z=null,ee=null,te=void 0,re=!1,ne=!1,ie={setTimeout:function(e,t){for(var r=[],n=2;n<arguments.length;n++)r[n-2]=arguments[n];var i=ie.delegate;return(null==i?void 0:i.setTimeout)?i.setTimeout.apply(i,z([e,t],L(r))):setTimeout.apply(void 0,z([e,t],L(r)))},clearTimeout:function(e){var t=ie.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function oe(){}var se=ae("C",void 0,void 0);function ae(e,t,r){return{kind:e,value:t,error:r}}var ce=null;function ue(e){if(re){var t=!ce;if(t&&(ce={errorThrown:!1,error:null}),e(),t){var r=ce,n=r.errorThrown,i=r.error;if(ce=null,n)throw i}}else e()}var le=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,X(t)&&t.add(r)):r.destination=be,r}return V(t,e),t.create=function(e,t,r){return new de(e,t,r)},t.prototype.next=function(e){this.isStopped?ve(function(e){return ae("N",e,void 0)}(e),this):this._next(e)},t.prototype.error=function(e){this.isStopped?ve(ae("E",void 0,e),this):(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped?ve(se,this):(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(q),fe=Function.prototype.bind;function pe(e,t){return fe.call(e,t)}var he=function(){function e(e){this.partialObserver=e}return e.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e)}catch(e){ye(e)}},e.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e)}catch(e){ye(e)}else ye(e)},e.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(e){ye(e)}},e}(),de=function(e){function t(t,r,n){var i,o,s=e.call(this)||this;return F(t)||!t?i={next:null!=t?t:void 0,error:null!=r?r:void 0,complete:null!=n?n:void 0}:s&&ne?((o=Object.create(t)).unsubscribe=function(){return s.unsubscribe()},i={next:t.next&&pe(t.next,o),error:t.error&&pe(t.error,o),complete:t.complete&&pe(t.complete,o)}):i=t,s.destination=new he(i),s}return V(t,e),t}(le);function ye(e){var t;re?(t=e,re&&ce&&(ce.errorThrown=!0,ce.error=t)):function(e){ie.setTimeout((function(){if(!Z)throw e;Z(e)}))}(e)}function ve(e,t){var r=ee;r&&ie.setTimeout((function(){return r(e,t)}))}var be={closed:!0,next:oe,error:function(e){throw e},complete:oe},ge="function"==typeof Symbol&&Symbol.observable||"@@observable";function Se(e){return e}function me(e){return 0===e.length?Se:1===e.length?e[0]:function(t){return e.reduce((function(e,t){return t(e)}),t)}}var we=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n,i=this,o=(n=e)&&n instanceof le||function(e){return e&&F(e.next)&&F(e.error)&&F(e.complete)}(n)&&X(n)?e:new de(e,t,r);return ue((function(){var e=i,t=e.operator,r=e.source;o.add(t?t.call(o,r):r?i._subscribe(o):i._trySubscribe(o))})),o},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var r=this;return new(t=xe(t))((function(t,n){var i=new de({next:function(t){try{e(t)}catch(e){n(e),i.unsubscribe()}},error:n,complete:t});r.subscribe(i)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[ge]=function(){return this},e.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return me(e)(this)},e.prototype.toPromise=function(e){var t=this;return new(e=xe(e))((function(e,r){var n;t.subscribe((function(e){return n=e}),(function(e){return r(e)}),(function(){return e(n)}))}))},e.create=function(t){return new e(t)},e}();function xe(e){var t;return null!==(t=null!=e?e:te)&&void 0!==t?t:Promise}var Ee=U((function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),Ae=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.currentObservers=null,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return V(t,e),t.prototype.lift=function(e){var t=new _e(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new Ee},t.prototype.next=function(e){var t=this;ue((function(){var r,n;if(t._throwIfClosed(),!t.isStopped){t.currentObservers||(t.currentObservers=Array.from(t.observers));try{for(var i=N(t.currentObservers),o=i.next();!o.done;o=i.next())o.value.next(e)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}}}))},t.prototype.error=function(e){var t=this;ue((function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var r=t.observers;r.length;)r.shift().error(e)}}))},t.prototype.complete=function(){var e=this;ue((function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}}))},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,r=this,n=r.hasError,i=r.isStopped,o=r.observers;return n||i?J:(this.currentObservers=null,o.push(e),new q((function(){t.currentObservers=null,H(o,e)})))},t.prototype._checkFinalizedStatuses=function(e){var t=this,r=t.hasError,n=t.thrownError,i=t.isStopped;r?e.error(n):i&&e.complete()},t.prototype.asObservable=function(){var e=new we;return e.source=this,e},t.create=function(e,t){return new _e(e,t)},t}(we),_e=function(e){function t(t,r){var n=e.call(this)||this;return n.destination=t,n.source=r,n}return V(t,e),t.prototype.next=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===r||r.call(t,e)},t.prototype.error=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===r||r.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,r;return null!==(r=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==r?r:J},t}(Ae);const Oe=(e=>{var t={};return r.d(t,e),t})({WebSocket:()=>t.WebSocket});var De=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{c(n.next(e))}catch(e){o(e)}}function a(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))};class Re{constructor(e,t,r,n=!0,i=!1){this.webSocketMessageSubject=new Ae,this.basicAuthKey=Buffer.from(`${t}:${r}`,"utf8").toString("base64"),this.hostName=e,this.tlsEnabled=n,this.verboseErrors=i}connectWebSocket(e=!0){if(this.webSocket&&this.webSocket.readyState===Oe.WebSocket.OPEN)throw new Error("Web socket is already connected");this.webSocket=this.createWebSocket(e)}createVirtualDevice(e,t,r){return De(this,void 0,void 0,(function*(){const n=yield this.fetchDataViaRest("PUT",`virtualdevice/${e}/${t}`,JSON.stringify(r));return this.processRestResponse(n,B)}))}createWebSocket(e){this.tlsEnabled&&!e&&console.warn("TLS certificate verification is disabled! This poses a security risk, activating certificate verification is strictly recommended.");const t=`${this.tlsEnabled?"wss":"ws"}://${this.hostName}/fhapi/v1/api/ws`,r={rejectUnauthorized:this.tlsEnabled&&e,headers:{Authorization:`Basic ${this.basicAuthKey}`}},n=new Oe.WebSocket(t,r);return n.on("error",(e=>console.error("Error received",e))),n.on("ping",(e=>console.debug("Ping received",e.toString("ascii")))),n.on("pong",(e=>console.debug("Pong received",e.toString("ascii")))),n.on("unexpected-response",(()=>console.error("Unexpected response received"))),n.on("upgrade",(()=>console.debug("Upgrade request received"))),n.on("open",(()=>console.log("Connection opened"))),n.on("close",(()=>console.log("Connection closed"))),n.on("message",((e,t)=>this.processWebSocketMessage(e,t))),n}disconnectWebSocket(e=!1){if(!this.webSocket||this.webSocket.readyState===Oe.WebSocket.CLOSED)throw new Error("Web socket is not open");e?this.webSocket.terminate():this.webSocket.close()}getConfiguration(){return De(this,void 0,void 0,(function*(){const e=yield this.fetchDataViaRest("GET","configuration");return this.processRestResponse(e,$)}))}getDeviceList(){return De(this,void 0,void 0,(function*(){const e=yield this.fetchDataViaRest("GET","devicelist");return this.processRestResponse(e,K)}))}getDevice(e,t){return De(this,void 0,void 0,(function*(){const r=yield this.fetchDataViaRest("GET",`device/${e}/${t}`);return this.processRestResponse(r,M)}))}getDatapoint(e,t,r,n){return De(this,void 0,void 0,(function*(){const i=yield this.fetchDataViaRest("GET",`datapoint/${e}/${t}.${r}.${n}`);return this.processRestResponse(i,Q)}))}getWebSocketMessages(){return this.webSocketMessageSubject.asObservable()}setDatapoint(e,t,r,n,i){return De(this,void 0,void 0,(function*(){const o=yield this.fetchDataViaRest("PUT",`datapoint/${e}/${t}.${r}.${n}`,i);return this.processRestResponse(o,j)}))}triggerProxyDevice(e,t,r,n){return De(this,void 0,void 0,(function*(){const i=yield this.fetchDataViaRest("GET",`proxydevice/${e}/${t}/${r}/action/${n}`);return this.processRestResponse(i,M)}))}setProxyDeviceValue(e,t,r,n){return De(this,void 0,void 0,(function*(){const i=yield this.fetchDataViaRest("PUT",`proxydevice/${e}/${t}/${r}/value/${n}`);return this.processRestResponse(i,M)}))}fetchDataViaRest(e,t,r){return De(this,void 0,void 0,(function*(){const n=`${this.tlsEnabled?"https":"http"}://${this.hostName}/fhapi/v1/api/rest/${t}`,i={method:e,headers:{Authorization:`Basic ${this.basicAuthKey}`},body:r};return fetch(n,i)}))}processRestResponse(e,t){return De(this,void 0,void 0,(function*(){let r,n;switch(e.status){case 200:if(r=yield e.json(),!t(r,this.verboseErrors))throw n="Received message has an unexpected type!",console.error(n,r),new Error(n);return r;case 401:throw n="Authentication information is missing or invalid.",console.error(n),new Error(n);case 502:throw n=yield e.text(),console.error(n),new Error(n);default:throw n=`Received HTTP ${e.status} status code unexpectedly: ${yield e.text()}`,console.error(n),new Error(n)}}))}processWebSocketMessage(e,t){if(t)return void console.warn("Binary message received. Binary messages are not processed.");console.debug("Message received");const r=e.toString(),n=JSON.parse(r);W(n,this.verboseErrors)?this.webSocketMessageSubject.next(n):console.error("Received message has an unexpected type!",r)}}var Pe=n.ns,ke=n.LB,Te=n.s,Ce=n.L$,We=n.LT,$e=n.iH,Ke=n.W0,Me=n.DO;export{Pe as SystemAccessPoint,ke as VirtualDeviceType,Te as isConfiguration,Ce as isDeviceList,We as isDeviceResponse,$e as isGetDataPointResponse,Ke as isSetDataPointResponse,Me as isWebSocketMessage};
2
2
  //# sourceMappingURL=bundle.js.map