UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 2.13 kB
"use strict";var b=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var d=(s,t)=>{for(var e in t)o(s,e,{get:t[e],enumerable:!0})},c=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!p.call(s,n)&&n!==e&&o(s,n,{get:()=>t[n],enumerable:!(i=v(t,n))||i.enumerable});return s};var k=(s,t,e)=>(e=s!=null?b(m(s)):{},c(t||!s||!s.__esModule?o(e,"default",{value:s,enumerable:!0}):e,s)),l=s=>c(o({},"__esModule",{value:!0}),s);var E={};d(E,{default:()=>h});module.exports=l(E);var g=k(require("debug")),r=require("../const"),a=require("./Websocket");const w=(0,g.default)("home-assistant"),f=["callService","connect","getDevices","getDeviceActions","getDeviceActionCapabilities","getDeviceTriggers","getDeviceTriggerCapabilities","getServices","getStates","getTranslations","getUser","send","subscribeMessage"],A=["fireEvent","get","getHistory","post","renderTemplate"];class h{constructor({websocketAPI:t,httpAPI:e,eventBus:i}){this.eventsList={};w("Instantiating HomeAssistant"),this.eventBus=i,this.http=e,this.websocket=t,this.exposeMethods(this.websocket,f),this.exposeMethods(this.http,A)}get isConnected(){return this.websocket.connectionState===a.ClientState.Connected}get isHomeAssistantRunning(){return this.isConnected&&this.websocket.isHomeAssistantRunning}get integrationVersion(){return this.websocket.integrationVersion}get isIntegrationLoaded(){return this.integrationVersion!==r.NO_VERSION}get connectionState(){return this.websocket.connectionState}get version(){return this?.websocket?.client?.haVersion??r.NO_VERSION}exposeMethods(t,e){e.forEach(i=>{typeof t[i]=="function"&&(this[i]=t[i].bind(t))})}getEntities(){const t=this.websocket.getStates();return Object.keys(t).sort()}getTags(){return this?.websocket?.tags??[]}subscribeEvents(){return this.websocket.subscribeEvents(this.eventsList)}close(){this?.websocket?.close()}addListener(t,e,i={once:!1}){i.once===!0?this.eventBus.once(t,e):this.eventBus.on(t,e)}removeListener(t,e){this.eventBus.removeListener(t,e)}}