signalk-shelly2 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mockDevices.d.ts.map +1 -1
- package/dist/mockDevices.js +3 -1
- package/dist/mockDevices.js.map +1 -1
- package/package.json +5 -5
- package/public/421.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockDevices.d.ts","sourceRoot":"","sources":["../src/mockDevices.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;yBASlC,KAAK,SAAS,EACd,QAAQ,GAAG,EACX,SAAS,OAAO,GAAG,IAAI,EACvB,WAAU,OAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJ1B,
|
|
1
|
+
{"version":3,"file":"mockDevices.d.ts","sourceRoot":"","sources":["../src/mockDevices.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAkB,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;yBASlC,KAAK,SAAS,EACd,QAAQ,GAAG,EACX,SAAS,OAAO,GAAG,IAAI,EACvB,WAAU,OAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJ1B,wBAoRC"}
|
package/dist/mockDevices.js
CHANGED
|
@@ -21,7 +21,9 @@ const defaultDeviceSettings = {
|
|
|
21
21
|
devicePath: undefined
|
|
22
22
|
};
|
|
23
23
|
exports.default = (app, plugin, channel, forTests = true) => {
|
|
24
|
-
const initialDeviceSettings = forTests
|
|
24
|
+
const initialDeviceSettings = forTests
|
|
25
|
+
? defaultDeviceSettings
|
|
26
|
+
: undefined;
|
|
25
27
|
return [
|
|
26
28
|
{
|
|
27
29
|
device: new device_1.Device(app, plugin, channel, '192.168.99.100', 'host.name', 'shelly-smokeDetector1', initialDeviceSettings, 'Smoke Detector'),
|
package/dist/mockDevices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockDevices.js","sourceRoot":"","sources":["../src/mockDevices.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAEH,qCAAiD;AAIjD,MAAM,qBAAqB,GAAmB;IAC5C,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,SAAS;CACtB,CAAA;AAED,kBAAe,CACb,GAAc,EACd,MAAW,EACX,OAAuB,EACvB,WAAoB,IAAI,EACxB,EAAE;IACF,MAAM,qBAAqB,GAA+B,QAAQ,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"mockDevices.js","sourceRoot":"","sources":["../src/mockDevices.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAEH,qCAAiD;AAIjD,MAAM,qBAAqB,GAAmB;IAC5C,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,SAAS;IACtB,UAAU,EAAE,SAAS;CACtB,CAAA;AAED,kBAAe,CACb,GAAc,EACd,MAAW,EACX,OAAuB,EACvB,WAAoB,IAAI,EACxB,EAAE;IACF,MAAM,qBAAqB,GAA+B,QAAQ;QAChE,CAAC,CAAC,qBAAqB;QACvB,CAAC,CAAC,SAAS,CAAA;IACb,OAAO;QACL;YACE,MAAM,EAAE,IAAI,eAAM,CAChB,GAAG,EACH,MAAM,EACN,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,CACjB;YACD,MAAM,EAAE;gBACN,eAAe,EAAE;oBACf,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;oBAChC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;iBAC5B;gBACD,SAAS,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;aACzC;SACF;QACD;YACE,MAAM,EAAE,IAAI,eAAM,CAChB,GAAG,EACH,MAAM,EACN,OAAO,EACP,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,CACjB;YACD,MAAM,EAAE;gBACN,eAAe,EAAE;oBACf,OAAO,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;oBAChC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;iBAC5B;gBACD,SAAS,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,UAAU,EAAE;oBACV,EAAE,EAAE,CAAC;oBACL,MAAM,EAAE,SAAS;oBACjB,MAAM,EAAE,KAAK;iBACd;gBACD,UAAU,EAAE;oBACV,EAAE,EAAE,CAAC;oBACL,MAAM,EAAE,KAAK;oBACb,MAAM,EAAE,KAAK;iBACd;gBACD,SAAS,EAAE;oBACT,EAAE,EAAE,CAAC;oBACL,KAAK,EAAE,KAAK;iBACb;gBACD,SAAS,EAAE;oBACT,EAAE,EAAE,CAAC;oBACL,KAAK,EAAE,KAAK;iBACb;gBACD,SAAS,EAAE;oBACT,EAAE,EAAE,CAAC;oBACL,MAAM,EAAE,IAAI;oBACZ,IAAI,EAAE,IAAI;iBACX;aACF;SACF;KACF,CAAA;AACH,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "signalk-shelly2",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Signal K Plugin For Shelly Gen 2+ devices",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,10 +24,6 @@
|
|
|
24
24
|
"author": "scott@scottbender.net",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@rjsf/bootstrap-4": "^5.24.12",
|
|
28
|
-
"@rjsf/core": "^5.24.11",
|
|
29
|
-
"@rjsf/utils": "^5.24.11",
|
|
30
|
-
"@rjsf/validator-ajv8": "^5.24.11",
|
|
31
27
|
"better-sse": "^0.15.1",
|
|
32
28
|
"buffer": "^6.0.3",
|
|
33
29
|
"camelcase": "^6.2.0",
|
|
@@ -39,6 +35,10 @@
|
|
|
39
35
|
"url": "https://github.com/sbender9/signalk-shelly2"
|
|
40
36
|
},
|
|
41
37
|
"devDependencies": {
|
|
38
|
+
"@rjsf/bootstrap-4": "^5.24.12",
|
|
39
|
+
"@rjsf/core": "^5.24.11",
|
|
40
|
+
"@rjsf/utils": "^5.24.11",
|
|
41
|
+
"@rjsf/validator-ajv8": "^5.24.11",
|
|
42
42
|
"@babel/core": "^7.11.6",
|
|
43
43
|
"@babel/preset-react": "^7.10.4",
|
|
44
44
|
"@fortawesome/fontawesome-free": "^5.15.1",
|
package/public/421.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(self.webpackChunksignalk_shelly2=self.webpackChunksignalk_shelly2||[]).push([[421],{63483:(e,t,a)=>{"use strict";a.r(t),a.d(t,{BTConfig:()=>y,default:()=>w});var n=a(16718),l=a(74810),s=a(40334),c=a(86528),r=a.n(c),o=a(11363),i=a(97493),d=a(82096),m=a(43540),u=a(13660),g=a(31008),h=a(61105),E=a(20455),p=a(57592);const f=e=>console.log.bind(console,e);function y(e){const t=(0,d.A)(e=>({root:{"& > *":{margin:e.spacing(1)}}})),[a,y]=(0,c.useState)({}),[w,v]=(0,c.useState)({}),[b,x]=(0,c.useState)(),[N,A]=(0,c.useState)(),[S,k]=(0,c.useState)(!0),[C,D]=(0,c.useState)(new Map),[$,J]=(0,c.useState)("unknown"),[O,P]=(0,c.useState)(),[U,j]=(0,c.useState)(!1),[M,T]=(0,c.useState)(""),_=t();function F(e,t){const a=new Headers;return a.append("Content-Type","application/json"),fetch(`/plugins/signalk-shelly2/${e}`,{credentials:"include",method:"POST",body:JSON.stringify(t),headers:a})}async function L(e,t={}){let a;try{const n=Object.keys(t).length?"?"+new URLSearchParams(t).toString():"";a=await fetch(`/plugins/signalk-shelly2/${e}${n}`,{credentials:"include",method:"GET"})}catch(e){a={status:500,statusText:e.toString()}}return a}async function z(){const e=await L("getDevices");if(200!=e.status)throw new Error(`Unable get device data: ${e.statusText} (${e.status}) `);return await e.json()}function R(e,t){const a={...b,[e]:t};x(a);const n=C.get(b.id);n&&(n._changesMade=!0,n.settings[e]=t)}function B(e,t){const a={...N.settings,[e]:t},n={...N,settings:a};console.log(`updating component data: ${JSON.stringify(n)}`),A(n);const l=C.get(b.id);l&&(l._changesMade=!0,l.components[N.id].settings=a)}function G(e){return e.isConfigured}function H(e){return G(e),r().createElement(E.A,{className:"d-flex justify-content-between",action:!0,onClick:()=>{const t={...e.settings,id:e.id,address:e.address,hostname:e.hostname,name:e.name,model:e.model,devicePath:e.settings.devicePath||e.defaultPath,enabled:void 0===e.settings?.enabled||e.settings.enabled,components:e.components};x(t),A(null)}},r().createElement("div",{style:{flex:1}},e._changesMade?"*":"",e.model),r().createElement("div",{style:{flex:1}},e.name??""),r().createElement("div",{style:{flex:1}},e.address),r().createElement("div",{style:{flex:1}},e.id),r().createElement("div",{style:{flex:1}},e.connected?"Yes":"No"))}return(0,c.useEffect)(()=>{let e=null;return L("getPluginState").then(async t=>{if(404==t.status)throw J("unknown"),new Error("unable to get plugin state");const a=await t.json();e=new EventSource("/plugins/signalk-shelly2/sse",{withCredentials:!0}),e.addEventListener("resetDevices",e=>{(async()=>{const e=await z();D(new Map(e.map(e=>[e.id,e])))})()}),e.addEventListener("newDevice",e=>{!function(e){let t=JSON.parse(e.data);console.log(`New device: ${JSON.stringify(t.id)}`),D(e=>(e.set(t.id,t),new Map(e)))}(e)}),e.addEventListener("deviceChanged",e=>{!function(e){console.log("devicechanged");const t=JSON.parse(e.data);console.log(t),D(e=>{const a=e.get(t.id);return a&&Object.assign(a,t),new Map(e)})}(e)}),e.addEventListener("pluginstate",e=>{const t=JSON.parse(e.data);J(t.state)}),J(a.state),(async()=>{const e=await z();D(new Map(e.map(e=>[e.id,e])))})()}).catch(e=>{P(e.message)}),()=>{console.log("Closing connection to SSE"),e.close()}},[]),(0,c.useEffect)(()=>{j(""!=M)},[M]),(0,c.useEffect)(()=>{"started"==$?async function(){const e=await L("getBaseData");if(200!=e.status)throw new Error(`Unable to get base data: ${e.statusText} (${e.status}) `);const t=await e.json();return t.schema.htmlDescription=r().createElement("div",null,(0,s.Ay)(t.schema.htmlDescription),r().createElement("p",null)),t}().then(e=>{y(e.schema),v(e.data)}).catch(e=>{P(e.message)}):(y({}),v({}))},[$]),"stopped"==$||"unknown"==$?r().createElement("h3",null,"Enable plugin to see configuration"):r().createElement("div",null,r().createElement(o.A,{anchorOrigin:{horizontal:"center",vertical:"bottom"},onClose:()=>j(!1),open:U,message:M,key:"snackbar"}),O?r().createElement("h2",{style:{color:"red"}},O):"",r().createElement(n.Ay,{schema:a,validator:l.Ay,uiSchema:{"ui:field":"LayoutGridField","ui:layoutGrid":{"ui:row":[{"ui:row":{className:"row",children:[{"ui:columns":{className:"col-xs-4",children:["poll"]}}]}}]}},onChange:e=>v(e.formData),onSubmit:({formData:e},t)=>{var a;a=e,D(new Map),F("updateBaseData",a).then(e=>{200!=e.status&&P(`Unable to update base data: ${e.statusText} (${e.status})`)}),x(null),A(null)},onError:f("errors"),formData:w}),r().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),r().createElement(u.A,{defaultActiveKey:"_configured",id:"domain-tabs",className:"mb-3"},function(){console.log("loading tabs");const e=Array.from(C.entries()).filter(e=>G(e[1])),t=Array.from(C.entries()).filter(e=>!G(e[1]));let a={};return a._configured=0==e.length?"Select a device from Unconfigured and configure it.":e.map(e=>(console.log(`configured devices: ${e[0]}`),H(C.get(e[0])))),a._unconfigured=0==t.length?"No Unconfigured Devices Found":t.map(e=>H(C.get(e[0]))),Object.keys(a).map(e=>function(e,t){let a=e.slice("_"===e.charAt(0)?1:0);return r().createElement(g.A,{eventKey:e,title:`${a.charAt(0).toUpperCase()}${a.slice(1)}${"string"==typeof t?"":" ("+t.length+")"}`},r().createElement(m.A,{style:{maxHeight:"300px",overflowY:"auto"}},r().createElement(E.A,{className:"d-flex justify-content-between font-weight-bold"},r().createElement("div",{style:{flex:1}},"Model"),r().createElement("div",{style:{flex:1}},"Name"),r().createElement("div",{style:{flex:1}},"Address"),r().createElement("div",{style:{flex:1}},"Shelly ID"),r().createElement("div",{style:{flex:1}},"Connected")),t))}(e,a[e]))}()),r().createElement("div",{style:{paddingLeft:10,paddingTop:10,display:b?"":"none"}},r().createElement("fieldset",{disabled:!S},r().createElement(p.lV,{onSubmit:e=>{e.preventDefault(),F("updateDeviceConfig",b).then(e=>{if(200!=e.status)throw new Error(e.statusText)});const t=C.get(b.id);t&&(t._changesMade=!1),x(null),A(null)},onError:f("errors")},(console.log(`getting common form for sensorData: ${JSON.stringify(b)}`),r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},"Device"),r().createElement(p.bw,null,r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"deviceEnabled"},"Enabled")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.JU,{className:"switch switch-text switch-primary mb-0 me-3"},r().createElement(p.pd,{type:"checkbox",id:"deviceEnabled",name:"deviceEnabled",className:"switch-input",checked:b?.enabled,onChange:e=>R("enabled",e.target.checked)}),r().createElement("span",{className:"switch-label","data-on":"On","data-off":"Off"}),r().createElement("span",{className:"switch-handle"})))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"devicePath"},"Path")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"devicePath",value:b?.devicePath||b?.defaultPath||"",onChange:e=>R("devicePath",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Signal K path to publish data to."))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"displayName"},"Display Name (meta)")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"displayName",value:b?.displayName||b?.name||"",onChange:e=>R("displayName",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Display name meta data for the device."))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"password"},"Password")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"password",name:"password",value:b?.password||"",onChange:e=>R("password",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Password for the device, leave empty if no password is set."))))))),b&&b.components?r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},"Component"),r().createElement(p.bw,null,r().createElement(m.A,{style:{maxHeight:"300px",overflowY:"auto"}},r().createElement(E.A,{className:"d-flex justify-content-between font-weight-bold"},r().createElement("div",{style:{flex:1}},"Type"),r().createElement("div",{style:{flex:1}},"Identifier")),b.components.map(e=>function(e){return r().createElement(E.A,{className:"d-flex justify-content-between",action:!0,onClick:t=>{t.preventDefault(),t.stopPropagation(),A(e)}},r().createElement("div",{style:{flex:1}},e.name),r().createElement("div",{style:{flex:1}},e.id))}(e)))))):"",N?(console.log(`getting component form : ${JSON.stringify(N)}`),r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},N.name," ",N.id),r().createElement(p.bw,null,r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"deviceEnabled"},"Enabled")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.JU,{className:"switch switch-text switch-primary mb-0 me-3"},r().createElement(p.pd,{type:"checkbox",id:"deviceEnabled",name:"deviceEnabled",className:"switch-input",checked:void 0===N?.settings.enabled||N.settings.enabled,onChange:e=>B("enabled",e.target.checked)}),r().createElement("span",{className:"switch-label","data-on":"On","data-off":"Off"}),r().createElement("span",{className:"switch-handle"})))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"devicePath"},"Path")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"devicePath",value:void 0!==N.settings.path?N.settings.path:N.id,onChange:e=>B("path",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Used to generate the path name, ie. electrical.switches.${devicePath}.${path}.state"))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"displayName"},"Display Name (meta)")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"displayName",value:N?.settings?.displayName||"",onChange:e=>B("displayName",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Display name meta data for the device."))))))):"",r().createElement("div",{className:_.root},r().createElement(i.A,{type:"submit",color:"primary",variant:"contained"},"Save"),r().createElement(i.A,{variant:"contained",onClick:()=>{!function(e){const t=C.get(e);t._changesMade=!1,t.settings=JSON.parse(JSON.stringify(t.settingsCopy)),x({...t.settings}),A(null)}(b.id)}},"Undo"),r().createElement(i.A,{variant:"contained",color:"secondary",onClick:e=>function(e){const t=C.get(e);(!G(t)||window.confirm(`Delete configuration for ${t.id}?`))&&function(e){try{F("removeDeviceConfig",{id:e}).then(e=>{if(200!=e.status)throw new Error(e.statusText)}),D(t=>(t.delete(e),new Map(t))),x(null),A(null)}catch{}}(e)}(b.id)},"Delete"))))))}const w=y},95098:()=>{}}]);
|
|
1
|
+
(self.webpackChunksignalk_shelly2=self.webpackChunksignalk_shelly2||[]).push([[421],{63483:(e,t,a)=>{"use strict";a.r(t),a.d(t,{BTConfig:()=>y,default:()=>w});var n=a(16718),l=a(74810),s=a(40334),c=a(86528),r=a.n(c),o=a(11363),i=a(97493),d=a(82096),m=a(43540),u=a(13660),g=a(31008),h=a(61105),E=a(20455),p=a(57592);const f=e=>console.log.bind(console,e);function y(e){const t=(0,d.A)(e=>({root:{"& > *":{margin:e.spacing(1)}}})),[a,y]=(0,c.useState)({}),[w,v]=(0,c.useState)({}),[b,x]=(0,c.useState)(),[N,A]=(0,c.useState)(),[S,k]=(0,c.useState)(!0),[C,D]=(0,c.useState)(new Map),[$,J]=(0,c.useState)("unknown"),[O,P]=(0,c.useState)(),[U,j]=(0,c.useState)(!1),[M,T]=(0,c.useState)(""),_=t();function F(e,t){const a=new Headers;return a.append("Content-Type","application/json"),fetch(`/plugins/signalk-shelly2/${e}`,{credentials:"include",method:"POST",body:JSON.stringify(t),headers:a})}async function L(e,t={}){let a;try{const n=Object.keys(t).length?"?"+new URLSearchParams(t).toString():"";a=await fetch(`/plugins/signalk-shelly2/${e}${n}`,{credentials:"include",method:"GET"})}catch(e){a={status:500,statusText:e.toString()}}return a}async function z(){const e=await L("getDevices");if(200!=e.status)throw new Error(`Unable get device data: ${e.statusText} (${e.status}) `);return await e.json()}function R(e,t){const a={...b,[e]:t};x(a);const n=C.get(b.id);n&&(n._changesMade=!0,n.settings[e]=t)}function B(e,t){const a={...N.settings,[e]:t},n={...N,settings:a};console.log(`updating component data: ${JSON.stringify(n)}`),A(n);const l=C.get(b.id);l&&(l._changesMade=!0,l.components[N.id].settings=a)}function G(e){return e.isConfigured}function H(e){return G(e),r().createElement(E.A,{className:"d-flex justify-content-between",action:!0,onClick:()=>{const t={...e.settings,id:e.id,address:e.address,hostname:e.hostname,name:e.name,model:e.model,devicePath:e.settings.devicePath||e.defaultPath,enabled:void 0===e.settings?.enabled||e.settings.enabled,components:e.components};x(t),A(null)}},r().createElement("div",{style:{flex:1}},e._changesMade?"*":"",e.model),r().createElement("div",{style:{flex:1}},e.name??""),r().createElement("div",{style:{flex:1}},e.address),r().createElement("div",{style:{flex:1}},e.id),r().createElement("div",{style:{flex:1}},e.connected?"Yes":"No"))}return(0,c.useEffect)(()=>{let e=null;return L("getPluginState").then(async t=>{if(404==t.status)throw J("unknown"),new Error("unable to get plugin state");const a=await t.json();e=new EventSource("/plugins/signalk-shelly2/sse",{withCredentials:!0}),e.addEventListener("resetDevices",e=>{(async()=>{const e=await z();D(new Map(e.map(e=>[e.id,e])))})()}),e.addEventListener("newDevice",e=>{!function(e){let t=JSON.parse(e.data);console.log(`New device: ${JSON.stringify(t.id)}`),D(e=>(e.set(t.id,t),new Map(e)))}(e)}),e.addEventListener("deviceChanged",e=>{!function(e){console.log("devicechanged");const t=JSON.parse(e.data);console.log(t),D(e=>{const a=e.get(t.id);return a&&Object.assign(a,t),new Map(e)})}(e)}),e.addEventListener("pluginstate",e=>{const t=JSON.parse(e.data);J(t.state)}),J(a.state),(async()=>{const e=await z();D(new Map(e.map(e=>[e.id,e])))})()}).catch(e=>{P(e.message)}),()=>{console.log("Closing connection to SSE"),e&&e.close()}},[]),(0,c.useEffect)(()=>{j(""!=M)},[M]),(0,c.useEffect)(()=>{"started"==$?async function(){const e=await L("getBaseData");if(200!=e.status)throw new Error(`Unable to get base data: ${e.statusText} (${e.status}) `);const t=await e.json();return t.schema.htmlDescription=r().createElement("div",null,(0,s.Ay)(t.schema.htmlDescription),r().createElement("p",null)),t}().then(e=>{y(e.schema),v(e.data)}).catch(e=>{P(e.message)}):(y({}),v({}))},[$]),"stopped"==$||"unknown"==$?r().createElement("h3",null,"Enable plugin to see configuration"):r().createElement("div",null,r().createElement(o.A,{anchorOrigin:{horizontal:"center",vertical:"bottom"},onClose:()=>j(!1),open:U,message:M,key:"snackbar"}),O?r().createElement("h2",{style:{color:"red"}},O):"",r().createElement(n.Ay,{schema:a,validator:l.Ay,uiSchema:{"ui:field":"LayoutGridField","ui:layoutGrid":{"ui:row":[{"ui:row":{className:"row",children:[{"ui:columns":{className:"col-xs-4",children:["poll"]}}]}}]}},onChange:e=>v(e.formData),onSubmit:({formData:e},t)=>{var a;a=e,D(new Map),F("updateBaseData",a).then(e=>{200!=e.status&&P(`Unable to update base data: ${e.statusText} (${e.status})`)}),x(null),A(null)},onError:f("errors"),formData:w}),r().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),r().createElement(u.A,{defaultActiveKey:"_configured",id:"domain-tabs",className:"mb-3"},function(){console.log("loading tabs");const e=Array.from(C.entries()).filter(e=>G(e[1])),t=Array.from(C.entries()).filter(e=>!G(e[1]));let a={};return a._configured=0==e.length?"Select a device from Unconfigured and configure it.":e.map(e=>(console.log(`configured devices: ${e[0]}`),H(C.get(e[0])))),a._unconfigured=0==t.length?"No Unconfigured Devices Found":t.map(e=>H(C.get(e[0]))),Object.keys(a).map(e=>function(e,t){let a=e.slice("_"===e.charAt(0)?1:0);return r().createElement(g.A,{eventKey:e,title:`${a.charAt(0).toUpperCase()}${a.slice(1)}${"string"==typeof t?"":" ("+t.length+")"}`},r().createElement(m.A,{style:{maxHeight:"300px",overflowY:"auto"}},r().createElement(E.A,{className:"d-flex justify-content-between font-weight-bold"},r().createElement("div",{style:{flex:1}},"Model"),r().createElement("div",{style:{flex:1}},"Name"),r().createElement("div",{style:{flex:1}},"Address"),r().createElement("div",{style:{flex:1}},"Shelly ID"),r().createElement("div",{style:{flex:1}},"Connected")),t))}(e,a[e]))}()),r().createElement("div",{style:{paddingLeft:10,paddingTop:10,display:b?"":"none"}},r().createElement("fieldset",{disabled:!S},r().createElement(p.lV,{onSubmit:e=>{e.preventDefault(),F("updateDeviceConfig",b).then(e=>{if(200!=e.status)throw new Error(e.statusText)});const t=C.get(b.id);t&&(t._changesMade=!1),x(null),A(null)},onError:f("errors")},(console.log(`getting common form for sensorData: ${JSON.stringify(b)}`),r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},"Device"),r().createElement(p.bw,null,r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"deviceEnabled"},"Enabled")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.JU,{className:"switch switch-text switch-primary mb-0 me-3"},r().createElement(p.pd,{type:"checkbox",id:"deviceEnabled",name:"deviceEnabled",className:"switch-input",checked:b?.enabled,onChange:e=>R("enabled",e.target.checked)}),r().createElement("span",{className:"switch-label","data-on":"On","data-off":"Off"}),r().createElement("span",{className:"switch-handle"})))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"devicePath"},"Path")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"devicePath",value:b?.devicePath||b?.defaultPath||"",onChange:e=>R("devicePath",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Signal K path to publish data to."))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"displayName"},"Display Name (meta)")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"displayName",value:b?.displayName||b?.name||"",onChange:e=>R("displayName",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Display name meta data for the device."))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"password"},"Password")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"password",name:"password",value:b?.password||"",onChange:e=>R("password",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Password for the device, leave empty if no password is set."))))))),b&&b.components?r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},"Component"),r().createElement(p.bw,null,r().createElement(m.A,{style:{maxHeight:"300px",overflowY:"auto"}},r().createElement(E.A,{className:"d-flex justify-content-between font-weight-bold"},r().createElement("div",{style:{flex:1}},"Type"),r().createElement("div",{style:{flex:1}},"Identifier")),b.components.map(e=>function(e){return r().createElement(E.A,{className:"d-flex justify-content-between",action:!0,onClick:t=>{t.preventDefault(),t.stopPropagation(),A(e)}},r().createElement("div",{style:{flex:1}},e.name),r().createElement("div",{style:{flex:1}},e.id))}(e)))))):"",N?(console.log(`getting component form : ${JSON.stringify(N)}`),r().createElement("div",{className:_.root},r().createElement(p.Zp,null,r().createElement(p.aR,{className:"d-flex justify-content-between align-items-center py-2",style:{cursor:"pointer"}},N.name," ",N.id),r().createElement(p.bw,null,r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"deviceEnabled"},"Enabled")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.JU,{className:"switch switch-text switch-primary mb-0 me-3"},r().createElement(p.pd,{type:"checkbox",id:"deviceEnabled",name:"deviceEnabled",className:"switch-input",checked:void 0===N?.settings.enabled||N.settings.enabled,onChange:e=>B("enabled",e.target.checked)}),r().createElement("span",{className:"switch-label","data-on":"On","data-off":"Off"}),r().createElement("span",{className:"switch-handle"})))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"devicePath"},"Path")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"devicePath",value:void 0!==N.settings.path?N.settings.path:N.id,onChange:e=>B("path",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Used to generate the path name, ie. electrical.switches.${devicePath}.${path}.state"))),r().createElement(p.gE,{row:!0},r().createElement(h.A,{md:"2"},r().createElement(p.JU,{htmlFor:"displayName"},"Display Name (meta)")),r().createElement(h.A,{xs:"12",md:"10"},r().createElement(p.pd,{size:"50",style:{width:"auto"},type:"text",name:"displayName",value:N?.settings?.displayName||"",onChange:e=>B("displayName",e.target.value)}),r().createElement(p.ay,{color:"muted"},"Display name meta data for the device."))))))):"",r().createElement("div",{className:_.root},r().createElement(i.A,{type:"submit",color:"primary",variant:"contained"},"Save"),r().createElement(i.A,{variant:"contained",onClick:()=>{!function(e){const t=C.get(e);t._changesMade=!1,t.settings=JSON.parse(JSON.stringify(t.settingsCopy)),x({...t.settings}),A(null)}(b.id)}},"Undo"),r().createElement(i.A,{variant:"contained",color:"secondary",onClick:e=>function(e){const t=C.get(e);(!G(t)||window.confirm(`Delete configuration for ${t.id}?`))&&function(e){try{F("removeDeviceConfig",{id:e}).then(e=>{if(200!=e.status)throw new Error(e.statusText)}),D(t=>(t.delete(e),new Map(t))),x(null),A(null)}catch{}}(e)}(b.id)},"Delete"))))))}const w=y},95098:()=>{}}]);
|