UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

2 lines (1 loc) 8.23 kB
import{I as c,m as r,u as n,a,K as d,n as l}from"./index-CtTdmJsx.js";const v={props:{node:Object,socket:Object},mixins:[c],data(){return{deviceJSON:"",errorDevice:!1,headers_hass:[{text:"Id",value:"id"},{text:"Type",value:"type"},{text:"Object id",value:"object_id"},{text:"Persistent",value:"persistent"},{text:"Discovery",value:"ignoreDiscovery"}],selectedDevice:null}},computed:{...r(n,["gateway"]),hassDevices(){const t=[];if(this.node&&this.node.hassDevices)for(const e in this.node.hassDevices){const s=JSON.parse(JSON.stringify(this.node.hassDevices[e]));s.id=e,t.push(s)}return t}},watch:{selectedDevice(){this.deviceJSON=this.selectedDevice?JSON.stringify(this.selectedDevice,null,2):""}},methods:{...a(n,["showSnackbar"]),async sendAction(t={}){return new Promise(e=>{this.socket.connected?(this.showSnackbar(`API ${t.apiName} called`,"info"),this.socket.emit(d.hass,t,s=>{s.success||this.showSnackbar(`Error while calling ${t.apiName}: ${s.message}`,"error"),e(s)})):(e({success:!1,message:"Socket disconnected"}),this.showSnackbar("Socket disconnected","error"))})},selectDevice(t,e){e.select(!e.isSelected),this.selectedDevice=this.selectedDevice===t?null:t},async addDevice(){if(!this.errorDevice){const t=JSON.parse(this.deviceJSON);(await this.sendAction({apiName:"add",device:t,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${t.id} added`,"success")}},async deleteDevice(){const t=this.selectedDevice;t&&await this.app.confirm("Attention","Are you sure you want to delete selected device?","alert")&&(await this.sendAction({apiName:"delete",device:t,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${t.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 t=this.selectedDevice;t&&await this.app.confirm("Rediscover Device","Are you sure you want to re-discover selected device?")&&(await this.sendAction({apiName:"discover",device:t,nodeId:this.node.id})).success&&this.showSnackbar(`Device ${t.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(t){(await this.sendAction({apiName:"store",devices:this.node.hassDevices,nodeId:this.node.id,remove:t})).success&&this.showSnackbar(`Devices stored for node ${this.node.id}`,"success")},async updateDeviceJSON(){if(!this.errorDevice){const t=JSON.parse(this.deviceJSON);this.$set(this.node.hassDevices,this.selectedDevice.id,t),await this.updateDevice(t)}},async toggleField(t,e){t[e]=!t[e],await this.updateDevice(t)},async updateDevice(t){(await this.sendAction({apiName:"update",device:t,nodeId:this.node.id})).success&&(this.node.hassDevices={...this.node.hassDevices,[t.id]:t},this.selectedDevice&&this.selectedDevice.id===t.id&&(this.deviceJSON=JSON.stringify(t,null,2)),this.showSnackbar(`Device ${t.id} updated`,"success"))},validJSONdevice(){let t=!0;try{JSON.parse(this.deviceJSON)}catch{t=!1}return this.errorDevice=!t,this.deviceJSON===""||t||"JSON test failed"}}};var u=function(){var e=this,s=e._self._c;return s("v-col",[s("v-subheader",[e._v("Home Assistant - Devices")]),e.gateway.manualDiscovery?s("v-alert",{attrs:{"max-width":"1150",text:"",type:"warning"}},[s("small",[e._v("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")])]):e._e(),e.hassDevices.length>0?s("v-row",[s("v-col",{attrs:{cols:"12",md:"6","pa-1":""}},[s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"blue darken-1",text:""},on:{click:function(o){return e.storeDevices(!1)}}},i),[e._v("Store")])]}}],null,!1,254688813)},[s("span",[e._v("Store all discovered devices in nodes.json in store directory. Prevents re-discovery on startup")])]),s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"red darken-1",text:""},on:{click:function(o){return e.storeDevices(!0)}}},i),[e._v("Remove Store")])]}}],null,!1,2263227117)},[s("span",[e._v("Remove devices from nodes.json in store directory")])]),s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"green darken-1",text:""},on:{click:e.rediscoverNode}},i),[e._v("Rediscover Node")])]}}],null,!1,2002762040)},[s("span",[e._v("Rediscover all node entities. Useful when changing node name/location and need to recalculate topics")])]),s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"yellow darken-1",text:""},on:{click:e.disableDiscovery}},i),[e._v("Disable Discovery")])]}}],null,!1,930281063)},[s("span",[e._v("Set the ignoreDiscovery flag to true on all entities of this node to skip the discovery of them")])]),s("v-data-table",{staticClass:"elevation-1",attrs:{headers:e.headers_hass,items:e.hassDevices,"single-select":"","item-key":"id"},on:{"click:row":e.selectDevice},scopedSlots:e._u([{key:"item.id",fn:function({item:i}){return[e._v(" "+e._s(i.id)+" ")]}},{key:"item.type",fn:function({item:i}){return[e._v(" "+e._s(i.type)+" ")]}},{key:"item.object_id",fn:function({item:i}){return[e._v(" "+e._s(i.object_id)+" ")]}},{key:"item.persistent",fn:function({item:i}){return[s("v-checkbox",{attrs:{"hide-details":"",dense:""},on:{click:function(o){o.stopPropagation()},change:function(o){return e.updateDevice(i)}},model:{value:i.persistent,callback:function(o){e.$set(i,"persistent",o)},expression:"item.persistent"}})]}},{key:"item.ignoreDiscovery",fn:function({item:i}){return[s("v-btn",{attrs:{color:i.ignoreDiscovery?"error":"success",rounded:"","x-small":""},on:{click:function(o){return o.stopPropagation(),e.toggleField(i,"ignoreDiscovery")}}},[e._v(" "+e._s(i.ignoreDiscovery?"Disabled":"Enabled")+" ")])]}}],null,!0)})],1),s("v-col",{attrs:{cols:"12",md:"6","pa-1":""}},[e.selectedDevice?e._e():s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"blue darken-1",disabled:e.errorDevice,text:""},on:{click:function(o){return e.addDevice()}}},i),[e._v("Add")])]}}],null,!1,2840958021)},[s("span",[e._v("Add this device to discovered entities")])]),e.selectedDevice?s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"blue darken-1",disabled:e.errorDevice,text:""},on:{click:function(o){return e.updateDeviceJSON()}}},i),[e._v("Update")])]}}],null,!1,1296603869)},[s("span",[e._v("Update the in-memory discover template. You have to press Rediscover in order to send this to HA")])]):e._e(),e.selectedDevice?s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"green darken-1",disabled:e.errorDevice,text:""},on:{click:e.rediscoverDevice}},i),[e._v("Rediscover")])]}}],null,!1,3561712070)},[s("span",[e._v("Send this payload to HA")])]):e._e(),e.selectedDevice?s("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:i}){return[s("v-btn",e._g({attrs:{color:"red darken-1",disabled:e.errorDevice,text:""},on:{click:e.deleteDevice}},i),[e._v("Delete")])]}}],null,!1,3940586574)},[s("span",[e._v("Delete this entity")])]):e._e(),s("v-textarea",{attrs:{label:"Hass Device JSON","auto-grow":"",rules:[e.validJSONdevice]},model:{value:e.deviceJSON,callback:function(i){e.deviceJSON=i},expression:"deviceJSON"}})],1)],1):s("div",{staticClass:"subtitle-1",staticStyle:{margin:"20px"}},[e._v(" No Hass Devices ")])],1)},h=[],p=l(v,u,h,!1,null,null);const D=p.exports;export{D as default};