UNPKG

node-red-contrib-home-assistant-websocket

Version:
2 lines (1 loc) 4.56 kB
"use strict";var C=Object.create;var l=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var W=(t,e)=>{for(var r in e)l(t,r,{get:e[r],enumerable:!0})},y=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of k(e))!O.call(t,n)&&n!==r&&l(t,n,{get:()=>e[n],enumerable:!(s=E(e,n))||s.enumerable});return t};var p=(t,e,r)=>(r=t!=null?C(w(t)):{},y(e||!t||!t.__esModule?l(r,"default",{value:t,enumerable:!0}):r,t)),j=t=>y(l({},"__esModule",{value:!0}),t);var B={};W(B,{default:()=>N});module.exports=j(B);var i=p(require("joi")),o=require("../../common/const"),f=require("../../common/controllers/helpers"),d=p(require("../../common/events/ClientEvents")),v=p(require("../../common/services/ComparatorService")),u=p(require("../../common/services/InputService")),g=p(require("../../common/status/Status")),P=p(require("../../common/TransformState")),a=require("../../const"),S=require("../../globals"),h=require("../../helpers/migrate"),T=require("../../helpers/node"),b=require("../../homeAssistant"),I=p(require("./WaitUntilController"));const R={entityId:{messageProp:["payload.entity_id","payload.entityId"]},entityIdFilterType:{messageProp:"payload.entityIdFilterType",default:"exact"},entities:{messageProp:"payload.entities",configProp:"entities"},property:{messageProp:"payload.property",configProp:"property"},comparator:{messageProp:"payload.comparator",configProp:"comparator"},value:{messageProp:"payload.value",configProp:"value"},valueType:{messageProp:"payload.valueType",configProp:"valueType"},timeout:{messageProp:"payload.timeout",configProp:"timeout"},timeoutUnits:{messageProp:"payload.timeoutUnits",configProp:"timeoutUnits"},checkCurrentState:{messageProp:"payload.checkCurrentState",configProp:"checkCurrentState"}};function A(t){if(t.entityId.value){const e={[o.IdSelectorType.Entity]:[],[o.IdSelectorType.Substring]:[],[o.IdSelectorType.Regex]:[]};switch(t.entityIdFilterType.value){case a.EntityFilterType.Exact:e[o.IdSelectorType.Entity]=[t.entityId.value];break;case a.EntityFilterType.Substring:e[o.IdSelectorType.Substring]=[t.entityId.value];break;case a.EntityFilterType.Regex:e[o.IdSelectorType.Regex]=[t.entityId.value];break;case a.EntityFilterType.List:e[o.IdSelectorType.Entity]=t.entityId.value;break}t.entities.value=e,t.entities.source=u.DataSource.Transformed}return t.entities.source===u.DataSource.Message&&(typeof t.entities.value=="string"||Array.isArray(t.entities.value))&&(t.entities.value={[o.IdSelectorType.Entity]:typeof t.entities.value=="string"?[t.entities.value]:t.entities.value},t.entities.source=u.DataSource.Transformed),[o.IdSelectorType.Entity,o.IdSelectorType.Substring,o.IdSelectorType.Regex].forEach(e=>{const r=t.entities.value[e];Array.isArray(r)||(t.entities.value[e]=[])}),t}const D=i.default.object({entities:i.default.object({entity:i.default.array().items(i.default.string()),substring:i.default.array().items(i.default.string()),regex:i.default.array().items(i.default.string())}).custom((t,e)=>{const{entity:r,substring:s,regex:n}=t;return r?.length>0||s?.length>0||n?.length>0?t:e.error("array.length")}).message("ha-wait-until.error.no_entities_provided"),property:i.default.string(),comparator:i.default.string().valid(...Object.values(a.ComparatorType)),value:i.default.alternatives().try(i.default.string(),i.default.number()),valueType:i.default.string(),timeout:i.default.alternatives().try(i.default.string(),i.default.number()).allow("").default("0"),timeoutUnits:i.default.string().valid(...Object.values(a.TimeUnit)),checkCurrentState:i.default.boolean(),entityId:i.default.alternatives().try(i.default.string(),i.default.array().items(i.default.string())),entityIdFilterType:i.default.string().valid(...Object.values(a.EntityFilterType))}).unknown(!0);function N(t){S.RED.nodes.createNode(this,t),this.config=(0,h.migrate)(t);const e=(0,T.getServerConfigNode)(this.config.server),r=(0,b.getHomeAssistant)(e),s=new d.default({node:this,emitter:r.eventBus}),n=new g.default({config:e.config,node:this});s.setStatus(n);const m=new u.default({inputs:R,nodeConfig:this.config,schema:D,transform:A});this.config.blockInputOverrides&&m.disableInputOverrides();const c=(0,f.createControllerDependencies)(this,r),U=new P.default(e.config.ha_boolean),x=new v.default({nodeRedContextService:c.nodeRedContextService,homeAssistant:r,jsonataService:c.jsonataService,transformState:U});new I.default({comparatorService:x,clientEvents:s,inputService:m,node:this,status:n,...c})}