UNPKG

zigbee2mqtt-windfront

Version:

[![Version](https://img.shields.io/npm/v/zigbee2mqtt-windfront.svg)](https://npmjs.org/package/zigbee2mqtt-windfront) [![CI](https://github.com/Nerivec/zigbee2mqtt-windfront/actions/workflows/ci.yml/badge.svg)](https://github.com/Nerivec/zigbee2mqtt-windf

2 lines (1 loc) 5.5 kB
import{j as r,b as D,r as F,c as A,C as q,E as T,F as z,G as V,a as b,A as I,d as $,t as k,g as E,N as M,I as R}from"./index-C9teBVht.js";import{u as G,b as B}from"./useColumnCount-Blfbr5hF.js";import{D as L}from"./DeviceCard-BgokW0wu.js";import{R as O}from"./RemoveDeviceModal-BwBAE1DK.js";import{D as W}from"./DashboardFeatureWrapper-CC4xEX29.js";import{u as P,T as U}from"./useTable-DxvhHQuW.js";import"./envs-CSqIi4cL.js";import"./Feature-NdqklTM_.js";import"./DisplayValue-CmowE72l.js";import"./isObject--vsEa_js.js";import"./_createCompounder-JFMc-LTw.js";import"./isArray-atDF8gHr.js";import"./index-Dm1jDR4v.js";import"./LastSeen-DpZtjfR1.js";import"./format-CR8fnhJq.js";import"./Lqi-BUi3mqI9.js";import"./PowerSource-DDICmrah.js";import"./snakeCase-DMy2ZOvg.js";import"./DeviceImage-DGFxocTf.js";import"./index-BdHs_BcQ.js";import"./CheckboxField-ZdCJFDzF.js";import"./DebouncedInput-CB_1_bR4.js";const H=({original:{sourceIdx:a,device:n,deviceState:u,deviceAvailability:p,features:l,lastSeenConfig:y,removeDevice:v}})=>{const{t:h}=D("zigbee"),w=F.useCallback(async c=>{await A(a,`${n.ieee_address}/set`,c)},[a,n.ieee_address]);return r.jsx("div",{className:`mb-3 card card-border bg-base-200 rounded-box shadow-md ${p==="offline"?"border-error/50":"border-base-300"}`,children:r.jsx(L,{features:l,sourceIdx:a,device:n,deviceState:u,onChange:w,featureWrapperClass:W,lastSeenConfig:y,children:r.jsx("div",{className:"join join-horizontal",children:r.jsx(q,{onClick:async()=>await T.show(O,{sourceIdx:a,device:n,removeDevice:v}),className:"btn btn-outline btn-error btn-square btn-sm join-item",title:h(c=>c.remove_device),children:r.jsx(z,{icon:V})})})})})},J=a=>a?.data?r.jsx(H,{...a.data}):null;function he(){const{t:a}=D(["common","zigbee"]),n=b(e=>e.deviceStates),u=b(e=>e.availability),p=b(e=>e.deviceDashboardFeatures),l=b(e=>e.bridgeInfo),y=b(e=>e.devices),v=G(),h=F.useCallback(async(e,t,d,j)=>{await A(e,"bridge/request/device/remove",{id:t,force:d,block:j})},[]),w=F.useMemo(()=>{const e=[];for(let t=0;t<I.length;t++){const d=l[t].config.advanced.last_seen,j=l[t].config.availability.enabled;for(const i of y[t]){if(i.disabled||!i.supported||!i.definition)continue;const g=p[t][i.ieee_address];if(!g||g.length===0)continue;const _=new Set,C=new Set;for(const s of g)if("features"in s&&s.features){for(const m of s.features)m.type&&_.add(m.type),m.name&&C.add(m.name);s.type&&_.add(s.type)}else s.type&&_.add(s.type),s.name&&C.add(s.name);const o=n[t][i.friendly_name]??{};let f;i.power_source==="Battery"&&(f=!1,"battery"in o?o.battery<20&&(f=!0):"battery_state"in o?o.battery_state==="low"&&(f=!0):"battery_low"in o&&(f=!!o.battery_low));let N="disabled";if(!i.disabled){const s=l[t].config.devices[i.ieee_address]?.availability;N=(s!=null?!!s:void 0)??j?u[t][i.friendly_name]?.state??"offline":"disabled"}e.push({sourceIdx:t,device:i,deviceState:o,deviceAvailability:N,batteryLow:f,features:g,featureTypes:Array.from(_),featureNames:Array.from(C),lastSeenConfig:d,removeDevice:h})}}return e},[y,n,p,l,u,h]),c=F.useMemo(()=>[{id:"source",accessorFn:({sourceIdx:e})=>$[e],filterFn:"equals",meta:{filterVariant:"select",showFacetedOccurrences:!0}},{id:"friendly_name",header:a(e=>e.friendly_name),accessorFn:({device:e})=>`${e.friendly_name} ${e.description??""}`,sortingFn:(e,t)=>e.original.device.friendly_name.localeCompare(t.original.device.friendly_name),filterFn:"includesString",meta:{filterVariant:"text",textFaceted:!0}},{id:"ieee_address",header:a(e=>e.ieee_address,{ns:"zigbee"}),accessorFn:({device:e})=>`${e.ieee_address} ${k(e.network_address,4)} ${e.network_address}`,filterFn:"includesString",meta:{filterVariant:"text"}},{id:"type",header:a(e=>e.type,{ns:"zigbee"}),accessorFn:({device:e})=>a(t=>t[e.type],{ns:"zigbee"}),filterFn:"equals",meta:{filterVariant:"select",showFacetedOccurrences:!0}},{id:"state",header:a(e=>e.state),accessorFn:({deviceState:e})=>e.state,filterFn:"equals",meta:{filterVariant:"select",showFacetedOccurrences:!0}},{id:"lqi",header:a(e=>e.lqi,{ns:"zigbee"}),accessorFn:({deviceState:e})=>e.linkquality,filterFn:"inNumberRange",meta:{filterVariant:"range"}},{id:"last_seen",header:a(e=>e.last_seen,{ns:"zigbee"}),accessorFn:({deviceState:e,lastSeenConfig:t})=>{const d=E(e.last_seen,t);return d?Math.round((Date.now()-d)/1e3/60):void 0},enableGlobalFilter:!1,filterFn:"inNumberRange",meta:{filterVariant:"range",tooltip:a(e=>e.last_seen_filter_info)}},{id:"battery_low",header:a(e=>e.battery_low,{ns:"zigbee"}),accessorFn:({batteryLow:e})=>e===void 0?"N/A":e,filterFn:"equals",meta:{filterVariant:"boolean"}},{id:"feature_type",header:a(e=>e.feature_type),accessorFn:({featureTypes:e})=>e,filterFn:"arrIncludes",meta:{filterVariant:"arrSelect"},enableGlobalFilter:!1},{id:"feature_name",header:a(e=>e.feature_name),accessorFn:({featureNames:e})=>e,filterFn:"arrIncludes",meta:{filterVariant:"arrSelect"},enableGlobalFilter:!1}],[a]),x=P({id:"dashboard-devices",columns:c,data:w,sorting:[{id:"friendly_name",desc:!1}]}),{rows:S}=x.table.getRowModel();return r.jsxs(r.Fragment,{children:[r.jsx(M,{children:r.jsx(U,{...x})}),r.jsx("div",{children:r.jsx(B,{useWindowScroll:!0,columnCount:v,data:S,ItemContent:J,className:"gap-3"},`dashboard-${S.length}-${x.globalFilter}`)}),r.jsx("div",{className:"sticky z-9 bottom-0 pb-1 w-full flex flex-row justify-end sm:hidden",children:r.jsx(q,{title:a(e=>e.scroll_to_top),className:"btn btn-primary btn-square",onClick:()=>{window.scrollTo(0,0)},children:r.jsx(z,{icon:R})})})]})}export{he as default};