UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

2 lines (1 loc) 5.83 kB
import{I as u,m as c,u as p,P as d,av as g,aw as i,ar as v,n as h}from"./index-CtTdmJsx.js";const f={mixins:[u],props:{value:Boolean,associations:Array,node:Object},watch:{value(){this.$refs.form&&this.$refs.form.resetValidation(),this.resetGroup(),this.associationError=""},group:{deep:!0,handler(){var o;(o=this.$refs.form)!=null&&o.validate()&&this.allowedAssociation()}}},computed:{...c(p,["controllerNode","nodes"]),filteredNodes(){return this.node.protocol===d.ZWaveLongRange?[this.controllerNode]:this.nodes.filter(o=>o.id!==this.node.id&&o.protocol!==d.ZWaveLongRange).sort((o,t)=>o._name.localeCompare(t._name))},endpoints(){return this.getEndpointItems(this.node)},targetEndpoints(){return this.getEndpointItems(this.group.target,!0)},maxNodes(){return this.group.group?this.group.group.maxNodes:-1},nodesInGroup(){return this.group.group?this.associations.filter(o=>o.groupId===this.group.group.value&&o.endpoint===this.group.endpoint).length:0},endpointGroups(){let o=[];try{o=this.node.groups;const t=this.group.endpoint;o=o.filter(e=>e.endpoint===t||t===null&&e.endpoint===0&&!e.multiChannel)}catch{}return o}},data(){return{valid:!0,group:{},associationError:"",defaultGroup:{endpoint:null},required:o=>!!o||"This field is required"}},methods:{getAssociationAddress:g,async allowedAssociation(){var l;const o=this.group,t=isNaN(o.target)?(l=o.target)==null?void 0:l.id:parseInt(o.target);if(isNaN(t)){this.associationError="";return}const e=o.group;if(!e){this.associationError="";return}const s={nodeId:t};e.multiChannel&&o.targetEndpoint>=0&&(s.endpoint=o.targetEndpoint);const a=[this.getAssociationAddress({nodeId:this.node.id,endpoint:o.endpoint}),e.value,s],r=await this.app.apiRequest("checkAssociation",a,{showInfo:!1});if(r.success){const n=r.result;n===i.OK?this.associationError="":n===i.Forbidden_SecurityClassMismatch?this.associationError=`Association not allowed: Node ${this.node.id} does not have the same security class as Node ${t}!`:n===i.Forbidden_DestinationSecurityClassNotGranted?this.associationError=`Association not allowed: Node ${this.node.id} was not granted the highest security class of Node ${t}!`:n===i.Forbidden_NoSupportedCCs?this.associationError=`Association not allowed: Node ${this.node.id} sends no commands in this group that Node ${t} supports!`:this.associationError=`Association not allowed: ${v(i,n)}`}},resetGroup(){this.group=Object.assign({},this.defaultGroup)},getEndpointLabel(o,t){if(o&&o.endpoints){const e=o.endpoints.find(s=>s.index===t);if(e)return e.label}return"Endpoint "+t},getEndpointItems(o,t=!1){const e=[];if(t&&e.unshift({text:"No Endpoint",value:null}),o&&o.endpoints)for(const s of o.endpoints)e.push({text:s.label,value:s.index});return e}}};var m=function(){var t=this,e=t._self._c;return e("v-dialog",{attrs:{"max-width":"500px",persistent:""},model:{value:t.value,callback:function(s){t.value=s},expression:"value"}},[e("v-card",[e("v-card-title",[e("span",{staticClass:"headline"},[t._v("New Association")])]),e("v-card-text",[e("v-container",{attrs:{"grid-list-md":""}},[e("v-form",{ref:"form",attrs:{"lazy-validation":""},model:{value:t.valid,callback:function(s){t.valid=s},expression:"valid"}},[e("v-row",[e("v-col",{attrs:{cols:"12"}},[e("v-select",{attrs:{label:"Node Endpoint",hint:"Used to filter available groups","persistent-hint":"",items:t.endpoints},model:{value:t.group.endpoint,callback:function(s){t.$set(t.group,"endpoint",s)},expression:"group.endpoint"}})],1),e("v-col",{attrs:{cols:"12"}},[e("v-select",{attrs:{label:"Group",hint:"Node/Endpoint Group association to Add/Remove","persistent-hint":"",items:t.endpointGroups,rules:[t.required],"return-object":""},scopedSlots:t._u([{key:"selection",fn:function({item:s}){return[t._v(" "+t._s(s.text)+" ")]}},{key:"item",fn:function({item:s,attrs:a,on:r}){return[e("v-list-item",t._g(t._b({attrs:{"two-line":""}},"v-list-item",a,!1),r),[e("v-list-item-content",[e("v-list-item-title",[t._v(t._s(`[${s.value}] ${s.text}`))]),e("v-list-item-subtitle",[t._v(t._s(s.endpoint>=0?t.getEndpointLabel(t.node,s.endpoint):"No Endpoint"))])],1)],1)]}}]),model:{value:t.group.group,callback:function(s){t.$set(t.group,"group",s)},expression:"group.group"}})],1),t.group.group?e("v-col",{attrs:{cols:"12"}},[e("p",{staticClass:"text-subtitle-1 pa-0 ma-0"},[t._v(" Max associations: "),e("strong",[t._v(t._s(t.maxNodes))])]),e("p",{staticClass:"text-subtitle-1 pa-0 ma-0"},[t._v(" Actual associations: "),e("strong",[t._v(t._s(t.nodesInGroup))])])]):t._e(),t.nodesInGroup<t.maxNodes?e("v-col",{staticClass:"pa-0"},[e("v-col",{attrs:{cols:"12"}},[e("v-combobox",{attrs:{label:"Target Node",items:t.filteredNodes,"return-object":"",rules:[t.required],hint:"Node to add to the association group","persistent-hint":"","item-text":"_name"},model:{value:t.group.target,callback:function(s){t.$set(t.group,"target",s)},expression:"group.target"}})],1),t.group.group&&t.group.group.multiChannel?e("v-col",{attrs:{cols:"12"}},[e("v-select",{attrs:{"persistent-hint":"",label:"Target Endpoint",hint:"Target node endpoint",items:t.targetEndpoints},model:{value:t.group.targetEndpoint,callback:function(s){t.$set(t.group,"targetEndpoint",t._n(s))},expression:"group.targetEndpoint"}})],1):t._e(),t.associationError?e("v-col",{attrs:{cols:"12"}},[e("v-alert",{attrs:{text:"",dense:"",type:"error"}},[t._v(" "+t._s(t.associationError)+" ")])],1):t._e()],1):t._e()],1)],1)],1)],1),e("v-card-actions",[e("v-spacer"),e("v-btn",{attrs:{color:"blue darken-1",text:""},on:{click:function(s){return t.$emit("close")}}},[t._v("Cancel")]),e("v-btn",{attrs:{color:"blue darken-1",text:"",disabled:t.nodesInGroup>=t.maxNodes||!!t.associationError},on:{click:function(s){t.$refs.form.validate()&&t.$emit("add",t.group)}}},[t._v("ADD")])],1)],1)],1)},_=[],b=h(f,m,_,!1,null,null);const E=b.exports;export{E as default};