UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 2.4 kB
"use strict";var p=Object.create;var i=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var C=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},g=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of f(e))!A.call(t,n)&&n!==o&&i(t,n,{get:()=>e[n],enumerable:!(s=v(e,n))||s.enumerable});return t};var E=(t,e,o)=>(o=t!=null?p(b(t)):{},g(e||!t||!t.__esModule?i(o,"default",{value:t,enumerable:!0}):o,t)),S=t=>g(i({},"__esModule",{value:!0}),t);var w={};C(w,{IntegrationEvent:()=>h,IntegrationState:()=>l,MessageType:()=>m,default:()=>u});module.exports=S(w);var c=require("../../homeAssistant/Websocket"),a=E(require("../errors/HomeAssistantError")),l=(s=>(s.Loaded="loaded",s.NotLoaded="notloaded",s.Unloaded="unloaded",s))(l||{}),h=(o=>(o.Trigger="trigger",o.ValueChange="itegration_value_change",o))(h||{}),m=(r=>(r.DeviceAction="nodered/device/action",r.DeviceTrigger="nodered/device/trigger",r.Discovery="nodered/discovery",r.Entity="nodered/entity",r.RemoveDevice="nodered/device/remove",r.SentenceTrigger="nodered/sentence",r.SentenceResponse="nodered/sentence_response",r.UpdateConfig="nodered/entity/update_config",r.Webhook="nodered/webhook",r))(m||{});class u{constructor({clientEvents:e,homeAssistant:o,state:s}){this.notInstalledMessage="Node-RED custom integration needs to be installed in Home Assistant for this node to function correctly.";this.registered=!1;this.status=[];this.clientEvents=e,this.homeAssistant=o,this.state=s}async init(){this.clientEvents.addListeners(this,[[c.ClientEvent.Close,this.#e],[c.ClientEvent.Integration,this.#t]]),this.isIntegrationLoaded&&await this.register()}get isConnected(){return this.homeAssistant.isConnected}get isIntegrationLoaded(){return this.homeAssistant.isIntegrationLoaded}get isRegistered(){return this.registered}#e(){this.registered=!1}async#t(e){switch(e){case"loaded":await this.register();break;case"unloaded":case"notloaded":this.registered=!1;break}}setStatus(e){this.status.push(e)}async sendUpdateConfig(e,o,s){const n={type:"nodered/entity/update_config",server_id:e,node_id:o,config:s};try{await this.homeAssistant.websocket.send(n)}catch(d){throw(0,a.isHomeAssistantApiError)(d)?new a.default(d,"home-assistant.error.error"):d}}}0&&(module.exports={IntegrationEvent,IntegrationState,MessageType});