node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
13 lines • 320 kB
HTML
<link rel="stylesheet" href="resources/node-red-contrib-home-assistant-websocket/virtual-select.v1.0.44.min.css"><script src="resources/node-red-contrib-home-assistant-websocket/virtual-select.v1.0.44.min.js"></script><script src="resources/node-red-contrib-home-assistant-websocket/handlebars.min-v4.7.8.js"></script><script type="text/html" data-template-name="ha_entity_filter"><div class="form-row ha-entity-search-row"><label data-i18n="home-assistant.label.filter_results_label"></label> <input type="text"></div><div class="form-row ha-entity-search-row"><ul></ul></div></script>
<script type="text/html" data-template-name="ha_sidebar"><div class="home-assistant-sidebar-container"></div></script>
<script type="text/html" data-template-name="ha_sidebar_toolbar"><div><a class="red-ui-footer-button" id="home-assistant-diagnostics-button" href="#"><i class="fa fa-cogs"></i></a></div></script>
<script type="text/html" data-help-name="ha-api"><p>The API node provides access to all points of the Home Assistant WebSocket and HTTP API. This enables you to interact programmatically with Home Assistant, sending and receiving data through these protocols. It’s a powerful tool for integrating third-party systems, custom automations, or advanced control within Node-RED, offering full access to Home Assistant's core functionalities.</p><h3>Config</h3><dl class="message-properties"><dt>Protocol <span text="required" class="home-assistant-badge">required</span><span class="property-type">string</span></dt><ul><li>Values: <code>websocket|http</code></li><li>Default: <code>websocket</code></li></ul><dd>Protocol to use to access Home Assistant API.</dd><dt>Method<span class="property-type">string</span></dt><ul><li>Values: <code>get|post</code></li></ul><dd>Type of method to use to access the HTTP endpoint.</dd><dt>Path<span class="property-type">string</span></dt><ul><li>Accepts <a href="https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html" rel="noopener noreferrer">Mustache Templates</a></li></ul><dd>URL of the API endpoint.</dd><dt>Params<span class="property-type">Object</span></dt><ul><li>Accepts <a href="https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html" rel="noopener noreferrer">Mustache Templates</a></li></ul><dd>A JSON object with key/value pairs that will be converted into URL parameters.</dd><dt>Data<span class="property-type">Object</span></dt><ul><li>Accepts <a href="https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/mustache-templates.html" rel="noopener noreferrer">Mustache Templates</a> when the data type is JSON</li></ul><dd>JSON Object to send for WebSocket requests and HTTP posts.</dd><dt>Results<span class="property-type">string</span></dt></dl><h3>Input</h3><dl class="message-properties"><dd>All properties need to be under <code>msg.payload</code>.</dd><dt>protocol<span class="property-type">string</span></dt><ul><li>Values: <code>websocket|http</code></li></ul><dd>Overrides or sets the protocol property of the config.</dd><dt>method<span class="property-type">string</span></dt><ul><li>Values: <code>get|post</code></li></ul><dd>Overrides or sets the method property of the config.</dd><dt>path<span class="property-type">string</span></dt><dd>Overrides or sets the path property of the config.</dd><dt>data<span class="property-type">Object|string</span></dt><dd>Overrides or sets the data/params property of the config.</dd><dt>location<span class="property-type">string</span></dt><dd>Overrides or sets the results property of the config.</dd><dt>locationType<span class="property-type">string</span></dt><ul><li>Values: <code>msg|flow|global</code></li></ul><dd>Overrides or sets the results type property of the config.</dd></dl><h3>Output</h3><dl class="message-properties"><dd>Value types:</dd><ul><li><code>results</code>: results of the API request</li><li><code>config</code>: config properties of the node</li></ul></dl><h3>References</h3><dl class="message-properties"><ul><li><a href="https://developers.home-assistant.io/docs/api/rest">http api</a></li><li><a href="https://developers.home-assistant.io/docs/api/websocket">websocket api</a></li></ul></dl></script>
<script type="text/html" id="handlebars-notification-bar" data-template-name="x-tmpl-handlebars"><li class="ha-notification">
<svg width="24" height="24" viewBox="0 0 240 240" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M240 224.762C240 233.012 233.25 239.762 225 239.762H15C6.75 239.762 0 233.012 0 224.762V134.762C0 126.512 4.77 114.993 10.61 109.153L109.39 10.3725C115.22 4.5425 124.77 4.5425 130.6 10.3725L229.39 109.162C235.22 114.992 240 126.522 240 134.772V224.772V224.762Z" fill="#F2F4F9"></path><path d="M229.39 109.153L130.61 10.3725C124.78 4.5425 115.23 4.5425 109.4 10.3725L10.61 109.153C4.78 114.983 0 126.512 0 134.762V224.762C0 233.012 6.75 239.762 15 239.762H107.27L66.64 199.132C64.55 199.852 62.32 200.262 60 200.262C48.7 200.262 39.5 191.062 39.5 179.762C39.5 168.462 48.7 159.262 60 159.262C71.3 159.262 80.5 168.462 80.5 179.762C80.5 182.092 80.09 184.322 79.37 186.412L111 218.042V102.162C104.2 98.8225 99.5 91.8425 99.5 83.7725C99.5 72.4725 108.7 63.2725 120 63.2725C131.3 63.2725 140.5 72.4725 140.5 83.7725C140.5 91.8425 135.8 98.8225 129 102.162V183.432L160.46 151.972C159.84 150.012 159.5 147.932 159.5 145.772C159.5 134.472 168.7 125.272 180 125.272C191.3 125.272 200.5 134.472 200.5 145.772C200.5 157.072 191.3 166.272 180 166.272C177.5 166.272 175.12 165.802 172.91 164.982L129 208.892V239.772H225C233.25 239.772 240 233.022 240 224.772V134.772C240 126.522 235.23 115.002 229.39 109.162V109.153Z" fill="#18BCF2"></path></svg>
<div id="notification-issues">
<span class="ha-issue-count">{{issuesCount}}</span>
<i class="fa fa-exclamation-triangle"></i>
</div>
</li>
</script>
<script type="text/javascript">!function(){"use strict";const e="0.0.0",t="__ALL_TAGS__";var i,n,a,o,s,r,l,u;!function(e){e.Is="is",e.IsNot="is_not",e.IsLessThan="lt",e.IsLessThanOrEqual="lte",e.IsGreaterThan="gt",e.IsGreaterThanOrEqual="gte",e.Includes="includes",e.DoesNotInclude="does_not_include",e.Contains="cont",e.DoesNotContain="does_not_cont",e.StartsWith="starts_with",e.InGroup="in_group",e.JSONata="jsonata",e.IsNull="is_null",e.IsNotNull="is_not_null",e.IsTrue="is_true",e.IsFalse="is_false",e.Regex="regex"}(i||(i={})),function(e){e.Boolean="boolean",e.Float="float",e.Integer="integer",e.PositiveTimePeriod="positive_time_period_dict",e.Select="select",e.String="string"}(n||(n={})),function(e){e.BinarySensor="binary_sensor",e.Button="button",e.Number="number",e.Select="select",e.Sensor="sensor",e.Switch="switch",e.Text="text",e.Time="time"}(a||(a={})),function(e){e.Exact="exact",e.List="list",e.Regex="regex",e.Substring="substring"}(o||(o={})),function(e){e.Action="api-call-service",e.API="ha-api",e.CurrentState="api-current-state",e.Device="ha-device",e.Entity="ha-entity",e.EventsAll="server-events",e.EventsCalendar="ha-events-calendar",e.EventsState="server-state-changed",e.FireEvent="ha-fire-event",e.GetEntities="ha-get-entities",e.GetHistory="api-get-history",e.PollState="poll-state",e.RenderTemplate="api-render-template",e.Select="ha-select",e.Sentence="ha-sentence",e.TriggerState="trigger-state",e.Tag="ha-tag",e.Time="ha-time",e.WaitUntil="ha-wait-until",e.Webhook="ha-webhook",e.Zone="ha-zone",e.Server="server",e.DeviceConfig="ha-device-config",e.EntityConfig="ha-entity-config",e.BinarySensor="ha-binary-sensor",e.Button="ha-button",e.Number="ha-number",e.Sensor="ha-sensor",e.Switch="ha-switch",e.Text="ha-text",e.TimeEntity="ha-time-entity",e.UpdateConfig="ha-update-config"}(s||(s={})),function(e){e.Get="get",e.Set="set",e.Listen="listen"}(r||(r={})),function(e){e.Message="msg",e.Flow="flow",e.Global="global",e.Boolean="bool",e.JSON="json",e.Date="date",e.JSONata="jsonata",e.Number="num",e.String="str",e.None="none",e.Config="config",e.Data="data",e.Entity="entity",e.EntityState="entityState",e.EventData="eventData",e.Headers="headers",e.Params="params",e.TriggerId="triggerId",e.PrevEntity="prevEntity",e.Results="results",e.Regex="re",e.Value="value",e.PreviousValue="previousValue",e.CalendarItem="calendarItem",e.DeviceId="deviceId",e.Enviroment="env"}(l||(l={})),function(e){e.Milliseconds="milliseconds",e.Seconds="seconds",e.Minutes="minutes",e.Hours="hours",e.Days="days"}(u||(u={}));const p=(e,t)=>{let i=RED._(`node-red-contrib-home-assistant-websocket/all:${e}`,t);return-1!==i.indexOf("\n")&&(i=i.split("\n").map((e=>`<p>${e}</p>`)).join("")),i};function d(e,t){if(e===t)return!0;if("object"!=typeof e||"object"!=typeof t||null==e||null==t)return!1;const i=Object.keys(e),n=Object.keys(t);if(i.length<n.length)return!1;for(const a of n){if(!i.includes(a))return!1;if(!d(e[a],t[a]))return!1}return!0}function c(e,t){return e.split(".").reduce(((e,t)=>e[t]),t)}const v={},y={},g={},h={},f={},m={},b={};function T(e){return e.split("/")[2]}function _(e,t){const i=e.label,n=t.label;return i===n?0:i.localeCompare(n)}function S(e,t){const i=E(e);if(t&&(null==i?void 0:i.length)){const e=i.find((e=>e.area_id===t));if(e)return e.name}return p("ha-device.ui.no_area")}function E(e){var t;return null!==(t=v[e])&&void 0!==t?t:[]}function w(e){var t;return null!==(t=y[e])&&void 0!==t?t:[]}function D(e,t){return b[e].find((e=>e.id===t))}function O(e,t,i="."){return Object.keys(e).reduce(((n,a)=>{const o=e[a],s=[t,a].filter(Boolean).join(i);return["object"==typeof o,null!==o,!(o instanceof Date),!(o instanceof RegExp),!(Array.isArray(o)&&0===o.length)].every(Boolean)?Object.assign(Object.assign({},n),O(o,s,i)):Object.assign(Object.assign({},n),{[s]:o})}),{})}let x;const I={show:e=>{RED.view.state(RED.state.EDITING);const t={title:p("home-assistant.label.filter_results_title"),width:"inherit",buttons:[{id:"node-dialog-cancel",text:p("home-assistant.label.cancel"),click:()=>{RED.tray.close()}},{id:"node-dialog-ok",text:p("home-assistant.label.done"),class:"primary",click:()=>{e.complete(x),RED.tray.close()}}],open:t=>{const i=t.find(".red-ui-tray-body");RED.editor.buildEditForm(i,"dialog-form","ha_entity_filter","node-red-contrib-home-assistant-websocket/all"),t.i18n(),$("#dialog-form").addClass("home-assistant"),i.find("select").val(e.filterType),i.find("input").val(e.filter).on("input",(t=>{const n=((e,t,i)=>{let n=[];if("regex"===i)try{const i=new RegExp(t);n=e.filter((e=>i.test(e.entity_id)))}catch(e){n=[]}else"substring"===i&&(n=e.filter((e=>e.entity_id.includes(t))));return n.sort(function(e){function t(e){let t,i=1;return"string"==typeof e&&e.startsWith("-")?(i=-1,t=e.substring(1)):t=e,function(e,n){const a=e[t],o=n[t];return("string"==typeof a&&"string"==typeof o?a.localeCompare(o):a<o?-1:a>o?1:0)*i}}return function(i,n){let a=0,o=0;const s=null==e?void 0:e.length;for(;0===o&&a<s;)o=t(e[a])(i,n),a++;return o}}(["entity_id"]))})(e.entities,t.target.value,e.filterType);x=t.target.value,i.find("ul").html((e=>e.length?e.map((e=>`<li>${e.entity_id}</li>`)).join(""):`<li>${p("home-assistant.label.no_matches_found")}</li>`)(n))})).trigger("input")}};RED.tray.show(t)}},C=({filter:e,filterType:t,entities:i,complete:n})=>{RED.editor.showTypeEditor("ha_entity_filter",{filter:e,filterType:t,entities:i,complete:n})};var j,R;let k;!function(e){e.Trigger="trigger",e.Response="response"}(j||(j={})),function(e){e.Dynamic="dynamic",e.Fixed="fixed"}(R||(R={}));const A={};function P(){const e=[s.BinarySensor,s.Button,s.Number,s.Select,s.Sensor,s.Switch,s.Text,s.TimeEntity];return"type"in k&&(null==k?void 0:k.type)&&e.includes(k.type)}function L(){const t=function(){let e=$("#node-input-server").val();if(P()){const t=RED.nodes.node($("#node-input-entityConfig").val());e=null==t?void 0:t.server}if(e&&"_ADD_"!==e)return e}();return t&&A[t]?A[t]:e}function N(){return L()!==e}function B(e){return"_ADD_"===$(`#node-input-${e}`).val()}function H(e){k=e;const t="type"in k&&k.type;!function(){const e="type"in k&&k.type;switch(e){case s.BinarySensor:case s.Button:case s.Number:case s.Select:case s.Sensor:case s.Switch:case s.Text:case s.TimeEntity:B("entityConfig")||M(e);break;case s.Device:case s.Sentence:case s.Webhook:B("server")||M(e);break;case s.EventsAll:case s.EventsCalendar:case s.EventsState:case s.PollState:case s.Tag:case s.Time:case s.TriggerState:case s.Zone:break;default:!function(){const e=$("<div />",{id:"exposeToHa",class:"form-row checkbox-option"+("type"in k&&"trigger-state"===k.type?"-left":"")});$("<input />",{type:"checkbox",id:"node-input-exposeToHomeAssistant",checked:k.exposeToHomeAssistant}).on("change",(function(){$("#haConfigRow").toggle(!0===$("#node-input-exposeToHomeAssistant").is(":checked"))})).appendTo(e),$("<label />",{for:"node-input-exposeToHomeAssistant",text:"Expose to Home Assistant"}).appendTo(e);const t=$("<div />",{class:"form-row",id:"haConfigRow"}),i=$("<ol />",{id:"haConfig"}).appendTo(t),n=k.haConfig||[{property:"name",value:""},{property:"icon",value:""}];i.editableList({addButton:!1,header:$("<div>Home Assistant Config (optional)</div>"),addItem:function(e,t,i){const n=$("<div />").appendTo(e),a=$("<label>").appendTo(n);$("<span>").text(i.property.replace(/_/g," ")).appendTo(a),$("<input />",{type:"hidden",name:"property",value:i.property}).appendTo(a),$("<input />",{type:"text",name:"value",value:i.value}).attr("autocomplete","disable").appendTo(a)}}).editableList("addItems",n),$("#dialog-form").append(e).append(t),$("#node-input-exposeToHomeAssistant").trigger("change")}()}}(),$("#node-input-server, #node-input-entityConfig").on("change",(()=>{switch(t){case s.BinarySensor:case s.Button:case s.Number:case s.Select:case s.Sensor:case s.Switch:case s.Text:case s.TimeEntity:B("entityConfig")||M(t);break;case s.Device:M(t);break;case s.Sentence:{const e=$("#node-input-mode").val();$("#exposed-as-row").toggle(e===j.Trigger),B("server")||M(t)}break;case s.Webhook:B("server")||M(t);break;case s.EventsAll:case s.EventsCalendar:case s.EventsState:case s.PollState:case s.Tag:case s.TriggerState:case s.Zone:case s.Time:default:!function(){$("#node-input-exposeAsEntityConfig").closest("div.form-row").toggle(N()),N()||$("#node-input-exposeToHomeAssistant").prop("checked",!1).trigger("change");$("#exposeToHa").toggle(N())}()}})),P()&&$("#node-input-mode").on("change",F)}const V={[s.BinarySensor]:"1.1.0",[s.Button]:"1.0.4",[s.Device]:"4.0.2",[s.Number]:"1.3.0",[s.Select]:"1.4.0",[s.Sentence]:"4.1.0",[s.Sensor]:"1.1.0",[s.Switch]:"1.1.0",[s.Tag]:"0.5.0",[s.Text]:"1.3.0",[s.TimeEntity]:"2.1.0",[s.Webhook]:"1.6.0"};function M(e){const t=V[e],i=void 0===t||(n=t,a=L(),(n=n.split(".").map((e=>e.padStart(5))).join("."))<=a.split(".").map((e=>e.padStart(5))).join("."));var n,a;const o=N()&&i;if(!$("#integrationAlert").length){const e=`\n <div id="integrationAlert" class="ui-state-error ha-alert-box">\n This node requires <a href="https://github.com/zachowj/hass-node-red" target="_blank">Node-RED custom integration ${i?"":`version ${t}+`} <i class="fa fa-external-link external-link"></i></a> to be installed in Home Assistant for it to function.\n </div>`;$("#dialog-form").prepend(e)}$("#integrationAlert").toggle(!o)}function F(){const e=$("#node-input-mode").val();$("#exposed-as-row").toggle(e===r.Listen)}var q;!function(e){e.IssuesUpdated="home-assistant:issues-updated",e.OpenIssues="home-assistant:open-issues"}(q||(q={}));const G=Handlebars.compile($("#handlebars-notification-bar").html());let W,J=[],z=!1;function U(){return J}var K=e=>{var t;try{null===(t=null===navigator||void 0===navigator?void 0:navigator.clipboard)||void 0===t||t.writeText(e)}catch(t){const i=document.createElement("textarea");i.textContent=e;const n=document.getElementsByTagName("body")[0];n.appendChild(i),i.select(),document.execCommand("copy"),n.removeChild(i)}};Handlebars.registerHelper("backgroundcolor",(function(e){return`style="background-color: ${e};"`})),Handlebars.registerHelper("ishidden",(function(e){return e?'class="ha-hidden"':""})),Handlebars.registerHelper("i18n",(function(e){return p(e)}));const Z=Handlebars.compile($("#handlebars-sidebar-list").html()),X=Handlebars.compile($("#handlebars-sidebar-filter").html()),Y=Handlebars.compile($("#handlebars-sidebar-issues").html()),Q=Handlebars.compile($("#handlebars-sidebar-issues-list").html());let ee,te,ie,ne;function ae(){[{type:s.Server,section:ee},{type:s.EntityConfig,section:te},{type:s.DeviceConfig,section:ie}].forEach((({type:e,section:t})=>{t.content.empty();const i=function(e){const t=[],i=new Set;return RED.nodes.eachConfig((function(n){return n.type===e&&(n.entityType&&i.add(n.entityType),t.push({name:n.name||n.id,id:n.id,count:n.users.length,type:n.entityType})),!0})),{list:t.sort(((e,t)=>e.name.localeCompare(t.name))),types:[...i].sort()}}(e);i.types.length>1&&$(X(i)).on("change","select",(function(){const e=$(this).val();t.content.find(".ha-list-row").each((function(){const t=$(this);"__all__"===e||t.data("type")===e?t.show():t.hide()}))})).appendTo(t.content),$(Z(i)).on("click",".ha-list-row-name",(function(t){t.stopPropagation(),RED.editor.editConfig("",e,$(this).parent().data("id"),"")})).on("click",".ha-list-row-count",(function(e){e.stopPropagation(),RED.search.show($(this).parent().data("id"))})).appendTo(t.content)}))}function oe(e){return e.map((e=>{const t=RED.nodes.node(e.nodeId),i=null==t?void 0:t._def.icon,n=!!(null==i?void 0:i.startsWith("font-awesome/")),a=n?i.slice(13):i;return{color:t._def.color,icon:a,isFontAwesomeIcon:n,name:t?t._def.label.call(t):e.nodeId,id:e.nodeId,issues:e.messages,hide:e.hide}}))}function se(e){ne&&($(Y({issues:e})).on("click","#ha-issues-toggle-hidden",(function(){this.checked?$(".ha-issues-list").addClass("ha-show-hidden"):$(".ha-issues-list").removeClass("ha-show-hidden")})).appendTo(ne.content),ne.content.find(".ha-issues-list").append(re(e)).on("click",".ha-find-node",(function(e){e.stopPropagation(),RED.view.reveal($(this).parents("li").data("id"))})).on("click",".ha-edit-node",(function(e){e.stopPropagation();const t=$(this).parents("li").data("id"),i=RED.nodes.node(t);i&&RED.editor.edit(i)})).on("click",".ha-hidden-issue",(function(e){e.stopPropagation();const t=$(this).parents("li[data-id]"),i=t.data("id"),n=$(this).data("popover");n&&(n.close(),n.setContent(t.hasClass("ha-hidden")?p("home-assistant.sidebar.issues.show_issue"):p("home-assistant.sidebar.issues.hide_issue"))),$.ajax({url:"homeassistant/issues/hidden",type:"POST",data:JSON.stringify({issue:i}),contentType:"application/json",success:()=>{RED.notify(p("home-assistant.service.issue.issue_hidden",{issue_id:i}),{type:"success",id:`issue${i}`,timeout:2e3}),t.addClass("ha-hidden")},error:function(e,t){let n="";n=500===e.status?p("home-assistant.service.issue.failed_to_hide",{issue_id:i}):0===e.status?p("home-assistant.service.issue.no-response"):p("home-assistant.service.issue.unexpected",{status:e.status,message:t}),RED.notify(n,"error")}})})))}function re(e){const t=$(Q({issues:oe(e)}));return $(".ha-edit-node",t).each((function(){RED.popover.tooltip($(this),p("home-assistant.sidebar.issues.open_editor"))})),$(".ha-find-node",t).each((function(){RED.popover.tooltip($(this),p("home-assistant.sidebar.issues.find_node"))})),$(".ha-hidden-issue",t).each((function(){const e=$(this),t=e.parents("li").hasClass("ha-hidden"),i=RED.popover.tooltip(e,p(t?"home-assistant.sidebar.issues.show_issue":"home-assistant.sidebar.issues.hide_issue"));$(this).data("popover",i)})),t}var le,ue,pe=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1});try{const i=JSON.parse(e.data);i.entity_id?(t.entityId=i.entity_id,delete i.entity_id,t.data=Object.keys(i).length?JSON.stringify(i):""):t.entityId=""}catch(e){}return t}},{version:2,up:e=>{const t=Object.assign(Object.assign({},e),{version:2,outputProperties:[]});return"none"!==e.output_location_type&&(t.outputProperties=[{property:e.output_location,propertyType:e.output_location_type,value:"",valueType:"data"}]),t}},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3,queue:"none"})},{version:4,up:e=>Object.assign(Object.assign({},e),{version:4,target:{entityId:(null==e?void 0:e.entityId)?e.entityId.split(",").map((e=>e.trim())):[],areaId:[],deviceId:[]},domain:e.service_domain,mergeContext:e.mergecontext,entityId:void 0,service_domain:void 0,mergecontext:void 0})},{version:5,up:e=>{var t,i,n;return Object.assign(Object.assign({},e),{version:5,areaId:null===(t=e.target)||void 0===t?void 0:t.areaId,deviceId:null===(i=e.target)||void 0===i?void 0:i.deviceId,entityId:null===(n=e.target)||void 0===n?void 0:n.entityId,target:void 0})}},{version:6,up:e=>{const t=Object.assign(Object.assign({},e),{version:6,floorId:[],labelId:[]});return(e.domain||e.service)&&(t.action=`${e.domain}.${e.service}`),t}},{version:7,up:e=>Object.assign(Object.assign({},e),{version:7,blockInputOverrides:!1})}],de=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,outputProperties:[],location:void 0,locationType:void 0});return"none"!==e.locationType&&(t.outputProperties=[{property:e.location,propertyType:e.locationType,value:"",valueType:"results"}]),t}}],ce=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}],ve=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,ha_boolean:e.ha_boolean||"y|yes|true|on|home|open",rejectUnauthorizedCerts:void 0===e.rejectUnauthorizedCerts||e.rejectUnauthorizedCerts,connectionDelay:void 0===e.connectionDelay||e.connectionDelay,cacheJson:void 0===e.cacheJson||e.cacheJson})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,heartbeat:!1,heartbeatInterval:30})},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3,areaSelector:"friendlyName",deviceSelector:"friendlyName",entitySelector:"friendlyName"})},{version:4,up:e=>Object.assign(Object.assign({},e),{version:4,statusSeparator:"at: ",statusYear:"hidden",statusMonth:"short",statusDay:"numeric",statusHourCycle:"h23",statusTimeFormat:"h:m"})},{version:5,up:e=>Object.assign(Object.assign({},e),{version:5,enableGlobalContextStore:!0})}],ye=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,blockInputOverrides:!1,entity_location:"data",halt_if_compare:"is",override_payload:!1===e.override_payload?"none":"msg",override_data:!1===e.override_data?"none":"msg",state_location:"payload",state_type:"str"})},{version:2,up:e=>{const t=Object.assign(Object.assign({},e),{version:2,outputProperties:[],state_location:void 0,override_payload:void 0,entity_location:void 0,override_data:void 0,override_topic:void 0});return"none"!==e.override_payload&&t.outputProperties.push({property:e.state_location,propertyType:e.override_payload,value:"",valueType:"entityState"}),"none"!==e.override_data&&t.outputProperties.push({property:e.entity_location,propertyType:e.override_data,value:"",valueType:"entity"}),!0===e.override_topic&&t.outputProperties.push({property:"topic",propertyType:"msg",value:"",valueType:"triggerId"}),t}},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3,for:0,forType:"num",forUnits:"minutes"})}],ge=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,exposeAsEntityConfig:""});return t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}}],he=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}],fe=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,inputOverride:"allow"})},{version:2,up:e=>{const t=Object.assign(Object.assign({},e),{version:2});return t.config.push({property:"state_class",value:""}),t.config.push({property:"last_reset",value:""}),t}},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3})}],me=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2})},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3})},{version:4,up:e=>Object.assign(Object.assign({},e),{version:4})},{version:5,up:e=>Object.assign(Object.assign({},e),{version:5})},{version:6,up:e=>Object.assign(Object.assign({},e),{version:6})}],be=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0,waitForRunning:void 0===e.waitForRunning||e.waitForRunning})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,outputProperties:[{property:"payload",propertyType:"msg",value:"",valueType:"eventData"},{property:"topic",propertyType:"msg",value:'$outputData("eventData").event_type',valueType:"jsonata"},{property:"event_type",propertyType:"msg",value:'$outputData("eventData").event_type',valueType:"jsonata"}]})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,eventType:e.event_type,event_type:void 0})},{version:3,up:e=>{const t=Object.assign(Object.assign({},e),{version:3,exposeAsEntityConfig:""});return t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}}],Te=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}];!function(e){e.Floor="floor",e.Area="area",e.Device="device",e.Entity="entity",e.Label="label",e.Substring="substring",e.Regex="regex"}(le||(le={})),function(e){e.Floor="floor_registry",e.Area="area_registry",e.Device="device_registry",e.State="state_object",e.Label="label_registry"}(ue||(ue={}));var _e=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0,state_type:void 0!==e.state_type?e.state_type:"str",halt_if_type:void 0!==e.halt_if_type?e.halt_if_type:"str",halt_if_compare:void 0!==e.halt_if_compare?e.halt_if_compare:"is"})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,ignorePrevStateNull:!1,ignorePrevStateUnknown:!1,ignorePrevStateUnavailable:!1,ignoreCurrentStateUnknown:!1,ignoreCurrentStateUnavailable:!1})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,for:void 0!==e.for?e.for:"0",forType:e.forType||"num",forUnits:e.forUnits||"minutes"})},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3,outputProperties:[{property:"payload",propertyType:"msg",value:"",valueType:"entityState"},{property:"data",propertyType:"msg",value:"",valueType:"eventData"},{property:"topic",propertyType:"msg",value:"",valueType:"triggerId"}]})},{version:4,up:e=>{var t;const i=Object.assign(Object.assign({},e),{version:4});return"substring"===e.entityidfiltertype&&(null===(t=e.entityidfilter)||void 0===t?void 0:t.includes(","))&&(i.entityidfiltertype="list",i.entityidfilter=e.entityidfilter.split(",").map((e=>e.trim())).filter((e=>e.length>0))),i}},{version:5,up:e=>{const t=Object.assign(Object.assign({},e),{version:5,entityId:e.entityidfilter,entityIdType:e.entityidfiltertype,ifState:e.haltifstate,ifStateType:e.halt_if_type,ifStateOperator:e.halt_if_compare,outputInitially:e.outputinitially,stateType:e.state_type,outputOnlyOnStateChange:e.output_only_on_state_change,exposeAsEntityConfig:""});return t.entityidfilter=void 0,t.entityidfiltertype=void 0,t.haltifstate=void 0,t.halt_if_type=void 0,t.halt_if_compare=void 0,t.outputinitially=void 0,t.state_type=void 0,t.output_only_on_state_change=void 0,t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}},{version:6,up:e=>{const t=Object.assign(Object.assign({},e),{version:6,entities:[],entityId:void 0,entityIdType:void 0}),i={[le.Entity]:[],[le.Substring]:[],[le.Regex]:[]};switch(e.entityIdType){case"list":i[le.Entity]=e.entityId;break;case"exact":i[le.Entity]=[e.entityId];break;case"substring":i[le.Substring]=[e.entityId];break;case"regex":i[le.Regex]=[e.entityId]}return t.entities=i,t}}],$e=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}],Se=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,outputType:e.output_type,outputEmptyResults:e.output_empty_results,outputLocationType:e.output_location_type,outputLocation:e.output_location,outputResultsCount:e.output_results_count});return t.output_type=void 0,t.output_empty_results=void 0,t.output_location_type=void 0,t.output_location=void 0,t.output_results_count=void 0,t}}],Ee=[{version:0,up:e=>{const t=Object.assign(Object.assign({},e),{version:0,output_type:void 0===e.output_type?"array":e.output_type});return void 0===t.output_location&&(t.output_location="payload",t.output_location_type="msg"),t}},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,startDate:e.startdate,endDate:e.enddate,entityId:e.entityid,outputType:e.output_type,outputLocationType:e.output_location_type,outputLocation:e.output_location,entityIdType:"includes"===e.entityidtype?"regex":"equals"});return t.startdate=void 0,t.enddate=void 0,t.entityid=void 0,t.entityidtype=void 0,t.output_type=void 0,t.output_location_type=void 0,t.output_location=void 0,t}}],we=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,mode:"out"===e.mode?"set":"listen"})}],De=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,state_type:"str",halt_if_type:"str",halt_if_compare:"is",updateIntervalUnits:"seconds"})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,updateIntervalType:"num"})},{version:3,up:e=>{const t=Object.assign(Object.assign({},e),{version:3,entityId:e.entity_id,exposeAsEntityConfig:"",ifState:e.halt_if,ifStateType:e.halt_if_type,ifStateOperator:e.halt_if_compare,outputInitially:e.outputinitially,outputOnChanged:e.outputonchanged,outputProperties:[{property:"payload",propertyType:l.Message,value:"",valueType:"entityState"},{property:"data",propertyType:l.Message,value:"",valueType:"entity"},{property:"topic",propertyType:l.Message,value:"",valueType:"triggerId"}],stateType:e.state_type,updateInterval:e.updateinterval});return t.entity_id=void 0,t.updateinterval=void 0,t.outputinitially=void 0,t.outputonchanged=void 0,t.state_type=void 0,t.halt_if=void 0,t.halt_if_type=void 0,t.halt_if_compare=void 0,t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}}],Oe=[{version:0,up:e=>{const t=Object.assign(Object.assign({},e),{version:0});return void 0===t.templateLocationType&&(t.templateLocation="template",t.templateLocationType="msg"),void 0===t.resultsLocationType&&(t.resultsLocation="payload",t.resultsLocationType="msg"),t}}],xe=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,mode:"out"===e.mode?"set":"listen"})}],Ie=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}],Ce=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,exposeAsEntityConfig:"",response:""})},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,mode:"trigger",triggerResponseType:"fixed",responseType:"jsonata",responseTimeout:1e3})}],je=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})}],Re=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,outputProperties:[{property:"payload",propertyType:"msg",value:"",valueType:"eventData"},{property:"topic",propertyType:"msg",value:"",valueType:"triggerId"}]})},{version:2,up:e=>{var t;const i=Object.assign(Object.assign({},e),{version:2,exposeAsEntityConfig:null!==(t=e.exposeAsEntityConfig)&&void 0!==t?t:""});return i.exposeToHomeAssistant=void 0,i.haConfig=void 0,i}}],ke=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,mode:"out"===e.mode?"set":"listen"})}],Ae=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,sunday:!0,monday:!0,tuesday:!0,wednesday:!0,thursday:!0,friday:!0,saturday:!0})},{version:2,up:e=>{const t="jsonata"===e.payloadType&&"$entity().state"===e.payload;return Object.assign(Object.assign({},e),{version:2,outputProperties:[{property:"payload",propertyType:"msg",value:t?"":e.payload,valueType:t?"entityState":e.payloadType},{property:"data",propertyType:"msg",value:"",valueType:"entity"},{property:"topic",propertyType:"msg",value:"",valueType:"triggerId"}],payload:void 0,payloadType:void 0})}},{version:3,up:e=>{const t=Object.assign(Object.assign({},e),{version:3,exposeAsEntityConfig:""});return t.debugenabled=void 0,t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}},{version:4,up:e=>Object.assign(Object.assign({},e),{version:4,ignorePastDate:!1})}],Pe=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>Object.assign(Object.assign({},e),{version:1,inputs:1,enableInput:!0})},{version:2,up:e=>{var t;const i=Object.assign(Object.assign({},e),{version:2});return"substring"===e.entityidfiltertype&&(null===(t=e.entityid)||void 0===t?void 0:t.includes(","))&&(i.entityidfiltertype="list",i.entityid=e.entityid.split(",").map((e=>e.trim())).filter((e=>e.length>0))),i}},{version:3,up:e=>{const t=Object.assign(Object.assign({},e),{version:3,entityId:e.entityid,entityIdType:e.entityidfiltertype,debugEnabled:e.debugenabled,customOutputs:e.customoutputs,outputInitially:e.outputinitially,stateType:e.state_type,exposeAsEntityConfig:""});return t.entityid=void 0,t.entityidfiltertype=void 0,t.debugenabled=void 0,t.customoutputs=void 0,t.outputinitially=void 0,t.state_type=void 0,t}},{version:4,up:e=>{const t=Object.assign(Object.assign({},e),{version:4});return void 0===e.stateType&&(t.stateType="str"),t}},{version:5,up:e=>{const t=Object.assign(Object.assign({},e),{version:5,entities:[],entityId:void 0,entityIdType:void 0}),i={[le.Entity]:[],[le.Substring]:[],[le.Regex]:[]};switch(e.entityIdType){case"list":i[le.Entity]=e.entityId;break;case"exact":i[le.Entity]=[e.entityId];break;case"substring":i[le.Substring]=[e.entityId];break;case"regex":i[le.Regex]=[e.entityId]}return t.entities=i,t}}],Le=[{version:0,up:e=>{const t=Object.assign(Object.assign({},e),{version:0,entityIdFilterType:e.entityIdFilterType||"exact",timeoutType:e.timeoutType||"num"});return void 0===t.blockInputOverrides&&(t.blockInputOverrides=!0),void 0===t.checkCurrentState&&(t.checkCurrentState=!1),t}},{version:1,up:e=>{var t;const i=Object.assign(Object.assign({},e),{version:1});return"substring"===e.entityIdFilterType&&(null===(t=e.entityId)||void 0===t?void 0:t.includes(","))&&(i.entityIdFilterType="list",i.entityId=e.entityId.split(",").map((e=>e.trim())).filter((e=>e.length>0))),i}},{version:2,up:e=>{const t=Object.assign(Object.assign({},e),{version:2,outputProperties:[],entityLocation:void 0,entityLocationType:void 0});return"none"!==e.entityLocationType&&t.outputProperties.push({property:e.entityLocation,propertyType:e.entityLocationType,value:"",valueType:l.Entity}),t}},{version:3,up:e=>{const t=Object.assign(Object.assign({},e),{version:3,entities:[],entityId:void 0,entityIdFilterType:void 0}),i={[le.Entity]:[],[le.Substring]:[],[le.Regex]:[]};switch(e.entityIdFilterType){case"list":i[le.Entity]=e.entityId;break;case"exact":i[le.Entity]=[e.entityId];break;case"substring":i[le.Substring]=[e.entityId];break;case"regex":i[le.Regex]=[e.entityId]}return t.entities=i,t}}],Ne=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,outputProperties:[{property:"topic",propertyType:"msg",value:"",valueType:"triggerId"}],payloadLocation:void 0,payloadLocationType:void 0,headersLocation:void 0,headersLocationType:void 0});return"none"!==e.payloadLocationType&&t.outputProperties.push({property:e.payloadLocation,propertyType:e.payloadLocationType,value:"",valueType:"data"}),"none"!==e.headersLocationType&&t.outputProperties.push({property:e.headersLocation,propertyType:e.headersLocationType,value:"",valueType:"headers"}),t}},{version:2,up:e=>Object.assign(Object.assign({},e),{version:2,method_post:!0,method_put:!0,method_get:!1,method_head:!1})},{version:3,up:e=>Object.assign(Object.assign({},e),{version:3,exposeAsEntityConfig:""})}],Be=[{version:0,up:e=>Object.assign(Object.assign({},e),{version:0})},{version:1,up:e=>{const t=Object.assign(Object.assign({},e),{version:1,exposeAsEntityConfig:""});return t.exposeToHomeAssistant=void 0,t.haConfig=void 0,t}}];const He={[s.API]:de,[s.BinarySensor]:ce,[s.Action]:pe,[s.Server]:ve,[s.CurrentState]:ye,[s.Device]:ge,[s.DeviceConfig]:he,[s.Entity]:fe,[s.EntityConfig]:me,[s.EventsAll]:be,[s.EventsCalendar]:Te,[s.EventsState]:_e,[s.FireEvent]:$e,[s.GetEntities]:Se,[s.GetHistory]:Ee,[s.Number]:we,[s.PollState]:De,[s.RenderTemplate]:Oe,[s.Select]:xe,[s.Sensor]:Ie,[s.Sentence]:Ce,[s.Switch]:je,[s.TriggerState]:Pe,[s.Tag]:Re,[s.Text]:ke,[s.Time]:Ae,[s.WaitUntil]:Le,[s.Webhook]:Ne,[s.Zone]:Be};function Ve(e){var t;const i=function(e){var t;const i=null!==(t=Me(e))&&void 0!==t?t:[],n=i.reduce(((e,t)=>t.version>e?t.version:e),0);return n}(e.type);if(void 0!==e.version&&e.version>=i)return e;const n=null===(t=function(e,t=-1){const i=Me(e),n=null==i?void 0:i.find((e=>e.version===Number(t)+1));return n}(e.type,e.version))||void 0===t?void 0:t.up;if(n){return Ve(n(e))}return e}function Me(e){return He[e]}const Fe=(e,t)=>{let i;for(i in t)t[i].forEach((t=>{RED.nodes.addLink(Object.assign(Object.assign({},t),{[i]:RED.nodes.node(e)}))}))},qe=()=>{let e;do{e=RED.nodes.id()}while(RED.nodes.node(e));return e},Ge=e=>{const t={source:RED.nodes.getNodeLinks(e.id),target:RED.nodes.getNodeLinks(e.id,1)},i=qe();if(e.g){const t=RED.nodes.node(e.id);t&&RED.group.removeFromGroup(RED.nodes.group(e.g),t)}RED.nodes.remove(e.id),(e=>{var t,i;RED.nodes.import({type:s.EntityConfig,id:e.id,server:e.server,deviceConfig:"",name:`${e.entityType.replace("_"," ")} config for ${e.name||e.id}`,version:RED.settings.get("haEntityConfigVersion",0),entityType:e.entityType,haConfig:null!==(t=e.config)&&void 0!==t?t:[],resend:null!==(i=e.resend)&&void 0!==i&&i})})(e),((e,t)=>{var i,n,o,r,l;let u={id:t,name:e.name,inputs:1,outputs:1,version:0,g:e.g,x:e.x,y:e.y,z:e.z,entityConfig:e.id};switch(e.entityType){case a.BinarySensor:case a.Sensor:u=Object.assign(Object.assign({},u),{type:e.entityType===a.Sensor?s.Sensor:s.BinarySensor,state:null!==(i=e.state)&&void 0!==i?i:"payload",stateType:null!==(n=e.stateType)&&void 0!==n?n:"msg",attributes:null!==(o=e.attributes)&&void 0!==o?o:[],inputOverride:null!==(r=e.inputOverride)&&void 0!==r?r:"allow",outputProperties:"none"===e.outputLocationType?[]:[{property:e.outputLocation,propertyType:e.outputLocationType,value:"",valueType:"data"}]});break;case a.Switch:default:u=Object.assign(Object.assign({},u),{type:s.Switch,outputs:2,outputOnStateChange:null!==(l=e.outputOnStateChange)&&void 0!==l&&l,enableInput:!0,outputProperties:"none"===e.outputPayloadType?[]:[{property:"payload",propertyType:"msg",value:e.outputPayload,valueType:e.outputPayloadType}]})}RED.nodes.import(u)})(e,i),Fe(i,t);const n=RED.nodes.node(i);n&&(RED.nodes.moveNodeToTab(n,e.z),e.g&&RED.group.addToGroup(RED.nodes.group(e.g),n),n.changed=!0),RED.view.redraw(!0)},We=(e,t)=>{const i={source:RED.nodes.getNodeLinks(e.id),target:RED.nodes.getNodeLinks(e.id,1)};if(e.g){const t=RED.nodes.node(e.id);t&&RED.group.removeFromGroup(RED.nodes.group(e.g),t)}RED.nodes.import([{type:s.EntityConfig,id:e.id,server:e.server,deviceConfig:"",name:`exposed as for ${e.name||e.id}`,version:RED.settings.get("haEntityConfigVersion",0),entityType:a.Switch,haConfig:null!=t?t:[],resend:!1}],{importMap:{[e.id]:"replace"}});const n=qe();RED.nodes.import(Object.assign(Object.assign({},e),{id:n,exposeAsEntityConfig:e.id})),Fe(n,i);const o=RED.nodes.node(n);o&&(RED.nodes.moveNodeToTab(o,e.z),e.g&&RED.group.addToGroup(RED.nodes.group(e.g),o),o.changed=!0),RED.view.redraw(!0)};let Je;const ze=[s.Device,s.EventsAll,s.EventsState,s.PollState,s.Tag,s.Time,s.Zone];function Ue(e){const t=RED.nodes.convertNode(e,!1),i=ze.includes(e.type)&&(!0===e.exposeToHomeAssistant||e.type===s.Device&&e.version<1)?t.haConfig:void 0,n=Ve(t);let a;for(a in"type"in n&&n.type===s.Entity?Ge(n):i&&We(n,i),n)void 0===n[a]?delete e[a]:e[a]=n[a];e.changed=!0,RED.editor.updateNodeProperties(e);const o=$("#upgrade-ha-node");return o.is(":visible")&&0===Qe()&&o.hide(),e}function Ke(){const e="home-assistant.ui.migrations",t=p(`${e}.button_ok`),i=p(`${e}.button_cancel`);$("#ha-dialog-confirm").dialog({resizable:!1,height:"auto",width:400,modal:!0,buttons:{[t]:function(){$(this).dialog("close"),function(){const e=[],t=t=>{Xe(t)&&!Ze(t)&&e.push(t)};RED.nodes.eachNode(t),RED.nodes.eachConfig(t),e.forEach((e=>Ue(e))),RED.nodes.dirty(!0),RED.notify(p("home-assistant.ui.migrations.all_nodes_updated")),RED.view.redraw()}()},[i]:function(){$(this).dialog("close")}}})}function Ze(e){const t=RED.settings.get(`${e.type.split("-").reduce(((e,t,i)=>e.concat(`${i?t[0].toUpperCase():t[0]}${t.slice(1)}`)),[]).join("")}Version`,-1);const i=Ye(e)&&void 0===e.version?e._def.defaults.version.value:e.version;return void 0!==i&&i>=t}function Xe(e){const t=RED.nodes.registry.getNodeSetForType(e.type);return"node-red-contrib-home-assistant-websocket"===(null==t?void 0:t.module)}function Ye(e){return(null==e?void 0:e.type)&&[s.Server,s.EntityConfig,s.DeviceConfig].includes(e.type)}function Qe(){let e=0;const t=t=>{Xe(t)&&!Ze(t)&&e++};return RED.nodes.eachNode(t),RED.nodes.eachConfig(t),e}function et(e,t,i,n){return new(i||(i=Promise))((function(a,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function r(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,r)}l((n=n.apply(e,t||[])).next())}))}function tt(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}function it(e,t,i,n,a){if("m"===n)throw new TypeError("Private method is not writable");if("a"===n&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===n?a.call(e,i):a?a.value=i:t.set(e,i),i}let nt,at,ot;"function"==typeof SuppressedError&&SuppressedError;let st=!1;function rt(e,t,i){nt=$(t),ot=e,ot.server||function(){let e;RED.nodes.eachConfig((t=>(t.type!==s.Server||e||(e=t.id),!0))),e&&nt.val(e)}(),at=nt.val(),setTimeout((()=>{nt.on("change",(()=>{at=nt.val(),null==i||i(at)}))}),500)}function lt(e,t){let i=nt.val();(ot.server||i&&"_ADD_"!==i)&&(at=ot.server||i,ut(e,t)),nt.on("change",(()=>{at=nt.val(),at!==i&&(i=at,ut(e,t))}))}function ut(e,t){"_ADD_"!==at&&$.getJSON(`homeassistant/${e}/${at}`).done((e=>{t(e)})).fail((e=>{503===e.status&&!1===st&&(st=!0,RED.notify(ot._("config-server.errors.server_deploy")),setTimeout((()=>st=!1),2e3))}))}function pt(e,t,{params:i={}}){let n=`homeassistant/${t}/${nt.val()}`;$.isEmptyObject(i)||(n+=`?${$.param(i)}`),$.getJSON(n).done((t=>{e(t)}))}function dt(e,t={}){let i=`homeassistant/${e}/${nt.val()}`;return $.isEmptyObject(t)||(i+=`?${$.param(t)}`),new Promise(((e,t)=>{$.getJSON(i).done((t=>e(t))).fail((e=>t(e)))}))}const ct=e=>S(at,e),vt=()=>function(e){var t;return null!==(t=b[e])&&void 0!==t?t:[]}(at),yt=()=>Object.values(function(e){var t;return null!==(t=g[e])&&void 0!==t?t:{}}(at)),gt=()=>function(e){var t;return null!==(t=h[e])&&void 0!==t?t:[]}(at),ht=()=>function(e){var t;return null!==(t=f[e])&&void 0!==t?t:[]}(at),ft=()=>function(e){var t;return null!==(t=m[e])&&void 0!==t?t:{}}(at),mt=()=>{const e=RED.nodes.node(at);return{areaSelector:null==e?void 0:e.areaSelector,deviceSelector:null==e?void 0:e.deviceSelector,entitySelector:null==e?void 0:e.entitySelector,status:{separator:null==e?void 0:e.statusSeparator,year:null==e?void 0:e.statusYear,month:null==e?void 0:e.statusMonth,day:null==e?void 0:e.statusDay,hourCycle:null==e?void 0:e.statusHourCycle,timeFormat:null==e?void 0:e.statusTimeFormat}}};var bt,Tt;!function(e){e.Config="config",e.HomeAssistant="home_assistant",e.HomeAssistantDeprecated="home_assistant_deprecated",e.HomeAssistantEntities="home_assistant_entities"}(bt||(bt={})),function(e){e.Action="#46B1EF",e.Alpha="#E78BB9",e.Api="#7CDFFD",e.Beta="#77DD77",e.Data="#5BCBF7",e.Deprecated="#A6BBCF",e.Event="#399CDF",e.HaBlue="#41BDF5"}(Tt||(Tt={}));var _t,$t,St={alphaWarning:e=>$.parseHTML(`\n <div class="ui-state-error ha-alpha-box">\n Alpha version: At this point anything could change or not work.\n <br />\n Found an issue? Post it in\n <a\n href="https://github.com/zachowj/node-red-contrib-home-assistant-websocket/issues"\n target="_blank"\n rel="noreferrer"\n >\n issues\n </a>\n . Have questions or comments? Post them\n <a\n href="https://github.com/zachowj/node-red-contrib-home-assistant-websocket/discussions/${e}"\n target="_blank"\n rel="noreferrer"\n >\n here\n </a>\n .\n </div>\n `),betaWarning:e=>$.parseHTML(`\n <div class="ui-state-error ha-beta-box">\n Beta version: Config should be stable and hopefully not too many bugs.\n <br />\n Found an issue? Post it in\n <a\n href="https://github.com/zachowj/node-red-contrib-home-assistant-websocket/issues"\n target="_blank"\n rel="noreferrer"\n >\n issues\n </a>\n . Have questions or comments? Post them\n <a\n href="https://github.com/zachowj/node-red-contrib-home-assistant-websocket/discussions/${e}"\n target="_blank"\n rel="noreferrer"\n >\n here\n </a>\n .\n </div>\n `),labelStyle:function(){const e=[];return Ze(this)||e.push("ha-node-label-legacy"),this.name&&e.push("node_label_italic"),e.join(" ")},setup:e=>{$("#dialog-form, #node-config-dialog-edit-form").addClass("home-assistant"),function(e){Xe(e)&&!Ze(e)&&(Ye(e=Ue(e))||RED.events.on("editor:close",(function t(){RED.events.off("editor:close",t),RED.editor.edit(e)})),RED.nodes.dirty(!0),RED.tray.close(),RED.notify(p("home-assistant.ui.migrations.node_schema_updated")))}(e)}};const Et=null===($t=null===(_t=null===Intl||void 0===Intl?void 0:Intl.DateTimeFormat())||void 0===_t?void 0:_t.resolvedOptions())||void 0===$t?void 0:$t.locale,wt={month:"short",day:"numeric",hour:"numeric",minute:"numeric"};var Dt;!function(e){e.Id="id",e.FriendlyName="friendlyName"}(Dt||(Dt={}));const Ot={category:bt.Config,defaults:{name:{value:"Home Assistant",required:!1},version:{value:RED.settings.get("serverVersion",0)},addon:{value:!1},rejectUnauthorizedCerts:{value:!0},ha_boolean:{value:"y|yes|true|on|home|open"},connectionDelay:{value:!0},cacheJson:{value:!0},heartbeat:{value:!1},heartbeatInterval:{value:30,validate:function(e){return!$("#node-config-input-heartbeat").is(":checked")||RED.validators.number()(e)&&Number(e)>=10}},areaSelector:{value:Dt.FriendlyName},deviceSelector:{value:Dt.FriendlyName},entitySelector:{value:Dt.FriendlyName},statusSeparator:{value:": "},statusYear:{value:"hidden"},statusMonth:{value:"short"},statusDay:{value:"numeric"},statusHourCycle:{value:"default"},statusTimeFormat:{value:"h:m"},enableGlobalContextStore:{value:!1}},credentials:{host:{type:"text"},access_token:{type:"text"}},icon:"font-awesome/fa-home",label:function(){return this.name||"Home Assistant"},oneditprepare:function(){St.setup(this);const e=$("#node-config-input-addon"),t=$("#node-config-input-host");!1===this.rejectUnauthorizedCerts&&$("#accept_unauthorized_certs").prop("checked",!0);function i(){$("#server-info").toggle(!e.prop("checked")),$(".addon").toggle(e.prop("checked"))}["http://hassio/homeassistant","http://supervisor/core"].includes(t.val())&&e.prop("checked",!0),i(),e.on("click",(function(){i()}));try{t.autocomplete("destroy")}catch(e){}const n=$("#discoverInstances");n.on("click",(function(){if($(this).hasClass("disabled"))return;const e=$("i",this).removeClass("fa-search").addClass("spinner");n.addClass("disabled"),t.autocomplete({source:(e,t)=>{$.ajax({dataType:"json",url:"/homeassistant/discover",cache:!1}).done((e=>{t(e)}))},minLength:0,response:()=>{e.addClass("fa-search").removeClass("spinner"),n.removeClass("disabled")},close:()=>t.autocomplete("destroy")}).autocomplete("search","")})),$("#node-config-input-heartbeat").on("change",(function(){$("#heartbeatIntervalRow").toggle(this.checked)})),$("#node-config-input-statusHourCycle").on("change",(function(){const e={hour:"numeric",minute:"numeric"},t=$(this).val();t&&"default"!==t&&(e.hourCycle=t),$("#node-config-input-statusTimeFormat").children().each((function(){const t=$(this);switch(t.val()){case"h:m:s":e.second="numeric";break;case"h:m:s.ms":e.second="numeric",e.fractionalSecondDigits=3}const i=function({date:e=new Date,locale:t=(null!=Et?Et:"en-US"),options:i=wt}){return new Intl.DateTimeFormat(t,i).format(e)}({date:new Date(2022,1,1,3,4,5,6),options:e});t.text(i)}))})).trigger("change")},oneditsave:function(){const e=$("#node-config-input-addon").is(":checked"),t=$("#node-config-input-host").val();if(e)this.addon=!0,this.rejectUnauthorizedCerts=!0;else{const e=documen