UNPKG

zwave-js-ui

Version:

Z-Wave Control Panel and MQTT Gateway

3 lines (2 loc) 18 kB
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Multipane-nNuqJ60A.js","./index-CtTdmJsx.js","./index-2j-kvxFz.css","./Multipane-Ds04H7aO.css","./MultipaneResizer-BXK8V28d.js","./RichValue-CQi-BNto.js","./RichValue-D2CNQpme.css","./FrameDetails-D81lgMDU.js","./FrameDetails-DfeKn8lA.css"])))=>i.map(i=>d[i]); import{_ as n,m as p,u as l,s as c,z as u,y as h,e as d,a as m,A as g,o as v,B as b,D as f,P as _,E as i,Z as o,F as y,G as C,H as k,J as S,K as w,n as x}from"./index-CtTdmJsx.js";const R={name:"Zniffer",props:{socket:Object},components:{Multipane:()=>n(()=>import("./Multipane-nNuqJ60A.js"),__vite__mapDeps([0,1,2,3]),import.meta.url),MultipaneResizer:()=>n(()=>import("./MultipaneResizer-BXK8V28d.js"),__vite__mapDeps([4,1,2]),import.meta.url),RichValue:()=>n(()=>import("./RichValue-CQi-BNto.js"),__vite__mapDeps([5,1,2,6]),import.meta.url),FrameDetails:()=>n(()=>import("./FrameDetails-D81lgMDU.js"),__vite__mapDeps([7,1,2,8]),import.meta.url)},computed:{...p(l,["zniffer","znifferState"]),buttons(){var s,e;return[{id:"start",icon:"play_arrow",color:"success",tooltip:"Start Zniffer",action:this.startZniffer,disabled:(s=this.znifferState)==null?void 0:s.started},{id:"stop",icon:"stop",color:"error",tooltip:"Stop Zniffer",action:this.stopZniffer,disabled:!((e=this.znifferState)!=null&&e.started)},{id:"clear",icon:"delete",color:"warning",tooltip:"Clear Zniffer",action:this.clearFrames,disabled:!this.frames.length},{id:"save",icon:"save",color:"primary",tooltip:"Save capture",action:this.createCapture,disabled:!this.frames.length}]},framesLimited(){return this.framesFiltered.slice(this.start,this.perPage+this.start)},totalFrames(){return this.framesFiltered.length},startHeight(){return this.start*this.rowHeight},endHeight(){const s=this.start+this.perPage;return this.rowHeight*(this.totalFrames-s+1)}},watch:{topPaneHeight(){this.resizeScrollWrapper()},znifferState(){this.clearZnifferConfiguration()},frequencySuccess(s){s&&setTimeout(()=>{this.frequencySuccess=!1},3e3)},lrChannelConfigSuccess(s){s&&setTimeout(()=>{this.lrChannelConfigSuccess=!1},3e3)},framesQueue(){this.queueTimeout&&clearTimeout(this.queueTimeout),this.queueTimeout=setTimeout(()=>{this.emptyQueue()},50)},search(s){this.searchTimeout&&clearTimeout(this.searchTimeout),this.searchTimeout=setTimeout(()=>{this.filterFrames(s)},300)},frames(){this.filterFrames(this.search),this.scrollBottom()}},mounted(){this.socket.on(c.znifferFrame,this.addFrame),this.onWindowResize=()=>{this.topPaneHeight=window.innerHeight/2},this.socket.on("connect",this.onConnnect),this.socket.connected&&this.onConnnect(),window.addEventListener("resize",this.onWindowResize),this.onWindowResize(),this.clearZnifferConfiguration()},beforeDestroy(){window.removeEventListener("resize",this.onWindowResize),this.roTopPane&&(this.roTopPane.unobserve(this.$refs.topPane),this.roTopPane.disconnect()),this.socket&&(this.socket.off(c.znifferFrame),this.socket.off("connect",this.onConnnect)),this.timeoutScroll&&clearTimeout(this.timeoutScroll),this.searchTimeout&&clearTimeout(this.searchTimeout)},data(){return{znifferRegions:u,znifferLRChannelConfigs:h,isPopup:d(),fab:!1,drawer:!1,frequency:null,frequencySuccess:!1,lrRegions:[],lrChannelConfigAvailable:!1,lrChannelConfig:null,lrChannelConfigSuccess:!1,start:0,offsetTop:125,search:"",searchError:!1,busy:!1,selectedFrame:null,scrollWrapper:null,rowHeight:32,perPage:22,topPaneHeight:500,frames:[],framesFiltered:[],framesQueue:[],headers:[{text:"#",value:"id",width:"10ch",sortable:!1},{text:"Timestamp",value:"timestamp",width:"12ch",sortable:!1,class:"no-wrap"},{text:"Delta [ms]",value:"delta",width:"4ch",sortable:!1},{text:"Protocol Data Rate",value:"protocolDataRate",width:"20ch",sortable:!1},{text:"RSSI",value:"rssi",width:"4ch",sortable:!1},{text:"Ch",value:"channel",width:"4ch",sortable:!1},{text:"Home Id",value:"homeId",width:"8ch",sortable:!1,class:"no-wrap"},{text:"Type",width:"8ch",value:"type",sortable:!1},{text:"Route",value:"sourceNodeId",sortable:!1},{text:"Payload",value:"payload",sortable:!1}],autoScroll:!0}},methods:{...m(l,["showSnackbar"]),getProtocolIcon:g,openInWindow:v,humanFriendlyNumber:b,emptyQueue(){this.framesQueue.length>0&&(this.frames.push(...this.framesQueue),this.framesQueue=[])},onConnnect(){this.getFrames()},addFrame(s){const e=this.framesQueue.length>0?this.framesQueue[this.framesQueue.length-1]:this.frames[this.frames.length-1];s.id=e?e.id+1:1,s.delta=e?s.timestamp-e.timestamp:0,this.framesQueue.push(s)},async clearZnifferConfiguration(){await this.$nextTick(),this.znifferState?(this.znifferRegions=Object.entries(this.znifferState.supportedFrequencies).map(([s,e])=>{const t=parseInt(s,10);return{text:e,value:t,disabled:t===f.Unknown||t===f["Default (EU)"]}}).sort((s,e)=>s.text.localeCompare(e.text)),this.frequency=this.znifferState.frequency,this.lrRegions=this.znifferState.lrRegions,this.znifferLRChannelConfigs=Object.entries(this.znifferState.supportedLRChannelConfigs).map(([s,e])=>({text:e,value:parseInt(s,10)})),this.lrChannelConfig=this.znifferState.lrChannelConfig,this.lrChannelConfigAvailable=this.lrRegions.includes(this.frequency)):(this.znifferRegions=u,this.frequency=null,this.lrRegions=[],this.znifferLRChannelConfigs=h,this.lrChannelConfig=null,this.lrChannelConfigAvailable=!1)},onTopColResize(){this.offsetTop=this.$refs.settingCol.clientHeight+20,this.resizeScrollWrapper()},resizeScrollWrapper(){this.scrollWrapper&&(this.scrollWrapper.style.height=`${this.topPaneHeight-this.offsetTop}px`)},filterFrames(s){if(!s||s.trim()===""){this.framesFiltered=this.frames,this.searchError=!1;return}try{s=s.replace(/([^=])=([^=])/g,"$1==$2");const e=new Function("frame, homeId, ch, src, dest, protocolDataRate, hop, dir, repeaters",`return ${s.replace(/\\/g,"\\\\")}`);this.framesFiltered=this.frames.filter(t=>{var r;return e(t,((r=t.homeId)==null?void 0:r.toString(16))||"",t.channel,t.sourceNodeId,t.destinationNodeId,t.protocolDataRate,t.hop,t.direction,t.repeaters||[])}),this.searchError=!1}catch{this.searchError=!0}},onRowClick(s,{select:e,isSelected:t}){t?(this.selectedFrame=null,this.autoScroll=!0,e(!1)):(this.selectedFrame=s,this.autoScroll=!1,e(!0))},getRowStyle(s){const e={backgroundColor:""};if(this.selectedFrame&&this.selectedFrame.id===s.id)e.backgroundColor="rgba(0, 0, 255, 0.5)";else if(s.corrupted)e.backgroundColor="rgba(255, 0, 0, 0.1)";else if(s.routedAck)e.backgroundColor="rgba(255, 165, 0, 0.1)";else if(s.protocol===_.ZWaveLongRange)switch(s.type){case i.Singlecast:e.backgroundColor="rgba(0, 255, 0, 0.1)";break;case i.Ack:e.backgroundColor="rgba(255, 165, 0, 0.1)";break;case i.BeamStart:e.backgroundColor="rgba(255, 255, 255, 0.1)";break;case i.BeamStop:e.backgroundColor="rgba(0, 0, 0, 0.1)";break;case i.Broadcast:e.backgroundColor="rgba(165, 0, 255, 0.1)";break}else switch(s.type){case o.Singlecast:e.backgroundColor="rgba(0, 255, 0, 0.1)";break;case o.Multicast:e.backgroundColor="rgba(0, 0, 255, 0.1)";break;case o.AckDirect:e.backgroundColor="rgba(255, 165, 0, 0.1)";break;case o.ExplorerNormal:e.backgroundColor="rgba(255, 255, 0, 0.1)";break;case o.ExplorerSearchResult:e.backgroundColor="rgba(255, 0, 255, 0.1)";break;case o.ExplorerInclusionRequest:e.backgroundColor="rgba(0, 255, 255, 0.1)";break;case o.BeamStart:e.backgroundColor="rgba(255, 255, 255, 0.1)";break;case o.BeamStop:e.backgroundColor="rgba(0, 0, 0, 0.1)";break;case o.Broadcast:e.backgroundColor="rgba(165, 0, 255, 0.1)";break}return e},getPayloadTags(s,e=[]){var r;return[...e,(r=s.tags)==null?void 0:r.join(" "),...(s.encapsulated||[]).map(a=>this.getPayloadTags(a,e))].filter(a=>!!a).join(" > ")},bindTopPaneObserver(){const s=e=>{this.topPaneHeight=e[0].contentRect.height,this.perPage=Math.ceil((this.topPaneHeight-this.offsetTop)/this.rowHeight)};this.roTopPane=new ResizeObserver(s),this.roTopPane.observe(this.$refs.topPane)},bindScroll(){var e;if(this.scrollWrapper)return;const s=(e=this.$refs.framesTable)==null?void 0:e.$el;if(s){const t=s.getElementsByClassName("v-data-table__wrapper")[0];t.addEventListener("scroll",this.onScroll.bind(this)),this.scrollWrapper=t}},enableAutoScroll(){this.autoScroll=!0,this.scrollBottom()},scrollBottom(){this.scrollWrapper&&this.autoScroll&&this.scrollWrapper.scrollTo(0,this.scrollWrapper.scrollHeight+this.rowHeight)},async onScroll(s){this.timeoutScroll&&clearTimeout(this.timeoutScroll),this.timeoutScroll=setTimeout(async()=>{const e=this.start,{scrollTop:t}=s.target,r=Math.ceil(t/this.rowHeight);this.start=r+this.perPage>=this.totalFrames&&this.perPage<=this.totalFrames?this.totalFrames-this.perPage:r;const a=e<=this.start?"down":"up";this.autoScroll&&a==="up"&&(this.autoScroll=!1)},50)},getTimestamp(s){const e=new Date(s),t=e.getMilliseconds();return`${e.toTimeString().split(" ")[0]}.${t.toString().padEnd(3,"0")}`},getRoute:y,getType:C,getRssi:k,getProtocolDataRate:S,async sendAction(s={},{hideInfo:e}={}){return new Promise(t=>{this.socket.connected?(e||this.showSnackbar(`API ${s.apiName} called`,"info"),this.socket.emit(w.zniffer,s,r=>{r.success||this.showSnackbar(`Error while calling ${s.apiName}: ${r.message}`,"error"),t(r)})):(t({success:!1,message:"Socket disconnected"}),this.showSnackbar("Socket disconnected","error"))})},async getFrames(){const s=await this.sendAction({apiName:"getFrames"},{hideInfo:!0});s.success&&(this.frames=[],s.result.forEach(this.addFrame))},async setFrequency(){(await this.sendAction({apiName:"setFrequency",frequency:this.frequency},{hideInfo:!0})).success&&(this.frequencySuccess=!0)},async setLRChannelConfig(){(await this.sendAction({apiName:"setLRChannelConfig",channelConfig:this.lrChannelConfig},{hideInfo:!0})).success&&(this.lrChannelConfigSuccess=!0)},async startZniffer(){(await this.sendAction({apiName:"start"})).success&&this.showSnackbar("Zniffer started","success")},async stopZniffer(){(await this.sendAction({apiName:"stop"})).success&&this.showSnackbar("Zniffer stopped","success")},async clearFrames(){(await this.sendAction({apiName:"clear"})).success&&(this.showSnackbar("Zniffer cleared","success"),this.frames=[],this.framesFiltered=[])},async createCapture(){const s=await this.sendAction({apiName:"saveCaptureToFile"});if(s.success){const e=s.result;this.showSnackbar(`Capture "${e.name}" created in store`,"success")}}}};var T=function(){var e=this,t=e._self._c;return t("v-container",{staticClass:"px-3",staticStyle:{"max-width":"unset"}},[t("multipane",{staticClass:"horizontal-panes",attrs:{layout:"horizontal"}},[t("div",{directives:[{name:"intersect",rawName:"v-intersect.once",value:e.bindTopPaneObserver,expression:"bindTopPaneObserver",modifiers:{once:!0}}],ref:"topPane",staticClass:"pane",style:{minHeight:"300px",height:`${e.topPaneHeight}px`}},[e.zniffer.enabled?t("v-row",[t("v-col",{staticStyle:{"max-width":"220px","margin-top":"7px"}},[t("v-btn-toggle",{attrs:{dense:"",multiple:""}},e._l(e.buttons,function(r){return t("v-tooltip",{key:r.label,attrs:{bottom:"",target:`#${r.id}`},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[t("v-btn",e._g({attrs:{id:r.id,color:r.color,disabled:r.disabled},on:{click:r.action}},a),[t("v-icon",[e._v(e._s(r.icon))])],1)]}}],null,!0)},[t("span",[e._v(e._s(r.tooltip))])])}),1)],1),t("v-col",{directives:[{name:"resize",rawName:"v-resize",value:e.onTopColResize,expression:"onTopColResize"}],ref:"settingCol",staticClass:"pa-0 pt-2",attrs:{cols:"6"}},[t("v-text-field",{staticClass:"ma-2",attrs:{clearable:"",flat:"","persistent-hint":"",hint:"Search expression using JS. Click on info button for more info",error:e.searchError,"error-messages":e.searchError?["Invalid search"]:[],outlined:"",dense:"","single-line":"","prepend-inner-icon":"search",label:"Search"},scopedSlots:e._u([{key:"append",fn:function(){return[t("v-menu",{attrs:{"offset-y":""},scopedSlots:e._u([{key:"activator",fn:function({on:r}){return[t("v-icon",e._g({attrs:{color:"grey",size:"20"}},r),[e._v("info")])]}}],null,!1,3839655683)},[t("v-card",[t("v-card-text",[t("p",[e._v(" Write a custom filter function in JS. Function arguments are: frame (the full frame object), homeId, ch, src, dest, protocolDataRate, hop, dir (direction), repeaters. ")]),t("strong",[e._v("Examples:")]),t("ul",[t("li",[t("code",[e._v("frame.corrupted")])]),t("li",[t("code",[e._v("src === 1 && dest === 2")])]),t("li",[t("code",[e._v("protocolDataRate === '100kbps'")])]),t("li",[t("code",[e._v("homeId === '12345678'")])]),t("li",[t("code",[e._v("hop > 1")])]),t("li",[t("code",[e._v("dir === 'inbound'")])]),t("li",[t("code",[e._v("repeaters.length > 0")])])])])],1)],1)]},proxy:!0},{key:"append-outer",fn:function(){return[e.totalFrames?t("v-col",{staticClass:"pa-0 caption grey--text text-center",staticStyle:{"margin-top":"-7px"}},[t("p",{staticClass:"mb-0"},[e._v("Frames")]),t("p",{staticClass:"mb-0"},[e._v(" "+e._s(e.humanFriendlyNumber(e.totalFrames,2))+" ")])]):e._e()]},proxy:!0}],null,!1,1936060987),model:{value:e.search,callback:function(r){e.search=r},expression:"search"}})],1),t("v-col",{attrs:{cols:"12"}},[t("v-data-table",{directives:[{name:"intersect",rawName:"v-intersect.once",value:e.bindScroll,expression:"bindScroll",modifiers:{once:!0}}],ref:"framesTable",attrs:{headers:e.headers,items:e.framesLimited,"item-style":e.getRowStyle,"single-select":"","fixed-header":"",dense:"",height:e.topPaneHeight-e.offsetTop,id:"framesTable","hide-default-footer":"","disable-pagination":"","mobile-breakpoint":-1},on:{"click:row":e.onRowClick},scopedSlots:e._u([{key:"item.timestamp",fn:function({item:r}){return[t("v-tooltip",{attrs:{bottom:""},scopedSlots:e._u([{key:"activator",fn:function({on:a}){return[t("span",e._g({},a),[e._v(e._s(e.getTimestamp(r.timestamp)))])]}}],null,!0)},[t("span",[e._v(e._s(new Date(r.timestamp).toLocaleDateString()))])])]}},{key:"item.channel",fn:function({item:r}){return[e._v(" "+e._s(r.channel)+" ")]}},{key:"item.rssi",fn:function({item:r}){return[e._v(" "+e._s(e.getRssi(r))+" ")]}},{key:"item.protocolDataRate",fn:function({item:r}){return[r.corrupted?t("span"):t("div",{staticClass:"d-flex text-center"},[t("rich-value",{attrs:{value:e.getProtocolIcon(r.protocol)}}),t("span",{staticClass:"ml-1"},[e._v(" "+e._s(e.getProtocolDataRate(r,!1)+(r.speedModified?" 🐌":""))+" ")])],1)]}},{key:"item.type",fn:function({item:r}){return[t("span",[e._v(" "+e._s(e.getType(r))+" ")])]}},{key:"item.sourceNodeId",fn:function({item:r}){return[t("span",{domProps:{innerHTML:e._s(e.getRoute(r))}})]}},{key:"item.homeId",fn:function({item:r}){var a;return[e._v(" "+e._s((a=r.homeId)==null?void 0:a.toString(16))+" ")]}},{key:"item.payload",fn:function({item:r}){return[r.corrupted?t("code",[e._v(" CRC Error ")]):r.parsedPayload?t("span",[e._v(" "+e._s(e.getPayloadTags(r.parsedPayload))+" ")]):r.payload&&!r.corrupted?t("span",[e._v(" "+e._s(r.payload)+" ")]):r.routedAck?t("span",[e._v("ROUTED ACK")]):t("span",[e._v("---")])]}},e.start>0?{key:"body.prepend",fn:function(){return[t("tr",[t("td",{staticClass:"text-center",style:"padding-top:"+e.startHeight+"px",attrs:{colspan:e.headers.length}})])]},proxy:!0}:null,e.start+e.perPage<=e.totalFrames?{key:"body.append",fn:function(){return[t("tr",[t("td",{staticClass:"text-center",style:"padding-top:"+e.endHeight+"px",attrs:{colspan:e.headers.length}})])]},proxy:!0}:null],null,!0)}),e.autoScroll?e._e():t("v-tooltip",{attrs:{left:""},scopedSlots:e._u([{key:"activator",fn:function({on:r}){return[t("v-btn",e._g({staticStyle:{top:"40px"},attrs:{color:"purple",dark:"",small:"",fab:"",hover:"",top:"",absolute:"",right:""},on:{click:function(a){return e.enableAutoScroll()}}},r),[t("v-icon",[e._v("vertical_align_bottom")])],1)]}}],null,!1,352983498)},[t("span",[e._v("Enable autoscroll")])])],1)],1):t("v-row",[t("v-col",{attrs:{cols:"12"}},[t("v-alert",{attrs:{text:"",type:"info"}},[t("span",[e._v("Zniffer is disabled, enable it in settings")])])],1)],1)],1),t("multipane-resizer",{class:e.$vuetify.theme.dark?"dark":""}),t("div",{staticClass:"pane pa-2",staticStyle:{"flex-grow":"1","overflow-y":"scroll","overflow-x":"hidden"},style:{height:`calc(100vh - ${e.topPaneHeight+110}px)`}},[t("frame-details",{staticClass:"my-1",attrs:{value:e.selectedFrame}})],1)],1),t("v-btn",{attrs:{color:"primary",dark:"",fab:"",hover:"",bottom:"",right:"",fixed:""},on:{click:function(r){e.drawer=!e.drawer}}},[e.drawer?t("v-icon",[e._v("close")]):t("v-icon",[e._v("menu")])],1),t("v-navigation-drawer",{staticStyle:{"z-index":"2"},attrs:{absolute:"",right:""},model:{value:e.drawer,callback:function(r){e.drawer=r},expression:"drawer"}},[t("v-card",{staticClass:"fill"},[t("v-card-title",[e._v(" Settings ")]),t("v-card-text",[t("v-row",[e.isPopup?e._e():t("v-col",{attrs:{cols:"12"}},[t("v-btn",{attrs:{text:"",small:"",color:"primary"},on:{click:function(r){return e.openInWindow("Zniffer",800,1500)}}},[e._v(" Open in new"),t("v-icon",[e._v("open_in_new")])],1)],1),t("v-col",{attrs:{cols:"12"}},[t("v-select",{attrs:{label:"Zniffer frequency","hide-details":"",items:e.znifferRegions},on:{change:e.setFrequency},scopedSlots:e._u([{key:"prepend",fn:function(){return[t("v-icon",[e._v("signal_cellular_alt")])]},proxy:!0},{key:"append-outer",fn:function(){return[e.frequencySuccess?t("v-icon",{attrs:{color:"success"}},[e._v("check_circle")]):e._e()]},proxy:!0}]),model:{value:e.frequency,callback:function(r){e.frequency=r},expression:"frequency"}})],1),e.lrChannelConfigAvailable?t("v-col",{attrs:{cols:"12"}},[t("v-select",{attrs:{label:"LR Channel Configuration","hide-details":"",items:e.znifferLRChannelConfigs},on:{change:e.setLRChannelConfig},scopedSlots:e._u([{key:"prepend",fn:function(){return[t("v-icon",[e._v("wifi_channel")])]},proxy:!0},{key:"append-outer",fn:function(){return[e.lrChannelConfigSuccess?t("v-icon",{attrs:{color:"success"}},[e._v("check_circle")]):e._e()]},proxy:!0}],null,!1,3693286932),model:{value:e.lrChannelConfig,callback:function(r){e.lrChannelConfig=r},expression:"lrChannelConfig"}})],1):e._e()],1)],1)],1)],1)],1)},P=[],F=x(R,T,P,!1,null,"e14aaf69");const E=F.exports;export{E as default};