signalk-shelly2 2.0.3 → 2.1.0
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/components/Flood.d.ts +9 -0
- package/dist/components/Flood.d.ts.map +1 -0
- package/dist/components/Flood.js +61 -0
- package/dist/components/Flood.js.map +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +4 -1
- package/dist/components/index.js.map +1 -1
- package/package.json +1 -1
- package/public/421.js +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Device } from '../device';
|
|
2
|
+
import { Component, ComponentPath } from './Component';
|
|
3
|
+
import { PathValue } from '@signalk/server-api';
|
|
4
|
+
export declare class Flood extends Component {
|
|
5
|
+
constructor(device: Device, componentId: number);
|
|
6
|
+
getDeltaValues(status: any): PathValue[];
|
|
7
|
+
getPaths(): ComponentPath[];
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=Flood.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Flood.d.ts","sourceRoot":"","sources":["../../src/components/Flood.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAQ,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAErD,qBAAa,KAAM,SAAQ,SAAS;gBACtB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAI/C,cAAc,CAAC,MAAM,EAAE,GAAG,GAAG,SAAS,EAAE;IAyBxC,QAAQ,IAAI,aAAa,EAAE;CAgB5B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Scott Bender <scott@scottbender.net>
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Flood = void 0;
|
|
18
|
+
const Component_1 = require("./Component");
|
|
19
|
+
class Flood extends Component_1.Component {
|
|
20
|
+
constructor(device, componentId) {
|
|
21
|
+
super(device, componentId, 'flood', 'Flood', 'environment.flood', false);
|
|
22
|
+
}
|
|
23
|
+
getDeltaValues(status) {
|
|
24
|
+
const values = super.getDeltaValues(status);
|
|
25
|
+
const componentProps = this.device.getComponentProps(this.componentName, this.componentId);
|
|
26
|
+
const componentStatus = status[`${this.componentName}:${this.componentId}`];
|
|
27
|
+
if (componentStatus !== undefined) {
|
|
28
|
+
const method = ['visual'];
|
|
29
|
+
if (componentStatus.mute !== true) {
|
|
30
|
+
method.push('sound');
|
|
31
|
+
}
|
|
32
|
+
values.push({
|
|
33
|
+
path: `notifications.${this.getComponentPath(undefined)}`,
|
|
34
|
+
value: {
|
|
35
|
+
state: componentStatus.alarm ? 'alarm' : 'normal',
|
|
36
|
+
method,
|
|
37
|
+
message: `${componentStatus.alarm ? 'Water detected' : 'No water detected'} in ${componentProps?.displayName || this.device.deviceSettings?.displayName || this.componentId}`
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return values;
|
|
42
|
+
}
|
|
43
|
+
getPaths() {
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
key: 'alarm',
|
|
47
|
+
meta: {
|
|
48
|
+
units: 'bool'
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: 'mute',
|
|
53
|
+
meta: {
|
|
54
|
+
units: 'bool'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Flood = Flood;
|
|
61
|
+
//# sourceMappingURL=Flood.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Flood.js","sourceRoot":"","sources":["../../src/components/Flood.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAGH,2CAAsD;AAGtD,MAAa,KAAM,SAAQ,qBAAS;IAClC,YAAY,MAAc,EAAE,WAAmB;QAC7C,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAA;IAC1E,CAAC;IAED,cAAc,CAAC,MAAW;QACxB,MAAM,MAAM,GAAgB,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QACxD,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAClD,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,WAAW,CACjB,CAAA;QACD,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;QAE3E,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,CAAA;YACzB,IAAI,eAAe,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACtB,CAAC;YACD,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,iBAAiB,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAU;gBACjE,KAAK,EAAE;oBACL,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;oBACjD,MAAM;oBACN,OAAO,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,mBAAmB,OAAO,cAAc,EAAE,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,WAAW,IAAI,IAAI,CAAC,WAAW,EAAE;iBAC9K;aACF,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED,QAAQ;QACN,OAAO;YACL;gBACE,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE;oBACJ,KAAK,EAAE,MAAM;iBACd;aACF;YACD;gBACE,GAAG,EAAE,MAAM;gBACX,IAAI,EAAE;oBACJ,KAAK,EAAE,MAAM;iBACd;aACF;SACF,CAAA;IACH,CAAC;CACF;AA9CD,sBA8CC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAavC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAavC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC,cAAc,aAAa,CAAA;AA6B3B,eAAO,MAAM,mBAAmB,UAe/B,CAAA;AAED,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD;AAED,eAAO,MAAM,iBAAiB,EAAE;IAC9B,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,SAAS,CAAA;CAgBzD,CAAA;AAED,wBAAgB,eAAe,CAC7B,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,SAAS,GAAG,IAAI,CAMlB"}
|
package/dist/components/index.js
CHANGED
|
@@ -44,6 +44,7 @@ const EM1_1 = require("./EM1");
|
|
|
44
44
|
const PM1_1 = require("./PM1");
|
|
45
45
|
const Smoke_1 = require("./Smoke");
|
|
46
46
|
const Devicepower_1 = require("./Devicepower");
|
|
47
|
+
const Flood_1 = require("./Flood");
|
|
47
48
|
__exportStar(require("./Component"), exports);
|
|
48
49
|
/*
|
|
49
50
|
export * from './Switch'
|
|
@@ -84,6 +85,7 @@ exports.supportedComponents = [
|
|
|
84
85
|
'voltmeter',
|
|
85
86
|
'input',
|
|
86
87
|
'smoke',
|
|
88
|
+
'flood',
|
|
87
89
|
'devicepower'
|
|
88
90
|
];
|
|
89
91
|
function getSupportedComponents() {
|
|
@@ -102,7 +104,8 @@ exports.componentCreators = {
|
|
|
102
104
|
voltmeter: (device, id) => new Voltmeter_1.Voltmeter(device, id),
|
|
103
105
|
input: (device, id) => new Input_1.Input(device, id),
|
|
104
106
|
smoke: (device, id) => new Smoke_1.Smoke(device, id),
|
|
105
|
-
devicepower: (device, id) => new Devicepower_1.Devicepower(device, id)
|
|
107
|
+
devicepower: (device, id) => new Devicepower_1.Devicepower(device, id),
|
|
108
|
+
flood: (device, id) => new Flood_1.Flood(device, id)
|
|
106
109
|
};
|
|
107
110
|
function createComponent(componentName, device, id) {
|
|
108
111
|
const creator = exports.componentCreators[componentName];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;AAiEH,wDAEC;AAqBD,0CAUC;AA/FD,qCAAiC;AACjC,mCAA+B;AAC/B,+BAA2B;AAC3B,iCAA6B;AAC7B,mCAA+B;AAC/B,+CAA2C;AAC3C,yCAAqC;AACrC,2CAAuC;AACvC,6BAAyB;AACzB,+BAA2B;AAC3B,+BAA2B;AAC3B,mCAA+B;AAE/B,+CAA2C;AAC3C,mCAA+B;AAE/B,8CAA2B;AAC3B;;;;;EAKE;AAEF;;;;;;;;;;;;;;;;;;;IAmBI;AAES,QAAA,mBAAmB,GAAG;IACjC,QAAQ;IACR,OAAO;IACP,KAAK;IACL,MAAM;IACN,IAAI;IACJ,KAAK;IACL,KAAK;IACL,aAAa;IACb,UAAU;IACV,WAAW;IACX,OAAO;IACP,OAAO;IACP,OAAO;IACP,aAAa;CACd,CAAA;AAED,SAAgB,sBAAsB;IACpC,OAAO,2BAAmB,CAAA;AAC5B,CAAC;AAEY,QAAA,iBAAiB,GAE1B;IACF,MAAM,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,eAAM,CAAC,MAAM,EAAE,EAAE,CAAC;IAC9D,KAAK,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,aAAK,CAAC,MAAM,EAAE,EAAE,CAAC;IAC5D,GAAG,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,SAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IACxD,IAAI,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,WAAI,CAAC,MAAM,EAAE,EAAE,CAAC;IAC1D,EAAE,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,OAAE,CAAC,MAAM,EAAE,EAAE,CAAC;IACtD,GAAG,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,SAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IACxD,GAAG,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,SAAG,CAAC,MAAM,EAAE,EAAE,CAAC;IACxD,WAAW,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,yBAAW,CAAC,MAAM,EAAE,EAAE,CAAC;IACxE,QAAQ,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,mBAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;IAClE,SAAS,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,qBAAS,CAAC,MAAM,EAAE,EAAE,CAAC;IACpE,KAAK,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,aAAK,CAAC,MAAM,EAAE,EAAE,CAAC;IAC5D,KAAK,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,aAAK,CAAC,MAAM,EAAE,EAAE,CAAC;IAC5D,WAAW,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,yBAAW,CAAC,MAAM,EAAE,EAAE,CAAC;IACxE,KAAK,EAAE,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,aAAK,CAAC,MAAM,EAAE,EAAE,CAAC;CAC7D,CAAA;AAED,SAAgB,eAAe,CAC7B,aAAqB,EACrB,MAAc,EACd,EAAU;IAEV,MAAM,OAAO,GAAG,yBAAiB,CAAC,aAAa,CAAC,CAAA;IAChD,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAC5B,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
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&&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,{ShellyConfig:()=>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 G(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 H(e){return e.isConfigured}function K(e){return H(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=>H(e[1])),t=Array.from(C.entries()).filter(e=>!H(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]}`),K(C.get(e[0])))),a._unconfigured=0==t.length?"No Unconfigured Devices Found":t.map(e=>K(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=>G("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=>G("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=>G("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);(!H(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:()=>{}}]);
|