zigbee2mqtt-windfront
Version:
[](https://npmjs.org/package/zigbee2mqtt-windfront) [](https://github.com/Nerivec/zigbee2mqtt-windf
2 lines (1 loc) • 21.4 kB
JavaScript
import{r as m,j as o,b6 as v,b as E,C as S,F as se,b7 as Be,au as ve,b8 as Ve,O as Oe}from"./index-Cg_dwqpD.js";import{D as O}from"./DisplayValue-DcXMP9Gf.js";import{r as Ue}from"./isObject--vsEa_js.js";import{r as Ge,a as He,b as ze}from"./_createCompounder-Dcznv9Az.js";import{g as je,a as Le}from"./index-BwjSpuUu.js";const k=m.memo(({feature:e,deviceValue:r})=>o.jsxs("div",{children:[e.property&&o.jsx("span",{className:"font-bold",children:o.jsx(O,{value:r,name:e.name})}),"unit"in e&&o.jsx("span",{className:"text-xs ms-1",children:e.unit})]})),w=m.memo(e=>o.jsxs("div",{className:"alert alert-warning",role:"alert",children:["Unknown access ",o.jsx("pre",{children:e.feature.access})]})),Pe=m.memo(e=>{const{feature:{access:r=v.SET,name:n,property:t,value_off:a,value_on:s},deviceValue:l,onChange:f,minimal:i}=e,{t:c}=E("zigbee"),x=m.useCallback(h=>f(t?{[t]:h}:h),[t,f]),u=m.useCallback(h=>{const d=h.target.checked?s:a;f(t?{[t]:d}:d)},[s,a,t,f]);if(r&v.SET){const h=l!=null,d=!i||i&&!h;return o.jsxs("div",{children:[d&&o.jsx(S,{className:"btn btn-link",item:a,onClick:x,children:o.jsx(O,{value:a,name:n})}),h?o.jsx("input",{className:"toggle",type:"checkbox",checked:l===s,onChange:u}):o.jsx("span",{className:"tooltip","data-tip":c(y=>y.unknown),children:o.jsx(se,{icon:Be})}),d&&o.jsx(S,{className:"btn btn-link",item:s,onClick:x,children:o.jsx(O,{value:s,name:n})})]})}return r&v.STATE?o.jsx(k,{...e}):o.jsx(w,{...e})});function Xe(e,r){if(e==="composite"&&r!==void 0){if(r.length===0)return!0;if(r.length===1){const n=r[0].type;return n!=null&&n!=="composite"&&n!=="list"}}return!1}function A({feature:e,onChange:r,parentFeatures:n,onRead:t,device:a,deviceState:s,featureWrapperClass:l,minimal:f,endpointSpecific:i,steps:c}){const{type:x,property:u}=e,[h,d]=m.useState({}),{t:y}=E("common"),C=m.useMemo(()=>({...s,...h}),[s,h]),j="features"in e&&e.features||[],N=Xe(x,n);m.useEffect(()=>{d({})},[a.ieee_address]);const g=m.useCallback(b=>{d(G=>({...G,...b})),N||r(x==="composite"&&u?{[u]:{...h,...b}}:b)},[h,x,u,N,r]),p=m.useCallback(()=>{const b={...s,...h};r(u?{[u]:b}:b)},[u,r,h,s]),_=m.useCallback(b=>{t?.(x==="composite"&&u?{[u]:b}:b)},[t,x,u]);return o.jsxs(o.Fragment,{children:[j.map(b=>o.jsx(Me,{feature:b,parentFeatures:n??[],device:a,deviceState:C,onChange:g,onRead:_,featureWrapperClass:l,minimal:f,endpointSpecific:i,steps:c?.[b.name]},je(b))),N&&o.jsx("div",{className:"self-end float-right",children:o.jsx(S,{className:`btn btn-primary ${f?"btn-sm":""}`,onClick:p,children:y(b=>b.apply)})})]})}function De(e){return o.jsx(A,{...e})}var H,oe;function Ke(){if(oe)return H;oe=1;function e(r,n,t){return r===r&&(t!==void 0&&(r=r<=t?r:t),n!==void 0&&(r=r>=n?r:n)),r}return H=e,H}var z,ae;function Je(){if(ae)return z;ae=1;var e=/\s/;function r(n){for(var t=n.length;t--&&e.test(n.charAt(t)););return t}return z=r,z}var L,ce;function Ye(){if(ce)return L;ce=1;var e=Je(),r=/^\s+/;function n(t){return t&&t.slice(0,e(t)+1).replace(r,"")}return L=n,L}var P,le;function Ze(){if(le)return P;le=1;var e=Ye(),r=Ue(),n=Ge(),t=NaN,a=/^[-+]0x[0-9a-f]+$/i,s=/^0b[01]+$/i,l=/^0o[0-7]+$/i,f=parseInt;function i(c){if(typeof c=="number")return c;if(n(c))return t;if(r(c)){var x=typeof c.valueOf=="function"?c.valueOf():c;c=r(x)?x+"":x}if(typeof c!="string")return c===0?c:+c;c=e(c);var u=s.test(c);return u||l.test(c)?f(c.slice(2),u?2:8):a.test(c)?t:+c}return P=i,P}var X,ie;function Qe(){if(ie)return X;ie=1;var e=Ke(),r=Ze();function n(t,a,s){return s===void 0&&(s=a,a=void 0),s!==void 0&&(s=r(s),s=s===s?s:0),a!==void 0&&(a=r(a),a=a===a?a:0),e(r(t),a,s)}return X=n,X}var We=Qe();const T=ve(We),en=[.412453,.35758,.180423,.212671,.71516,.072169,.019334,.119193,.950227],nn=[3.2404813432005266,-1.5371515162713183,-.49853632616888777,-.9692549499965684,1.8759900014898907,.041555926558292815,.05564663913517715,-.20404133836651123,1.0573110696453443],Se=.42,Te=.0031308,Ne=12.92,U=.055,B=e=>e<=Te?Ne*e:(1+U)*e**Se-U,rn=1/Se,tn=B(Te),sn=1/Ne,D=e=>e<=tn?e*sn:((e+U)/(1+U))**rn,Ae=(e,r)=>{const n=[0,0,0];for(let t=0;t<3;t++){n[t]=0;for(let a=0;a<3;a++)n[t]+=r[t*3+a]*e[a]}return n},ue=(e,r,n)=>{const t=[D(e),D(r),D(n)];return Ae(t,en)},on=(e,r,n)=>{const t=Ae([e,r,n],nn);return[B(t[0]),B(t[1]),B(t[2])]},Re=(e,r,n)=>{const t=1-e-r;return on(n/r*e,n,n/r*t)},Ee=(e,r,n=10)=>{let t=1;for(let a=0;a<n;a++){const s=Math.max(...Re(e,r,t));t=t/s}return t},I=(e,r,n)=>{if(e/=255,r/=255,n/=255,e<1e-12&&r<1e-12&&n<1e-12){const[f,i,c]=ue(1,1,1),x=f+i+c;return[f/x,i/x,0]}const[t,a,s]=ue(e,r,n),l=t+a+s;return[t/l,a/l,a]},an=(e,r,n)=>{n===void 0&&(n=Ee(e,r));const[t,a,s]=Re(e,r,n);return[T(t*255,0,255),T(a*255,0,255),T(s*255,0,255)]},q=(e,r,n)=>{e/=255,r/=255,n/=255;const t=Math.max(e,r,n),a=t-Math.min(e,r,n),s=a?(t===e?(r-n)/a+(r<n?6:0):t===r?2+(n-e)/a:4+(e-r)/a)*60:0,l=t?a/t*100:0,f=t*100;return[T(s,0,360),T(l,0,100),T(f,0,100)]},cn=(e,r,n)=>{r/=100,n/=100;const t=~~(e/60),a=e/60-t,s=n*(1-r),l=n*(1-r*a),f=n*(1-r*(1-a)),i=t%6,c=[n,l,s,s,f,n][i]*255,x=[f,n,n,l,s,s][i]*255,u=[s,s,f,n,n,l][i]*255;return[T(c,0,255),T(x,0,255),T(u,0,255)]},F=(e,r,n)=>{const[t,a,s]=[e,r,n].map(l=>Math.round(l).toString(16).padStart(2,"0"));return`#${t}${a}${s}`},ln=e=>(e=e.slice(1),Array.from({length:3}).map((r,n)=>Number.parseInt(e.slice(n*2,n*2+2),16))),R=(e,r)=>{switch(r){case"color_xy":{const{x:n=.313,y:t=.329,Y:a=Ee(n,t===0?.329:t)}=e,s=t===0?[255,255,255]:an(n,t,a);return{color_rgb:s,color_hs:q(...s),color_xy:[n,t,a],hex:F(...s)}}case"color_hs":{const{hue:n=0,saturation:t=0}=e,a=100,s=cn(n,t,a);return{color_rgb:s,color_hs:[n,t,a],color_xy:I(...s),hex:F(...s)}}case"color_rgb":{const{r:n=255,g:t=255,b:a=255}=e;return{color_rgb:[n,t,a],color_hs:q(n,t,a),color_xy:I(n,t,a),hex:F(n,t,a)}}case"hex":{const n=e.hex,t=ln(n);return{color_rgb:t,color_hs:q(...t),color_xy:I(...t),hex:n}}default:{const n=[255,255,255];return{color_rgb:n,color_hs:q(...n),color_xy:I(...n),hex:F(...n)}}}},me=(e,r)=>{switch(r){case"color_xy":return{x:e.color_xy[0],y:e.color_xy[1]};case"color_hs":return{hue:e.color_hs[0],saturation:e.color_hs[1]};case"color_rgb":return{r:e.color_rgb[0],g:e.color_rgb[1],b:e.color_rgb[2]};case"hex":return{hex:e.hex}}},ke=e=>`${e[0].toFixed(3)}, ${e[1].toFixed(3)}, ${e[2].toFixed(3)}`,V=e=>`${e[0].toFixed(2)}°, ${e[1].toFixed(2)}%, ${e[2].toFixed(2)}%`,we=e=>`${e[0].toFixed(0)}, ${e[1].toFixed(0)}, ${e[2].toFixed(0)}`,Ie=e=>e,fe=e=>({color_xy:ke(e.color_xy),color_hs:V(e.color_hs),color_rgb:we(e.color_rgb),hex:Ie(e.hex)}),un=e=>{const r=e.match(/\d+(\.\d+)?/gu)??[];return Array.from({length:3}).map((n,t)=>+(r[t]??0))},mn=e=>{const r=e.match(/\d+(\.\d+)?/gu)??[];return Array.from({length:3}).map((n,t)=>T(+(r[t]??0),0,t?100:360))},fn=e=>{const r=e.match(/\d+(\.\d+)?/gu)??[];return Array.from({length:3}).map((n,t)=>T(+(r[t]??0),0,255))},K=(e,r)=>{switch(r){case"color_xy":{const n=un(e);return R({x:n[0],y:n[1]},"color_xy")}case"color_hs":{const n=mn(e);return R({hue:n[0],saturation:n[1]},"color_hs")}case"color_rgb":{const n=fn(e);return R({r:n[0],g:n[1],b:n[2]},"color_rgb")}case"hex":return R({hex:e},"hex")}},xn="linear-gradient(to right, white, transparent)",hn="linear-gradient(to right, rgb(255, 0, 0), rgb(255, 255, 0), rgb(0, 255, 0), rgb(0, 255, 255), rgb(0, 0, 255), rgb(255, 0, 255), rgb(255, 0, 0))",$=m.memo(({label:e,...r})=>o.jsxs("label",{className:"input",children:[e,o.jsx("input",{type:"text",className:"grow",...r})]})),qe=m.memo(e=>{const{onChange:r,value:n={},format:t,minimal:a}=e,[s,l]=m.useState(R(n,t)),[f,i]=m.useState(fe(s)),[c,x]=m.useState({color_rgb:!1,color_hs:!1,color_xy:!1,hex:!1});m.useEffect(()=>{const g=R(n,t);l(g),i(fe(g))},[n,t]),m.useEffect(()=>{if(!c.color_xy){const g=ke(s.color_xy);i(p=>({...p,color_xy:g}))}},[c.color_xy,s.color_xy]),m.useEffect(()=>{if(!c.color_hs){const g=V(s.color_hs);i(p=>({...p,color_hs:g}))}},[c.color_hs,s.color_hs]),m.useEffect(()=>{if(!c.color_rgb){const g=we(s.color_rgb);i(p=>({...p,color_rgb:g}))}},[c.color_rgb,s.color_rgb]),m.useEffect(()=>{if(!c.hex){const g=Ie(s.hex);i(p=>({...p,hex:g}))}},[c.hex,s.hex]);const u=m.useCallback(g=>{if(g.target.value){const p=Array.from(s.color_hs);p[1]=g.target.valueAsNumber;const _=V(p);i(b=>({...b,color_hs:_})),l(K(_,"color_hs"))}},[s.color_hs]),h=m.useCallback(g=>{if(g.target.value){const p=Array.from(s.color_hs),_=p[1];p[1]=_===0?100:_,p[0]=g.target.valueAsNumber;const b=V(p);i(G=>({...G,color_hs:b})),l(K(b,"color_hs"))}},[s.color_hs]),d=m.useCallback(g=>{const{value:p,name:_}=g.target;i(b=>({...b,[_]:p})),l(K(p,_))},[]),y=m.useCallback(g=>{x(p=>({...p,[g.target.name]:!0}))},[]),C=m.useCallback(g=>{x(p=>({...p,[g.target.name]:!1})),r(me(s,t))},[s,t,r]),j=m.useCallback(()=>{r(me(s,t))},[s,t,r]),N=m.useMemo(()=>`hsl(${s.color_hs[0]}, 100%, 50%)`,[s.color_hs[0]]);return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex flex-row flex-wrap gap-3 items-center",children:o.jsx("div",{className:`w-full${a?" max-w-xs":""}`,children:o.jsx("input",{type:"range",min:0,max:100,value:s.color_hs[1],className:`range [--range-bg:transparent] [--range-fill:0] w-full${a?" range-xs ":""}`,style:{backgroundImage:xn,backgroundColor:N},onChange:u,onTouchEnd:j,onMouseUp:j,onKeyUp:j})})}),o.jsx("div",{className:"flex flex-row flex-wrap gap-3 items-center",children:o.jsx("div",{className:`w-full${a?" max-w-xs":""}`,children:o.jsx("input",{type:"range",min:0,max:360,value:s.color_hs[0],className:`range [--range-bg:transparent] [--range-fill:0] w-full${a?" range-xs ":""}`,style:{backgroundImage:hn},onChange:h,onTouchEnd:j,onMouseUp:j,onKeyUp:j})})}),!a&&o.jsxs("div",{className:"flex flex-row flex-wrap gap-2 justify-around",children:[o.jsx($,{label:"hex",name:"hex",value:f.hex,onChange:d,onFocus:y,onBlur:C}),o.jsx($,{label:"rgb",name:"color_rgb",value:f.color_rgb,onChange:d,onFocus:y,onBlur:C}),o.jsx($,{label:"hsv",name:"color_hs",value:f.color_hs,onChange:d,onFocus:y,onBlur:C}),o.jsx($,{label:"xyY",name:"color_xy",value:f.color_xy,onChange:d,onFocus:y,onBlur:C})]})]})}),dn=m.memo(e=>{const{deviceValue:r,feature:{name:n,features:t,property:a},onChange:s,minimal:l}=e,f=m.useMemo(()=>{const c={},x=r!=null&&typeof r=="object"?r:{};for(const u of t){const h=Number.parseFloat(x[u.name]);c[u.name]=Number.isNaN(h)?0:h}return c},[r,t]),i=m.useCallback(c=>s({[a??"color"]:c}),[a,s]);return o.jsx(qe,{onChange:i,value:f,format:n,minimal:l})}),gn={position:[0,25,50,75,100].map(e=>({value:e,name:`${e}`})),tilt:[0,25,50,75,100].map(e=>({value:e,name:`${e}`}))};function pn(e){return o.jsx(A,{...e,steps:gn})}function M(e){return typeof e!="object"}const Fe=m.memo(e=>{const{onChange:r,values:n,value:t,minimal:a}=e,{t:s}=E("common"),l=M(t),f=m.useCallback(i=>{const c=n.find(x=>M(x)?x===i.target.value:x.value===Number.parseInt(i.target.value,10));r(c)},[n,r]);return a?o.jsxs("select",{className:"select",onChange:f,value:(l?t:t?.value)??"",children:[o.jsx("option",{value:"",disabled:!0,children:s(i=>i.select_value)}),n.map(i=>{const c=M(i);return o.jsx("option",{value:c?i:i.value,children:c?i:i.name},c?i:i.name)})]}):o.jsx("div",{className:"flex flex-row flex-wrap gap-1",children:n.map(i=>{const c=M(i),x=c?i===t:i.value===(l?t:t?.value);return o.jsx(S,{className:`btn btn-soft btn-sm join-item${x?" btn-active":""}`,onClick:u=>r(u),item:c?i:i.value,title:c?`${i}`:i.description,children:c?o.jsx(O,{value:i,name:""}):i.name},c?i:i.name)})})}),bn=6,yn=m.memo(e=>{const{onChange:r,feature:{access:n=v.SET,values:t,property:a},deviceValue:s,minimal:l}=e;return n&v.SET?o.jsx(Fe,{onChange:f=>r(a?{[a]:f}:f),values:t,value:s!=null&&(typeof s=="string"||typeof s=="number"||typeof s=="object")?s:"",minimal:l||t.length>bn}):n&v.STATE?o.jsx(k,{...e}):o.jsx(w,{...e})});function _n(e){return o.jsx(A,{...e})}const Cn=m.memo(e=>{const{minimal:r,onChange:n,feature:{length_min:t,length_max:a,property:s},deviceValue:l}=e,{t:f}=E("common"),[i,c]=m.useState(t>0?Array(t).fill("#ffffff"):[]),[x,u]=m.useState(!1),[h,d]=m.useState(!1);m.useEffect(()=>{l&&Array.isArray(l)&&l.length>0&&c(l)},[l]),m.useEffect(()=>{u(i.length<a),d(i.length>t)},[i,t,a]);const y=m.useCallback((g,p)=>{c(_=>{const b=Array.from(_);return b[g]=p,b})},[]),C=m.useCallback(()=>{c(g=>[...g,"#ffffff"])},[]),j=m.useCallback(g=>{c(p=>{const _=Array.from(p);return _.splice(g,1),_})},[]),N=m.useCallback(()=>n({[s??"gradient"]:i}),[i,s,n]);return o.jsxs("div",{className:"flex flex-col gap-2",children:[i.map((g,p)=>o.jsxs("div",{className:"flex flex-row flex-wrap gap-2 items-center",children:[o.jsx(qe,{onChange:_=>{y(p,_.hex)},value:{hex:g},format:"hex",minimal:r}),h&&o.jsx(S,{className:"btn btn-sm btn-error",onClick:()=>j(p),children:"-"})]},`${g}-${p}`)),x&&o.jsx("div",{className:"flex flex-row flex-wrap gap-2",children:o.jsx(S,{className:"btn btn-sm btn-success",onClick:C,children:"+"})}),o.jsx("div",{children:o.jsx(S,{className:`btn btn-primary ${r?"btn-sm":""}`,onClick:N,children:f(g=>g.apply)})})]})}),vn={brightness:[0,25,50,75,100].map(e=>({value:Ve(e,[0,100],[0,255]),name:`${e}%`})),color_temp:[1e3,2e3,3e3,4e3,5e3,6500].map(e=>({value:1e6/e,name:`${e}K`}))};function jn(e){return o.jsx(A,{...e,steps:vn})}var J,xe;function Sn(){if(xe)return J;xe=1;function e(r,n,t){var a=-1,s=r.length;n<0&&(n=-n>s?0:s+n),t=t>s?s:t,t<0&&(t+=s),s=n>t?0:t-n>>>0,n>>>=0;for(var l=Array(s);++a<s;)l[a]=r[a+n];return l}return J=e,J}var Y,he;function Tn(){if(he)return Y;he=1;var e=Sn();function r(n,t,a){var s=n.length;return a=a===void 0?s:a,!t&&a>=s?n:e(n,t,a)}return Y=r,Y}var Z,de;function $e(){if(de)return Z;de=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",t="\\u20d0-\\u20ff",a=r+n+t,s="\\ufe0e\\ufe0f",l="\\u200d",f=RegExp("["+l+e+a+s+"]");function i(c){return f.test(c)}return Z=i,Z}var Q,ge;function Nn(){if(ge)return Q;ge=1;function e(r){return r.split("")}return Q=e,Q}var W,pe;function An(){if(pe)return W;pe=1;var e="\\ud800-\\udfff",r="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",t="\\u20d0-\\u20ff",a=r+n+t,s="\\ufe0e\\ufe0f",l="["+e+"]",f="["+a+"]",i="\\ud83c[\\udffb-\\udfff]",c="(?:"+f+"|"+i+")",x="[^"+e+"]",u="(?:\\ud83c[\\udde6-\\uddff]){2}",h="[\\ud800-\\udbff][\\udc00-\\udfff]",d="\\u200d",y=c+"?",C="["+s+"]?",j="(?:"+d+"(?:"+[x,u,h].join("|")+")"+C+y+")*",N=C+y+j,g="(?:"+[x+f+"?",f,u,h,l].join("|")+")",p=RegExp(i+"(?="+i+")|"+g+N,"g");function _(b){return b.match(p)||[]}return W=_,W}var ee,be;function Rn(){if(be)return ee;be=1;var e=Nn(),r=$e(),n=An();function t(a){return r(a)?n(a):e(a)}return ee=t,ee}var ne,ye;function En(){if(ye)return ne;ye=1;var e=Tn(),r=$e(),n=Rn(),t=He();function a(s){return function(l){l=t(l);var f=r(l)?n(l):void 0,i=f?f[0]:l.charAt(0),c=f?e(f,1).join(""):l.slice(1);return i[s]()+c}}return ne=a,ne}var re,_e;function kn(){if(_e)return re;_e=1;var e=En(),r=e("toUpperCase");return re=r,re}var te,Ce;function wn(){if(Ce)return te;Ce=1;var e=ze(),r=kn(),n=e(function(t,a,s){return t+(s?" ":"")+r(a)});return te=n,te}var In=wn();const qn=ve(In);function Fn(e){return e.type==="composite"&&(e.name==="color_xy"||e.name==="color_hs")}function $n({children:e,feature:r,deviceValue:n,onRead:t,endpointSpecific:a,parentFeatures:s}){const{t:l}=E("zigbee"),f=r.unit,[i,c]=Le(r.name,n,f),x=t!==void 0&&(!!(r.property&&r.access&v.GET)||Fn(r)),u=s?.[s.length-1],h=r.name==="state"?r.property:r.name;let d=r.label||qn(h);u?.label&&r.name==="state"&&u.type!=="light"&&u.type!=="switch"&&(d=`${u.label} ${r.label.charAt(0).toLowerCase()}${r.label.slice(1)}`);const y=m.useCallback(C=>{C.property&&t?.({[C.property]:""})},[t]);return o.jsxs("div",{className:"list-row p-3",children:[o.jsx("div",{children:o.jsx(se,{icon:i,className:c,size:"2xl"})}),o.jsxs("div",{children:[o.jsxs("div",{title:h,children:[d,!a&&r.endpoint?` (${l(C=>C.endpoint)}: ${r.endpoint})`:""]}),o.jsx("div",{className:"text-xs font-semibold opacity-60",children:r.description})]}),o.jsx("div",{className:"list-col-wrap flex flex-col gap-2",children:e}),x&&o.jsx(S,{item:r,onClick:y,className:"btn btn-xs btn-square btn-primary",children:o.jsx(se,{icon:Oe})})]})}const Mn=m.memo(e=>{const{onChange:r,value:n,feature:t,parentFeatures:a}=e,[s,l]=m.useState(n);m.useEffect(()=>{l(n)},[n]);const f=m.useCallback((x,u)=>{const h=Array.from(s);typeof x=="object"&&x!=null&&(x={...s[u],...x}),h[u]=x??"",l(h),r(h)},[s,r]),i=m.useCallback(x=>{const u=Array.from(s);u.splice(x,1),l(u),r(u)},[s,r]),c=m.useCallback(()=>l(x=>[...x,t.type==="composite"?{}:""]),[t.type]);return s.length===0?o.jsx("div",{className:"flex flex-row flex-wrap gap-2",children:o.jsx(S,{className:"btn btn-success col-1",onClick:c,children:"+"})}):s.map((x,u)=>o.jsxs("div",{className:"flex flex-row flex-wrap gap-2",children:[o.jsx(Me,{feature:t,device:{},deviceState:x,onChange:h=>f(h,u),featureWrapperClass:$n,parentFeatures:a}),o.jsxs("div",{className:"flex flex-row flex-wrap gap-1",children:[o.jsx(S,{item:u,className:"btn btn-sm btn-error btn-square join-item",onClick:i,children:"-"}),s.length-1===u&&o.jsx(S,{className:"btn btn-sm btn-success btn-square join-item",onClick:c,children:"+"})]})]},u))});function Bn(e){if(e!==void 0){if(e.length===0)return!0;if(e.length===1){const r=e[0].type;return r!=null&&r!=="composite"&&r!=="list"}}return!1}const Vn=m.memo(e=>{const{t:r}=E("common"),{feature:n,minimal:t,parentFeatures:a,onChange:s,deviceValue:l}=e,[f,i]=m.useState([]),c=Bn(a);m.useEffect(()=>{l?Array.isArray(l)?i(l):n.property&&typeof l=="object"?i(l[n.property]??[]):i([]):i([])},[n.property,l]);const x=m.useCallback(y=>{i(y),c||s(n.property?{[n.property]:y}:y)},[n.property,s,c]),u=m.useCallback(()=>{s(n.property?{[n.property]:f}:f)},[n.property,s,f]),{access:h=v.SET,item_type:d}=n;return h&v.SET?o.jsxs(o.Fragment,{children:[o.jsx(Mn,{feature:d,parentFeatures:[...a,n],onChange:x,value:f}),c&&o.jsx("div",{children:o.jsx(S,{className:`btn btn-primary ${t?"btn-sm":""}`,onClick:u,disabled:f.length===0,children:r(y=>y.apply)})})]}):h&v.STATE?o.jsx(k,{...e}):o.jsx(w,{...e})});function On(e){return o.jsx(A,{...e})}const Un=m.memo(e=>{const{onChange:r,value:n,min:t,max:a,unit:s,steps:l,minimal:f,...i}=e,[c,x]=m.useState(n),u=t!=null&&a!=null;m.useEffect(()=>{x(n)},[n]);const h=m.useCallback(y=>{x(y.target.value?y.target.valueAsNumber:"")},[]),d=m.useCallback(y=>!y.target.validationMessage&&r(c===""?null:c),[c,r]);return o.jsxs("div",{className:"flex flex-row flex-wrap gap-3 items-center",children:[!f&&l?o.jsx(Fe,{values:l,onChange:r,value:c}):null,u?o.jsxs("div",{className:"w-full max-w-xs",children:[o.jsx("input",{min:t,max:a,type:"range",className:"range range-xs range-primary validator",value:c,onChange:h,onTouchEnd:d,onMouseUp:d,onKeyUp:d,...i}),o.jsxs("div",{className:"flex justify-between px-1 mt-1 text-xs",children:[o.jsx("span",{children:t}),f&&o.jsx("span",{children:c}),o.jsx("span",{children:a})]})]}):null,(!f||!u)&&o.jsxs("label",{className:"input",children:[o.jsx("input",{type:"number",className:"grow validator",value:c,onChange:h,onBlur:d,min:t,max:a,...i}),s]})]})}),Gn=m.memo(e=>{const{feature:{presets:r,access:n=v.SET,property:t,unit:a,value_max:s,value_min:l,value_step:f},deviceValue:i,steps:c,onChange:x,minimal:u}=e;return n&v.SET?o.jsx(Un,{onChange:h=>x(t?{[t]:h}:h),value:typeof i=="number"?i:"",min:l,max:s,step:f,steps:r?.length?r:c,unit:a,minimal:u}):n&v.STATE?o.jsx(k,{...e}):o.jsx(w,{...e})});function Hn(e){return o.jsx(A,{...e})}const zn=m.memo(e=>{const{onChange:r,value:n,...t}=e,[a,s]=m.useState(n);return m.useEffect(()=>{s(n)},[n]),o.jsx("input",{type:"text",className:"input validator",value:a,onChange:l=>s(l.target.value),onBlur:l=>!l.target.validationMessage&&r(a),...t})}),Ln=m.memo(e=>{const{feature:{access:r=v.SET,property:n},deviceValue:t,onChange:a}=e;return r&v.SET?o.jsx(zn,{onChange:s=>a(n?{[n]:s}:s),value:t!=null?typeof t=="string"?t:JSON.stringify(t):""}):r&v.STATE?o.jsx(k,{...e}):o.jsx(w,{...e})});function Me({feature:e,device:r,deviceState:n,steps:t,onRead:a,onChange:s,featureWrapperClass:l,minimal:f,endpointSpecific:i,parentFeatures:c}){const x=e.property?n[e.property]:n,u=je(e),h={device:r,deviceValue:x,onChange:s,onRead:a,featureWrapperClass:l,minimal:f,endpointSpecific:i,parentFeatures:c},d={feature:e,onRead:a,deviceValue:x,parentFeatures:c,endpointSpecific:i};switch(e.type){case"binary":return o.jsx(l,{...d,children:o.jsx(Pe,{feature:e,...h},u)},u);case"numeric":return o.jsx(l,{...d,children:o.jsx(Gn,{feature:e,...h,steps:t},u)},u);case"list":return e.name==="gradient"&&e.length_min!=null&&e.length_max!=null?o.jsx(l,{...d,children:o.jsx(Cn,{feature:e,...h},u)},u):o.jsx(l,{...d,children:o.jsx(Vn,{feature:e,...h},u)},u);case"text":return o.jsx(l,{...d,children:o.jsx(Ln,{feature:e,...h},u)},u);case"enum":return o.jsx(l,{...d,children:o.jsx(yn,{feature:e,...h},u)},u);case"light":return o.jsx(jn,{feature:e,...h,deviceState:n},u);case"switch":return o.jsx(Hn,{feature:e,...h,deviceState:n},u);case"cover":return o.jsx(pn,{feature:e,...h,deviceState:n},u);case"lock":return o.jsx(On,{feature:e,...h,deviceState:n},u);case"climate":return o.jsx(De,{feature:e,...h,deviceState:n},u);case"fan":return o.jsx(_n,{feature:e,...h,deviceState:n},u);case"composite":{if(e.name==="color_xy"||e.name==="color_hs")return o.jsx(l,{...d,children:o.jsx(dn,{feature:e,...h},u)},u);const y=c&&e.property?n[e.property]:n;return o.jsx(l,{...d,children:o.jsx(A,{feature:e,...h,deviceState:y},u)},u)}default:return console.error("Unsupported feature",e),o.jsx(l,{...d,children:o.jsx("pre",{children:JSON.stringify(e,null,4)})},u)}}export{Me as F,$n as a,qn as s};