UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

3 lines (2 loc) 10.6 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ValueId-DdD47gVx.js","./index-DwzE-W2i.js","./index-B2zoqM3Y.css","./colors-DoZdCu1D.js","./ValueId-8KlLQyB0.css"])))=>i.map(i=>d[i]); import{_ as x,a as C,d as M,I as P,s as k,e as N,z as w,w as r,b as s,ar as I,k as d,i as u,l as A,t as p,dB as F,F as f,G as h,V as S,f as y,D as b,B as E,O as K,c as T,h as v,P as R,H as V,at as g,Q as B,C as c,x as D,y as U}from"./index-DwzE-W2i.js";import{V as W}from"./VDataTable-D8DZXD9Y.js";import"./sort-C8HQTCiq.js";import"./VTable-Cxuwit5L.js";const j=/^\d+(\.\d+)+$/,L={name:"TemplateWizard",mixins:[P],components:{ValueId:M(()=>U(()=>import("./ValueId-DdD47gVx.js"),__vite__mapDeps([0,1,2,3,4]),import.meta.url))},props:{template:{type:Object,default:null}},emits:["cancel","saved"],data(){return{step:this.template?2:1,stepLabels:["Select Device","Select Parameters","Name & Settings"],selectedNodeId:null,nodeParams:[],selectedParams:[],templateName:"",templateFirmwareMin:"",templateFirmwareMax:"",templateAutoApply:!1,loadingParams:!1,saving:!1,paramHeaders:[{title:"Parameter",key:"property",width:"100px"},{title:"Label",key:"label"},{title:"Template Value",key:"newValue",sortable:!1}]}},computed:{...C(D,["nodes"]),availableNodes(){return this.nodes.filter(t=>t&&!t.isControllerNode&&t.ready).map(t=>({text:t._name,value:t.id,props:{subtitle:[t.manufacturer,t.productLabel].filter(Boolean).join(" - ")}}))},selectedNodeName(){if(!this.selectedNodeId)return"";const t=this.availableNodes.find(e=>e.value===this.selectedNodeId);return t?t.text:""},canSave(){return this.templateName&&this.selectedParams.length>0&&this.firmwareRule(this.templateFirmwareMin)===!0&&this.firmwareRule(this.templateFirmwareMax)===!0}},watch:{template:{immediate:!0,handler(t){t?this.initEdit(t):this.initCreate()}}},methods:{firmwareRule(t){return t?j.test(t)||"Must be in format X.Y or X.Y.Z (e.g. 1.0)":!0},buildValueIdParam(t,e){return{id:`0-112-0-${t.property}${t.propertyKey!=null?"-"+t.propertyKey:""}`,commandClass:112,property:t.property,propertyKey:t.propertyKey!=null?t.propertyKey:null,endpoint:t.endpoint||0,type:"number",readable:!0,writeable:!0,label:t.label||`Parameter ${t.property}`,description:t.description||"",currentValue:e,min:t.min,max:t.max,default:t.default,list:!!(t.states&&t.states.length>0),allowManualEntry:t.allowManualEntry!=null?t.allowManualEntry:!0,states:t.states||null,newValue:e}},enrichWithConfigDb(t,e){if(!e||!e.length)return;const o=new Map;for(const l of e){const a=`${l.endpoint||0}-${l.property}${l.propertyKey!=null?"-"+l.propertyKey:""}`;o.set(a,l)}for(const l of t){const a=`${l.endpoint||0}-${l.property}${l.propertyKey!=null?"-"+l.propertyKey:""}`,i=o.get(a);i&&(!l.states&&i.states&&i.states.length>0&&(l.states=i.states,l.list=!0),l.min==null&&i.min!=null&&(l.min=i.min),l.max==null&&i.max!=null&&(l.max=i.max),l.default==null&&i.default!=null&&(l.default=i.default),l.allowManualEntry==null&&i.allowManualEntry!=null&&(l.allowManualEntry=i.allowManualEntry))}},initCreate(){this.selectedNodeId=null,this.nodeParams=[],this.selectedParams=[],this.templateName="",this.templateFirmwareMin="",this.templateFirmwareMax="",this.templateAutoApply=!1,this.step=1},async initEdit(t){this.selectedNodeId=null,this.templateName=t.name,this.templateFirmwareMin=t.firmwareRange?.min||"",this.templateFirmwareMax=t.firmwareRange?.max||"",this.templateAutoApply=t.autoApply;let e=[];if(t.deviceId)try{const a=await c.getDeviceConfigurationParams(t.deviceId);a.success&&(e=a.data)}catch{}const o=this.nodes.find(a=>a&&a.ready&&a.deviceId===t.deviceId&&a.values),l=new Map;if(o){const a=`${o.id}-112-`;for(const i in o.values)i.startsWith(a)&&l.set(i.substring(a.length),o.values[i])}this.nodeParams=t.values.map(a=>{const i=`${a.endpoint||0}-${a.property}${a.propertyKey!=null?"-"+a.propertyKey:""}`,m=l.get(i);return this.buildValueIdParam({property:a.property,propertyKey:a.propertyKey,endpoint:a.endpoint,label:a.label||m?.label,description:a.description||m?.description,states:m?.states||null,min:m?.min,max:m?.max,default:m?.default,allowManualEntry:m?.allowManualEntry},a.value)}),this.enrichWithConfigDb(this.nodeParams,e),this.selectedParams=[...this.nodeParams],this.step=2},async onNodeSelected(t){if(!t){this.nodeParams=[],this.selectedParams=[];return}const e=t;this.loadingParams=!0;try{const o=this.nodes.find(a=>a&&a.id===t);if(!o||!o.values){this.showSnackbar("Node not found or has no values","error");return}const l=[];for(const a in o.values){const i=o.values[a];i.commandClass===112&&i.writeable&&l.push(this.buildValueIdParam(i,i.value))}if(o.deviceId)try{const a=await c.getDeviceConfigurationParams(o.deviceId);a.success&&this.enrichWithConfigDb(l,a.data)}catch{}if(this.selectedNodeId!==e)return;l.length===0&&this.showSnackbar("This node has no writeable configuration parameters","warning"),this.nodeParams=l,this.selectedParams=[...l],this.templateName||(this.templateName=o.productLabel||o.productDescription||`Node ${o.id} template`)}finally{this.loadingParams=!1}},async save(){this.saving=!0;try{const t=this.selectedParams.map(l=>({property:l.property,propertyKey:l.propertyKey,endpoint:l.endpoint,value:l.list&&l.states&&l.states.length>0?l.newValue:l.newValue!==""&&l.newValue!=null?Number(l.newValue):0,label:l.label,description:l.description}));let e;const o=this.templateFirmwareMin||this.templateFirmwareMax?{min:this.templateFirmwareMin||void 0,max:this.templateFirmwareMax||void 0}:void 0;this.template?e=await c.updateConfigurationTemplate(this.template.id,{name:this.templateName,firmwareRange:o,autoApply:this.templateAutoApply,values:t}):e=await c.createConfigurationTemplate({nodeId:this.selectedNodeId,name:this.templateName,firmwareRange:o,autoApply:this.templateAutoApply,values:t}),this.showSnackbar(e.message,e.success?"success":"error"),e.success&&this.$emit("saved")}catch(t){this.showSnackbar(t.message,"error")}finally{this.saving=!1}}}};function O(t,e,o,l,a,i){const m=k("ValueId");return w(),N(f,{elevation:"1"},{default:r(()=>[s(I,{class:"d-flex align-center"},{default:r(()=>[s(u,{icon:"",variant:"text",onClick:e[0]||(e[0]=n=>t.$emit("cancel")),class:"mr-2"},{default:r(()=>[s(A,null,{default:r(()=>[...e[15]||(e[15]=[d("arrow_back",-1)])]),_:1})]),_:1}),d(" "+p(o.template?"Edit Template":"Create Template"),1)]),_:1}),s(F,{modelValue:a.step,"onUpdate:modelValue":e[14]||(e[14]=n=>a.step=n),elevation:"0",items:a.stepLabels,"hide-actions":""},{"item.1":r(()=>[s(f,{flat:""},{default:r(()=>[s(h,null,{default:r(()=>[e[16]||(e[16]=V("p",{class:"text-body-1 mb-4"}," Select a node to create a template from its configuration parameters. ",-1)),s(B,{modelValue:a.selectedNodeId,"onUpdate:modelValue":[e[1]||(e[1]=n=>a.selectedNodeId=n),i.onNodeSelected],items:i.availableNodes,"item-title":"text","item-value":"value",label:"Select a node",variant:"outlined",density:"comfortable",clearable:"",loading:a.loadingParams},null,8,["modelValue","items","loading","onUpdate:modelValue"])]),_:1}),s(g,{class:"justify-end"},{default:r(()=>[s(u,{variant:"text",onClick:e[2]||(e[2]=n=>t.$emit("cancel"))},{default:r(()=>[...e[17]||(e[17]=[d(" Cancel ",-1)])]),_:1}),s(u,{color:"primary",disabled:!a.selectedNodeId||a.loadingParams,onClick:e[3]||(e[3]=n=>a.step=2)},{default:r(()=>[...e[18]||(e[18]=[d(" Next ",-1)])]),_:1},8,["disabled"])]),_:1})]),_:1})]),"item.2":r(()=>[s(f,{flat:""},{default:r(()=>[s(h,null,{default:r(()=>[e[19]||(e[19]=V("p",{class:"text-body-1 mb-4"}," Select which parameters to include and optionally modify their values. ",-1)),s(W,{modelValue:a.selectedParams,"onUpdate:modelValue":e[4]||(e[4]=n=>a.selectedParams=n),headers:a.paramHeaders,items:a.nodeParams,"show-select":"","item-value":"id","return-object":"",density:"compact",class:"elevation-0","items-per-page":"-1"},{"item.property":r(({item:n})=>[d(p(n.property)+p(n.propertyKey!=null?`[${n.propertyKey}]`:""),1)]),"item.newValue":r(({item:n})=>[s(m,{"model-value":n,disable_send:!0,"hide-label":"",compact:""},null,8,["model-value"])]),_:2},1032,["modelValue","headers","items"])]),_:1}),s(g,{class:"justify-end"},{default:r(()=>[s(u,{variant:"text",onClick:e[5]||(e[5]=n=>t.$emit("cancel"))},{default:r(()=>[...e[20]||(e[20]=[d(" Cancel ",-1)])]),_:1}),o.template?v("",!0):(w(),N(u,{key:0,variant:"text",onClick:e[6]||(e[6]=n=>a.step=1)},{default:r(()=>[...e[21]||(e[21]=[d(" Back ",-1)])]),_:1})),s(u,{color:"primary",disabled:a.selectedParams.length===0,onClick:e[7]||(e[7]=n=>a.step=3)},{default:r(()=>[...e[22]||(e[22]=[d(" Next ",-1)])]),_:1},8,["disabled"])]),_:1})]),_:1})]),"item.3":r(()=>[s(f,{flat:""},{default:r(()=>[s(h,null,{default:r(()=>[s(S,null,{default:r(()=>[s(y,{cols:"12",sm:"6"},{default:r(()=>[s(b,{modelValue:a.templateName,"onUpdate:modelValue":e[8]||(e[8]=n=>a.templateName=n),label:"Template name",variant:"outlined",rules:[n=>!!n||"Name is required"]},null,8,["modelValue","rules"])]),_:1}),s(y,{cols:"12",sm:"3"},{default:r(()=>[s(b,{modelValue:a.templateFirmwareMin,"onUpdate:modelValue":e[9]||(e[9]=n=>a.templateFirmwareMin=n),label:"Min firmware",variant:"outlined",placeholder:"e.g. 1.0",hint:"Optional","persistent-hint":"",rules:[i.firmwareRule]},null,8,["modelValue","rules"])]),_:1}),s(y,{cols:"12",sm:"3"},{default:r(()=>[s(b,{modelValue:a.templateFirmwareMax,"onUpdate:modelValue":e[10]||(e[10]=n=>a.templateFirmwareMax=n),label:"Max firmware",variant:"outlined",placeholder:"e.g. 3.0",hint:"Optional","persistent-hint":"",rules:[i.firmwareRule]},null,8,["modelValue","rules"])]),_:1}),s(y,{cols:"12",sm:"6"},{default:r(()=>[s(E,{modelValue:a.templateAutoApply,"onUpdate:modelValue":e[11]||(e[11]=n=>a.templateAutoApply=n),label:"Auto-apply to new matching devices",color:"primary","hide-details":""},null,8,["modelValue"])]),_:1})]),_:1}),s(K,{type:"info",variant:"tonal",class:"mt-4"},{default:r(()=>[d(p(a.selectedParams.length)+" parameter(s) selected ",1),i.selectedNodeName?(w(),T(R,{key:0},[e[23]||(e[23]=d(" from ",-1)),V("strong",null,p(i.selectedNodeName),1)],64)):v("",!0)]),_:1})]),_:1}),s(g,{class:"justify-end"},{default:r(()=>[s(u,{variant:"text",onClick:e[12]||(e[12]=n=>t.$emit("cancel"))},{default:r(()=>[...e[24]||(e[24]=[d(" Cancel ",-1)])]),_:1}),s(u,{variant:"text",onClick:e[13]||(e[13]=n=>a.step=2)},{default:r(()=>[...e[25]||(e[25]=[d(" Back ",-1)])]),_:1}),s(u,{color:"primary",disabled:!i.canSave,loading:a.saving,onClick:i.save},{default:r(()=>[d(p(o.template?"Update":"Create"),1)]),_:1},8,["disabled","loading","onClick"])]),_:1})]),_:1})]),_:2},1032,["modelValue","items"])]),_:1})}const G=x(L,[["render",O]]);export{G as default};