UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

2 lines (1 loc) 6.21 kB
import{_ as v,I as x,m as A,u as C,av as E,d$ as _,e0 as m,du as w,o as g,l as c,w as i,b as n,N as y,ar as k,U as f,O as I,V as G,a0 as S,e as U,f as u,Q as N,k as p,t as h,Z as R,$ as T,q as V,P as q,X as B,at as D,ai as L,h as b,a7 as M}from"./index-B9yS4Bcc.js";const j={mixins:[x],props:{modelValue:Boolean,associations:Array,node:Object},watch:{modelValue(){this.$refs.form&&this.$refs.form.resetValidation(),this.resetGroup(),this.associationError=""},group:{deep:!0,async handler(){var e;const t=await((e=this.$refs.form)==null?void 0:e.validate());t!=null&&t.valid&&this.allowedAssociation()}}},computed:{...A(C,["controllerNode","nodes"]),filteredNodes(){return this.node.protocol===E.ZWaveLongRange?[this.controllerNode]:this.nodes.filter(t=>t.id!==this.node.id&&t.protocol!==E.ZWaveLongRange).sort((t,e)=>t._name.localeCompare(e._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(t=>t.groupId===this.group.group.value&&t.endpoint===this.group.endpoint).length:0},endpointGroups(){let t=[];try{t=this.node.groups;const e=this.group.endpoint;t=t.filter(a=>a.endpoint===e||e===null&&a.endpoint===0&&!a.multiChannel)}catch{}return t},_value:{get(){return this.modelValue},set(t){this.$emit("update:modelValue",t)}}},data(){return{valid:!0,group:{},associationError:"",defaultGroup:{endpoint:null},required:t=>!!t||"This field is required"}},methods:{getAssociationAddress:_,async handleAdd(){(await this.$refs.form.validate()).valid&&this.$emit("add",this.group)},async allowedAssociation(){var o;const t=this.group,e=isNaN(t.target)?(o=t.target)==null?void 0:o.id:parseInt(t.target);if(isNaN(e)){this.associationError="";return}const a=t.group;if(!a){this.associationError="";return}const l={nodeId:e};a.multiChannel&&t.targetEndpoint>=0&&(l.endpoint=t.targetEndpoint);const s=[this.getAssociationAddress({nodeId:this.node.id,endpoint:t.endpoint}),a.value,l],r=await this.app.apiRequest("checkAssociation",s,{showInfo:!1});if(r.success){const d=r.result;d===m.OK?this.associationError="":d===m.Forbidden_SecurityClassMismatch?this.associationError=`Association not allowed: Node ${this.node.id} does not have the same security class as Node ${e}!`:d===m.Forbidden_DestinationSecurityClassNotGranted?this.associationError=`Association not allowed: Node ${this.node.id} was not granted the highest security class of Node ${e}!`:d===m.Forbidden_NoSupportedCCs?this.associationError=`Association not allowed: Node ${this.node.id} sends no commands in this group that Node ${e} supports!`:this.associationError=`Association not allowed: ${w(m,d)}`}},resetGroup(){this.group=Object.assign({},this.defaultGroup)},getEndpointLabel(t,e){if(t&&t.endpoints){const a=t.endpoints.find(l=>l.index===e);if(a)return a.label}return"Endpoint "+e},getEndpointItems(t,e=!1){const a=[];if(e&&a.unshift({title:"No Endpoint",value:null}),t&&t.endpoints)for(const l of t.endpoints)a.push({title:l.label,value:l.index});return a}}},F={class:"text-subtitle-1 pa-0 ma-0"},O={class:"text-subtitle-1 pa-0 ma-0"};function P(t,e,a,l,s,r){return g(),c(M,{modelValue:r._value,"onUpdate:modelValue":e[6]||(e[6]=o=>r._value=o),"max-width":"500px",persistent:""},{default:i(()=>[n(y,null,{default:i(()=>[n(k,null,{default:i(()=>e[7]||(e[7]=[f("span",{class:"text-h5"},"New Association",-1)])),_:1,__:[7]}),n(I,null,{default:i(()=>[n(G,{"grid-list-md":""},{default:i(()=>[n(S,{modelValue:s.valid,"onUpdate:modelValue":e[4]||(e[4]=o=>s.valid=o),ref:"form","validate-on":"lazy"},{default:i(()=>[n(U,null,{default:i(()=>[n(u,{cols:"12"},{default:i(()=>[n(N,{label:"Node Endpoint",hint:"Used to filter available groups",modelValue:s.group.endpoint,"onUpdate:modelValue":e[0]||(e[0]=o=>s.group.endpoint=o),"persistent-hint":"",items:r.endpoints},null,8,["modelValue","items"])]),_:1}),n(u,{cols:"12"},{default:i(()=>[n(N,{label:"Group",hint:"Node/Endpoint Group association to Add/Remove","persistent-hint":"",modelValue:s.group.group,"onUpdate:modelValue":e[1]||(e[1]=o=>s.group.group=o),items:r.endpointGroups,rules:[s.required],"return-object":""},{selection:i(({item:o})=>[p(h(o.raw.title),1)]),item:i(({item:o,props:d})=>[n(R,T(d,{title:o.raw.title,subtitle:o.raw.endpoint>=0?r.getEndpointLabel(a.node,o.raw.endpoint):"No Endpoint"}),null,16,["title","subtitle"])]),_:1},8,["modelValue","items","rules"])]),_:1}),s.group.group?(g(),c(u,{key:0,cols:"12"},{default:i(()=>[f("p",F,[e[8]||(e[8]=p(" Max associations: ")),f("strong",null,h(r.maxNodes),1)]),f("p",O,[e[9]||(e[9]=p(" Actual associations: ")),f("strong",null,h(r.nodesInGroup),1)])]),_:1})):V("",!0),r.nodesInGroup<r.maxNodes?(g(),c(u,{key:1,class:"pa-0"},{default:i(()=>[n(u,{cols:"12"},{default:i(()=>[n(q,{label:"Target Node",modelValue:s.group.target,"onUpdate:modelValue":e[2]||(e[2]=o=>s.group.target=o),items:r.filteredNodes,"return-object":"",rules:[s.required],hint:"Node to add to the association group","persistent-hint":"","item-title":"_name"},null,8,["modelValue","items","rules"])]),_:1}),s.group.group&&s.group.group.multiChannel?(g(),c(u,{key:0,cols:"12"},{default:i(()=>[n(N,{modelValue:s.group.targetEndpoint,"onUpdate:modelValue":e[3]||(e[3]=o=>s.group.targetEndpoint=o),modelModifiers:{number:!0},"persistent-hint":"",label:"Target Endpoint",hint:"Target node endpoint",items:r.targetEndpoints},null,8,["modelValue","items"])]),_:1})):V("",!0),s.associationError?(g(),c(u,{key:1,cols:"12"},{default:i(()=>[n(B,{text:"",density:"compact",type:"error"},{default:i(()=>[p(h(s.associationError),1)]),_:1})]),_:1})):V("",!0)]),_:1})):V("",!0)]),_:1})]),_:1},8,["modelValue"])]),_:1})]),_:1}),n(D,null,{default:i(()=>[n(L),n(b,{color:"blue-darken-1",variant:"text",onClick:e[5]||(e[5]=o=>t.$emit("close"))},{default:i(()=>e[10]||(e[10]=[p("Cancel")])),_:1,__:[10]}),n(b,{color:"blue-darken-1",variant:"text",disabled:r.nodesInGroup>=r.maxNodes||!!s.associationError,onClick:r.handleAdd},{default:i(()=>e[11]||(e[11]=[p("ADD")])),_:1,__:[11]},8,["disabled","onClick"])]),_:1})]),_:1})]),_:1},8,["modelValue"])}const W=v(j,[["render",P]]);export{W as default};