zwave-js-ui
Version:
Z-Wave Control Panel and MQTT Gateway
2 lines (1 loc) • 7.74 kB
JavaScript
import{_ as k,a as w,I as S,e as c,z as a,w as i,b as h,h as p,c as N,N as g,k as r,O,H as J,V,f as y,q as v,i as l,am as u,o as b,t as D,M as x,aN as C,x as A}from"./index-DwzE-W2i.js";import{V as I}from"./VDataTable-D8DZXD9Y.js";import{V as R}from"./VTextarea-DtC2nuOc.js";import"./sort-C8HQTCiq.js";import"./VTable-Cxuwit5L.js";const j={props:{node:Object,socket:Object},mixins:[S],data(){return{deviceJSON:"",errorDevice:!1,headers_hass:[{title:"Id",value:"id"},{title:"Type",value:"type"},{title:"Object id",value:"object_id"},{title:"Persistent",value:"persistent"},{title:"Discovery",value:"ignoreDiscovery"}],selectedDevice:null}},computed:{...w(A,["gateway"]),hassDevices(){const s=[];if(this.node&&this.node.hassDevices)for(const e in this.node.hassDevices){const n=JSON.parse(JSON.stringify(this.node.hassDevices[e]));n.id=e,s.push(n)}return s}},watch:{selectedDevice(){this.deviceJSON=this.selectedDevice?JSON.stringify(this.selectedDevice,null,2):""}},methods:{async sendAction(s={}){return new Promise(e=>{this.socket.connected?(this.showSnackbar(`API ${s.apiName} called`,"info"),this.socket.emit(C.hass,s,n=>{n.success||this.showSnackbar(`Error while calling ${s.apiName}: ${n.message}`,"error"),e(n)})):(e({success:!1,message:"Socket disconnected"}),this.showSnackbar("Socket disconnected","error"))})},selectDevice(s,{item:e,toggleSelect:n,internalItem:f,index:d}){n(f,d,s),this.selectedDevice=this.selectedDevice===e?null:e},async addDevice(){if(!this.errorDevice){const s=JSON.parse(this.deviceJSON);(await this.sendAction({apiName:"add",device:s,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${s.id} added`,"success")}},async deleteDevice(){const s=this.selectedDevice;s&&await this.app.confirm("Attention","Are you sure you want to delete selected device?","alert")&&(await this.sendAction({apiName:"delete",device:s,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${s.id} deleted`,"success")},async disableDiscovery(){this.node&&await this.app.confirm("Rediscover node","Are you sure you want to disable discovery of all values? In order to make this persistent remember to click on Store")&&(await this.sendAction({apiName:"disableDiscovery",nodeId:this.node.id})).success&&this.showSnackbar(`Discovery disabled for node ${this.node.id}`,"success")},async rediscoverDevice(){const s=this.selectedDevice;s&&await this.app.confirm("Rediscover Device","Are you sure you want to re-discover selected device?")&&(await this.sendAction({apiName:"discover",device:s,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${s.id} re-discovered`,"success")},async rediscoverNode(){this.node&&await this.app.confirm("Rediscover node","Are you sure you want to re-discover all node values?")&&(await this.sendAction({apiName:"rediscoverNode",nodeId:this.node.id})).success&&this.showSnackbar(`Node ${this.node.id} re-discovered`,"success")},async storeDevices(s){(await this.sendAction({apiName:"store",devices:this.node.hassDevices,nodeId:this.node.id,remove:s})).success&&this.showSnackbar(`Devices stored for node ${this.node.id}`,"success")},async updateDeviceJSON(){if(!this.errorDevice){const s=JSON.parse(this.deviceJSON);this.node.hassDevices[this.selectedDevice.id]=s,await this.updateDevice(s)}},async toggleField(s,e){s[e]=!s[e],await this.updateDevice(s)},async updateDevice(s){(await this.sendAction({apiName:"update",device:s,nodeId:this.node.id})).success&&(this.node.hassDevices={...this.node.hassDevices,[s.id]:s},this.selectedDevice&&this.selectedDevice.id===s.id&&(this.deviceJSON=JSON.stringify(s,null,2)),this.showSnackbar(`Device ${s.id} updated`,"success"))},validJSONdevice(){let s=!0;try{JSON.parse(this.deviceJSON)}catch{s=!1}return this.errorDevice=!s,this.deviceJSON===""||s||"JSON test failed"}}},H={key:2,style:{margin:"20px"},class:"text-subtitle-1"};function T(s,e,n,f,d,o){return a(),c(y,null,{default:i(()=>[h(g,null,{default:i(()=>[...e[6]||(e[6]=[r("Home Assistant - Devices",-1)])]),_:1}),s.gateway.manualDiscovery?(a(),c(O,{key:0,"max-width":"1150",text:"",type:"warning"},{default:i(()=>[...e[7]||(e[7]=[J("small",null,"Manual discovery is enabled, you have to select an entity in the table and then press on `REDISCOVER` button on the top of JSON input in order to publish the discovery payload to MQTT",-1)])]),_:1})):p("",!0),o.hassDevices.length>0?(a(),c(V,{key:1},{default:i(()=>[h(y,{cols:"12",md:"6"},{default:i(()=>[v((a(),c(l,{color:"primary",variant:"text",onClick:e[0]||(e[0]=t=>o.storeDevices(!1))},{default:i(()=>[...e[8]||(e[8]=[r(" Store ",-1)])]),_:1})),[[u,"Store all discovered devices in nodes.json in store directory. Prevents re-discovery on startup","bottom"]]),v((a(),c(l,{color:"error",variant:"text",onClick:e[1]||(e[1]=t=>o.storeDevices(!0))},{default:i(()=>[...e[9]||(e[9]=[r(" Remove Store ",-1)])]),_:1})),[[u,"Remove devices from nodes.json in store directory","bottom"]]),v((a(),c(l,{color:"success",variant:"text",onClick:o.rediscoverNode},{default:i(()=>[...e[10]||(e[10]=[r(" Rediscover Node ",-1)])]),_:1},8,["onClick"])),[[u,"Rediscover all node entities. Useful when changing node name/location and need to recalculate topics","bottom"]]),v((a(),c(l,{color:"warning",variant:"text",onClick:o.disableDiscovery},{default:i(()=>[...e[11]||(e[11]=[r(" Disable Discovery ",-1)])]),_:1},8,["onClick"])),[[u,"Set the ignoreDiscovery flag to true on all entities of this node to skip the discovery of them","bottom"]]),h(I,{headers:d.headers_hass,items:o.hassDevices,"show-select":"","select-strategy":"single","item-key":"id","onClick:row":o.selectDevice,class:"elevation-1"},{"item.id":i(({item:t})=>[r(D(t.id),1)]),"item.type":i(({item:t})=>[r(D(t.type),1)]),"item.object_id":i(({item:t})=>[r(D(t.object_id),1)]),"item.persistent":i(({item:t})=>[h(x,{modelValue:t.persistent,"onUpdate:modelValue":[m=>t.persistent=m,m=>o.updateDevice(t)],onClick:e[2]||(e[2]=b(()=>{},["stop"])),"hide-details":"",density:"compact"},null,8,["modelValue","onUpdate:modelValue"])]),"item.ignoreDiscovery":i(({item:t})=>[h(l,{variant:"flat",onClick:b(m=>o.toggleField(t,"ignoreDiscovery"),["stop"]),color:t.ignoreDiscovery?"error":"success",size:"x-small"},{default:i(()=>[r(D(t.ignoreDiscovery?"Disabled":"Enabled"),1)]),_:2},1032,["onClick","color"])]),_:2},1032,["headers","items","onClick:row"])]),_:1}),h(y,{cols:"12",md:"6","pa-1":""},{default:i(()=>[d.selectedDevice?p("",!0):v((a(),c(l,{key:0,color:"primary",disabled:d.errorDevice,variant:"text",onClick:e[3]||(e[3]=t=>o.addDevice())},{default:i(()=>[...e[12]||(e[12]=[r(" Add ",-1)])]),_:1},8,["disabled"])),[[u,"Add this device to discovered entities","bottom"]]),d.selectedDevice?v((a(),c(l,{key:1,color:"primary",disabled:d.errorDevice,variant:"text",onClick:e[4]||(e[4]=t=>o.updateDeviceJSON())},{default:i(()=>[...e[13]||(e[13]=[r(" Update ",-1)])]),_:1},8,["disabled"])),[[u,"Update the in-memory discover template. You have to press Rediscover in order to send this to HA","bottom"]]):p("",!0),d.selectedDevice?v((a(),c(l,{key:2,color:"success",disabled:d.errorDevice,variant:"text",onClick:o.rediscoverDevice},{default:i(()=>[...e[14]||(e[14]=[r(" Rediscover ",-1)])]),_:1},8,["disabled","onClick"])),[[u,"Send this payload to HA","bottom"]]):p("",!0),d.selectedDevice?v((a(),c(l,{key:3,color:"error",disabled:d.errorDevice,variant:"text",onClick:o.deleteDevice},{default:i(()=>[...e[15]||(e[15]=[r(" Delete ",-1)])]),_:1},8,["disabled","onClick"])),[[u,"Delete this entity","bottom"]]):p("",!0),h(R,{label:"Hass Device JSON","auto-grow":"",rules:[o.validJSONdevice],modelValue:d.deviceJSON,"onUpdate:modelValue":e[5]||(e[5]=t=>d.deviceJSON=t)},null,8,["rules","modelValue"])]),_:1})]),_:1})):(a(),N("div",H," No Hass Devices "))]),_:1})}const z=k(j,[["render",T]]);export{z as default};