node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
2 lines (1 loc) • 2.4 kB
JavaScript
;var m=Object.create;var s=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var w=(o,t)=>{for(var e in t)s(o,e,{get:t[e],enumerable:!0})},c=(o,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of y(t))!S.call(o,i)&&i!==e&&s(o,i,{get:()=>t[i],enumerable:!(n=C(t,i))||n.enumerable});return o};var u=(o,t,e)=>(e=o!=null?m(I(o)):{},c(t||!o||!o.__esModule?s(e,"default",{value:o,enumerable:!0}):e,o)),v=o=>c(s({},"__esModule",{value:!0}),o);var N={};w(N,{default:()=>g});module.exports=v(N);var d=u(require("../../common/controllers/InputOutputController")),a=u(require("../../common/errors/InputError")),h=u(require("../../common/errors/NoConnectionError")),f=require("../../common/integration/Integration"),l=require("../../const");class g extends d.default{#t;constructor(t){super(t),this.#t=this.integration?.getEntityConfigNode()}async#e({done:t,message:e,send:n}){const i=this.#t?.state?.getLastPayload()?.state;this.status.setSuccess(i),await this.setCustomOutputs(this.node.config.outputProperties,e,{config:this.node.config,value:i}),n(e),t()}async#o({done:t,message:e,parsedMessage:n,send:i}){if(!this.integration?.isConnected)throw new h.default;if(!this.integration?.isIntegrationLoaded)throw new a.default("home-assistant.error.integration_not_loaded","home-assistant.status.error");const r=await this.typedInputService.getValue(n.value.value,n.valueType.value,{message:e});if(this.#i(r)===!1)throw new a.default("ha-select.error.invalid_value","home-assistant.status.error");const p=this.#t?.state?.getLastPayload()?.state;await this.integration?.updateValue(r),this.#t?.emit(f.IntegrationEvent.ValueChange,r,p),await this.setCustomOutputs(this.node.config.outputProperties,e,{config:this.node.config,value:r,previousValue:p}),this.status.setSuccess(r),i(e),t()}async onInput({done:t,message:e,parsedMessage:n,send:i}){if(this.node.config.mode===l.ValueIntegrationMode.Get)this.#e({done:t,message:e,parsedMessage:n,send:i});else if(this.node.config.mode===l.ValueIntegrationMode.Set)await this.#o({done:t,message:e,parsedMessage:n,send:i});else throw new a.default("ha-text.error.mode_not_supported","home-assistant.status.error")}#i(t){const e=this.integration?.getEntityHomeAssistantConfigValue("options");return!e||!Array.isArray(e)?!1:e.includes(t)}}