bt-sensors-plugin-sk 1.2.6-beta → 1.2.6-beta-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.
@@ -19,8 +19,6 @@ object-assign
19
19
 
20
20
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
21
21
 
22
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
23
-
24
22
  /**
25
23
  * @license React
26
24
  * react-is.production.min.js
package/public/847.js ADDED
@@ -0,0 +1 @@
1
+ (self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[]).push([[847],{9337:()=>{},62995:(e,t,n)=>{"use strict";n.r(t),n.d(t,{BTConfig:()=>k,default:()=>C});var a=n(73490),s=n(74810),r=n(40334),o=n(86528),c=n.n(o),i=n(11363),l=n(97493),u=n(27606),m=n(82096),d=n(3768),g=n(71431),f=n(39676),h=n(47041),p=n(86038),E=n(95027),w=n(43540),y=n(38250),S=n(31008),b=n(20455),v=n(23399);const A=e=>console.log.bind(console,e);function k(e){const t=(0,m.A)((e=>({root:{"& > *":{margin:e.spacing(1)}}}))),[n,k]=(0,o.useState)({}),[C,D]=(0,o.useState)({}),[_,$]=(0,o.useState)({}),[N,x]=(0,o.useState)({"ui:options":{label:!1},paths:{enableMarkdownInDescription:!0},title:{"ui:widget":"hidden"}}),[O,T]=(0,o.useState)(),[j,M]=(0,o.useState)(!1),[U,J]=(0,o.useState)(!0),[L,I]=(0,o.useState)(new Map),[P,K]=(0,o.useState)({progress:0,maxTimeout:100,deviceCount:0,totalDevices:0}),[R,B]=(0,o.useState)("unknown"),[G,W]=(0,o.useState)(),[F,H]=(0,o.useState)(!1),[z,Y]=(0,o.useState)(""),q=t();function Q(e,t){const n=new Headers;return n.append("Content-Type","application/json"),fetch(`/plugins/bt-sensors-plugin-sk/${e}`,{credentials:"include",method:"POST",body:JSON.stringify(t),headers:n})}async function V(e,t={}){let n;try{const a=Object.keys(t).length?"?"+new URLSearchParams(t).toString():"";n=await fetch(`/plugins/bt-sensors-plugin-sk/${e}${a}`,{credentials:"include",method:"GET"})}catch(e){n={status:500,statusText:e.toString()}}return n}function X(e){return Object.keys(e.configCopy).length>0}function Z(e){const t=X(e);return c().createElement(b.A,{action:!0,onClick:()=>{e.config.mac_address=e.info.mac,$(e.schema),T(e.config)}},c().createElement("div",{class:"d-flex justify-content-between align-items-center",style:t?{fontWeight:"normal"}:{fontStyle:"italic"}},`${e._changesMade?"*":""}${e.info.name} MAC: ${e.info.mac} RSSI: ${n=e.info.RSSI,null==n?NaN:n}`,c().createElement("div",{class:"d-flex justify-content-between "},function(e){return null==e.info.lastContactDelta||e.info.lastContactDelta>e.config.discoveryTimeout?c().createElement(d.A,null):e.info.signalStrength>80?c().createElement(g.A,null):e.info.signalStrength>60?c().createElement(f.A,null):e.info.signalStrength>40?c().createElement(h.A,null):e.info.signalStrength>20?c().createElement(p.A,null):c().createElement(E.A,null)}(e))));var n}function ee(e){window.open(e,"_blank","noreferrer")}return(0,o.useEffect)((()=>{let e=null;return V("getPluginState").then((async t=>{if(404==t.status)throw B("unknown"),new Error("unable to get plugin state");const n=await t.json();e=new EventSource("/plugins/bt-sensors-plugin-sk/sse",{withCredentials:!0}),e.addEventListener("newsensor",(e=>{!function(e){let t=JSON.parse(e.data);console.log(`New sensor: ${t.info.mac}`),I((e=>(e.set(t.info.mac,t),new Map(e))))}(e)})),e.addEventListener("sensorchanged",(e=>{!function(e){console.log("sensorchanged");const t=JSON.parse(e.data);I((e=>{const n=e.get(t.mac);return n&&Object.assign(n.info,t),new Map(e)}))}(e)})),e.addEventListener("progress",(e=>{const t=JSON.parse(e.data);K(t)})),e.addEventListener("pluginstate",(e=>{const t=JSON.parse(e.data);B(t.state)})),B(n.state),(async()=>{const e=await async function(){const e=await V("getSensors");if(200!=e.status)throw new Error(`Unable get sensor data: ${e.statusText} (${e.status}) `);return await e.json()}();I(new Map(e.map((e=>[e.info.mac,e]))))})()})).catch((e=>{W(e.message)})),()=>{console.log("Closing connection to SSE"),e.close()}}),[]),(0,o.useEffect)((()=>{if(!j)return;if(!O||!L)return;const e=L.get(O.mac_address);e&&_&&O&&Object.hasOwn(O,"params")&&"UNKNOWN"==e.info.class&&O.params.sensorClass&&"UNKNOWN"!=O.params.sensorClass&&(J(!1),Y(`Please wait. Fetching schema for ${O.params.sensorClass}...`),async function(e,t){const n=await V("getSensorInfo",{mac_address:e,class:t});if(200!=n.status)throw new Error(`Unable get sensor info: ${n.statusText} (${n.status}) `);return await n.json()}(O.mac_address,O.params.sensorClass).then((e=>{$(e.schema)})).catch((e=>{alert(e.message)})).finally((()=>{Y(""),J(!0),M(!1)})))}),[j]),(0,o.useEffect)((()=>{H(""!=z)}),[z]),(0,o.useEffect)((()=>{"started"==R?(async function(){const e=await V("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=c().createElement("div",null,(0,r.Ay)(t.schema.htmlDescription),c().createElement("p",null)),t}().then((e=>{k(e.schema),D(e.data)})).catch((e=>{W(e.message)})),async function(){const e=await V("getProgress");if(200!=e.status)throw new Error(`Unable to get progress: ${e.statusText} (${e.status}) `);return await e.json()}().then((e=>{K(e)})).catch((e=>{W(e.message)}))):(k({}),D({}))}),[R]),"stopped"==R||"unknown"==R?c().createElement("h3",null,"Enable plugin to see configuration"):c().createElement("div",null,c().createElement(i.A,{anchorOrigin:{horizontal:"center",vertical:"bottom"},onClose:()=>H(!1),open:F,message:z,key:"snackbar"}),c().createElement("div",{className:q.root},c().createElement(l.A,{variant:"contained",onClick:()=>{ee("https://github.com/naugehyde/bt-sensors-plugin-sk/tree/1.2.0-beta#configuration")}},"Documentation"),c().createElement(l.A,{variant:"contained",onClick:()=>{ee("https://github.com/naugehyde/bt-sensors-plugin-sk/issues/new/choose")}},"Report Issue"),c().createElement(l.A,{variant:"contained",onClick:()=>{ee("https://discord.com/channels/1170433917761892493/1295425963466952725")}},"Discord Thread"),c().createElement("p",null),c().createElement("p",null)),c().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),G?c().createElement("h2",{style:{color:"red"}},G):"",c().createElement(a.Ay,{schema:n,validator:s.Ay,uiSchema:{"ui:field":"LayoutGridField","ui:layoutGrid":{"ui:row":[{"ui:row":{className:"row",children:[{"ui:columns":{className:"col-xs-4",children:["adapter","transport","duplicateData","discoveryTimeout","discoveryInterval"]}}]}}]}},onChange:e=>D(e.formData),onSubmit:({formData:e},t)=>{var n;n=e,I(new Map),Q("updateBaseData",n).then((e=>{200!=e.status&&W(`Unable to update base data: ${e.statusText} (${e.status})`)})),$({})},onError:A("errors"),formData:C}),c().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),c().createElement("p",null),c().createElement("p",null),P.deviceCount<P.totalDevices?c().createElement(v.A,{max:P.maxTimeout,now:P.progress}):"",c().createElement("p",null),c().createElement(y.A,{defaultActiveKey:"_configured",id:"domain-tabs",className:"mb-3"},function(){const e=[...new Set(L.entries().map((e=>e[1].info.domain)))].sort(),t=Array.from(L.entries()).filter((e=>X(e[1])));let n={};return n._configured=0==t.length?"Select a device from its domain tab (Electrical etc.) and configure it.":t.map((e=>Z(L.get(e[0])))),e.forEach((e=>{var t;n[e]=(t=e,Array.from(L.entries()).filter((e=>e[1].info.domain===t))).map((e=>Z(L.get(e[0]))))})),Object.keys(n).map((e=>function(e,t){let n=e.slice("_"===e.charAt(0)?1:0);return c().createElement(S.A,{eventKey:e,title:`${n.charAt(0).toUpperCase()}${n.slice(1)}${"string"==typeof t?"":" ("+t.length+")"}`},c().createElement(w.A,{style:{maxHeight:"300px",overflowY:"auto"}},t))}(e,n[e])))}()),c().createElement("div",{style:{paddingLeft:10,paddingTop:10,display:0==Object.keys(_).length?"none":""}},c().createElement(u.A,{container:!0,direction:"column",style:{spacing:5}},c().createElement(u.A,{item:!0},c().createElement("h2",null,_?.title),c().createElement("p",null)),c().createElement(u.A,{item:!0},(0,r.Ay)(_?.htmlDescription))),c().createElement("fieldset",{disabled:!U},c().createElement(a.Ay,{schema:_,validator:s.Ay,uiSchema:N,onChange:(e,t)=>{const n=L.get(e.formData.mac_address);n&&(n._changesMade=!0,n.config=e.formData,T(e.formData)),"root_params_sensorClass"==t&&M(!0)},onSubmit:({formData:e},t)=>{var n;Q("updateSensorData",n=e).then((e=>{if(200!=e.status)throw new Error(e.statusText);I((e=>(e.delete(n.mac_address),new Map(e)))),$({})})),alert("Changes saved")},onError:A("errors"),formData:O},c().createElement("div",{className:q.root},c().createElement(l.A,{type:"submit",color:"primary",variant:"contained"},"Save"),c().createElement(l.A,{variant:"contained",onClick:()=>{var e;e=O.mac_address,L.get(e)._changesMade=!1,L.get(e).config=JSON.parse(JSON.stringify(L.get(e).configCopy)),T(L.get(e).config)}},"Undo"),c().createElement(l.A,{variant:"contained",color:"secondary",onClick:e=>function(e){const t=L.get(e);(!X(t)||window.confirm(`Delete configuration for ${t.info.name}?`))&&function(e){try{Q("removeSensorData",{mac_address:e}).then((e=>{if(200!=e.status)throw new Error(e.statusText)})),I((t=>(t.delete(e),new Map(t)))),$({})}catch{}}(e)}(O.mac_address)},"Delete"))))))}const C=k}}]);
Binary file
package/public/main.js CHANGED
@@ -1 +1 @@
1
- (()=>{var e,r,t={49445:()=>{}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.m=t,o.c=n,o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce((r,t)=>(o.f[t](e,r),r),[])),o.u=e=>e+".js",o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="bt-sensors-plugin-sk:",o.l=(t,n,a,i)=>{if(e[t])e[t].push(n);else{var s,l;if(void 0!==a)for(var u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var p=u[c];if(p.getAttribute("src")==t||p.getAttribute("data-webpack")==r+a){s=p;break}}s||(l=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,o.nc&&s.setAttribute("nonce",o.nc),s.setAttribute("data-webpack",r+a),s.src=t),e[t]=[n];var d=(r,n)=>{s.onerror=s.onload=null,clearTimeout(f);var o=e[t];if(delete e[t],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach(e=>e(n)),r)return r(n)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),l&&document.head.appendChild(s)}},(()=>{o.S={};var e={},r={};o.I=(t,n)=>{n||(n=[]);var a=r[t];if(a||(a=r[t]={}),!(n.indexOf(a)>=0)){if(n.push(a),e[t])return e[t];o.o(o.S,t)||(o.S[t]={});var i=o.S[t],s="bt-sensors-plugin-sk",l=[];return"default"===t&&((e,r,t,n)=>{var a=i[e]=i[e]||{},l=a[r];(!l||!l.loaded&&(1!=!l.eager?n:s>l.from))&&(a[r]={get:()=>o.e(159).then(()=>()=>o(96540)),from:s,eager:!1})})("react","16.14.0"),e[t]=l.length?Promise.all(l).then(()=>e[t]=1):1}}})(),(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var r=o.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={792:0};o.f.j=(r,t)=>{var n=o.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var a=new Promise((t,o)=>n=e[r]=[t,o]);t.push(n[2]=a);var i=o.p+o.u(r),s=new Error;o.l(i,t=>{if(o.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var a=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;s.message="Loading chunk "+r+" failed.\n("+a+": "+i+")",s.name="ChunkLoadError",s.type=a,s.request=i,n[1](s)}},"chunk-"+r,r)}};var r=(r,t)=>{var n,a,[i,s,l]=t,u=0;if(i.some(r=>0!==e[r])){for(n in s)o.o(s,n)&&(o.m[n]=s[n]);l&&l(o)}for(r&&r(t);u<i.length;u++)a=i[u],o.o(e,a)&&e[a]&&e[a][0](),e[a]=0},t=self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})(),o(49445)})();
1
+ (()=>{var e,r,t={49445:()=>{}},n={};function o(e){var r=n[e];if(void 0!==r)return r.exports;var a=n[e]={exports:{}};return t[e](a,a.exports,o),a.exports}o.m=t,o.c=n,o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((r,t)=>(o.f[t](e,r),r)),[])),o.u=e=>e+".js",o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="bt-sensors-plugin-sk:",o.l=(t,n,a,i)=>{if(e[t])e[t].push(n);else{var s,l;if(void 0!==a)for(var u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var p=u[c];if(p.getAttribute("src")==t||p.getAttribute("data-webpack")==r+a){s=p;break}}s||(l=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,o.nc&&s.setAttribute("nonce",o.nc),s.setAttribute("data-webpack",r+a),s.src=t),e[t]=[n];var d=(r,n)=>{s.onerror=s.onload=null,clearTimeout(f);var o=e[t];if(delete e[t],s.parentNode&&s.parentNode.removeChild(s),o&&o.forEach((e=>e(n))),r)return r(n)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),l&&document.head.appendChild(s)}},(()=>{o.S={};var e={},r={};o.I=(t,n)=>{n||(n=[]);var a=r[t];if(a||(a=r[t]={}),!(n.indexOf(a)>=0)){if(n.push(a),e[t])return e[t];o.o(o.S,t)||(o.S[t]={});var i=o.S[t],s="bt-sensors-plugin-sk",l=[];return"default"===t&&((e,r,t,n)=>{var a=i[e]=i[e]||{},l=a[r];(!l||!l.loaded&&(1!=!l.eager?n:s>l.from))&&(a[r]={get:()=>o.e(159).then((()=>()=>o(96540))),from:s,eager:!1})})("react","16.14.0"),e[t]=l.length?Promise.all(l).then((()=>e[t]=1)):1}}})(),(()=>{var e;o.g.importScripts&&(e=o.g.location+"");var r=o.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={792:0};o.f.j=(r,t)=>{var n=o.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var a=new Promise(((t,o)=>n=e[r]=[t,o]));t.push(n[2]=a);var i=o.p+o.u(r),s=new Error;o.l(i,(t=>{if(o.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var a=t&&("load"===t.type?"missing":t.type),i=t&&t.target&&t.target.src;s.message="Loading chunk "+r+" failed.\n("+a+": "+i+")",s.name="ChunkLoadError",s.type=a,s.request=i,n[1](s)}}),"chunk-"+r,r)}};var r=(r,t)=>{var n,a,[i,s,l]=t,u=0;if(i.some((r=>0!==e[r]))){for(n in s)o.o(s,n)&&(o.m[n]=s[n]);l&&l(o)}for(r&&r(t);u<i.length;u++)a=i[u],o.o(e,a)&&e[a]&&e[a][0](),e[a]=0},t=self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})(),o(49445)})();
@@ -1 +1 @@
1
- var bt_sensors_plugin_sk;(()=>{"use strict";var e,r,t,n,o,a,i,u,s,l,f,d,c,p,h,v,g,b,m,y,w,k={43237:(e,r,t)=>{var n={"./PluginConfigurationPanel":()=>Promise.all([t.e(681),t.e(764)]).then(()=>()=>t(62995))},o=(e,r)=>(t.R=r,r=t.o(n,e)?n[e]():Promise.resolve().then(()=>{throw new Error('Module "'+e+'" does not exist in container.')}),t.R=void 0,r),a=(e,r)=>{if(t.S){var n="default",o=t.S[n];if(o&&o!==e)throw new Error("Container initialization failed as it has already been initialized with a different share scope");return t.S[n]=e,t.I(n,r)}};t.d(r,{get:()=>o,init:()=>a})}},S={};function _(e){var r=S[e];if(void 0!==r)return r.exports;var t=S[e]={id:e,loaded:!1,exports:{}};return k[e].call(t.exports,t,t.exports,_),t.loaded=!0,t.exports}_.m=k,_.c=S,_.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return _.d(r,{a:r}),r},_.d=(e,r)=>{for(var t in r)_.o(r,t)&&!_.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},_.f={},_.e=e=>Promise.all(Object.keys(_.f).reduce((r,t)=>(_.f[t](e,r),r),[])),_.u=e=>e+".js",_.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),_.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="bt-sensors-plugin-sk:",_.l=(t,n,o,a)=>{if(e[t])e[t].push(n);else{var i,u;if(void 0!==o)for(var s=document.getElementsByTagName("script"),l=0;l<s.length;l++){var f=s[l];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==r+o){i=f;break}}i||(u=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,_.nc&&i.setAttribute("nonce",_.nc),i.setAttribute("data-webpack",r+o),i.src=t),e[t]=[n];var d=(r,n)=>{i.onerror=i.onload=null,clearTimeout(c);var o=e[t];if(delete e[t],i.parentNode&&i.parentNode.removeChild(i),o&&o.forEach(e=>e(n)),r)return r(n)},c=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),u&&document.head.appendChild(i)}},_.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},_.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),(()=>{_.S={};var e={},r={};_.I=(t,n)=>{n||(n=[]);var o=r[t];if(o||(o=r[t]={}),!(n.indexOf(o)>=0)){if(n.push(o),e[t])return e[t];_.o(_.S,t)||(_.S[t]={});var a=_.S[t],i="bt-sensors-plugin-sk",u=[];return"default"===t&&((e,r,t,n)=>{var o=a[e]=a[e]||{},u=o[r];(!u||!u.loaded&&(1!=!u.eager?n:i>u.from))&&(o[r]={get:()=>_.e(159).then(()=>()=>_(96540)),from:i,eager:!1})})("react","16.14.0"),e[t]=u.length?Promise.all(u).then(()=>e[t]=1):1}}})(),(()=>{var e;_.g.importScripts&&(e=_.g.location+"");var r=_.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),_.p=e})(),t=e=>{var r=e=>e.split(".").map(e=>+e==e?+e:e),t=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(e),n=t[1]?r(t[1]):[];return t[2]&&(n.length++,n.push.apply(n,r(t[2]))),t[3]&&(n.push([]),n.push.apply(n,r(t[3]))),n},n=(e,r)=>{e=t(e),r=t(r);for(var n=0;;){if(n>=e.length)return n<r.length&&"u"!=(typeof r[n])[0];var o=e[n],a=(typeof o)[0];if(n>=r.length)return"u"==a;var i=r[n],u=(typeof i)[0];if(a!=u)return"o"==a&&"n"==u||"s"==u||"u"==a;if("o"!=a&&"u"!=a&&o!=i)return o<i;n++}},o=e=>{var r=e[0],t="";if(1===e.length)return"*";if(r+.5){t+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var n=1,a=1;a<e.length;a++)n--,t+="u"==(typeof(u=e[a]))[0]?"-":(n>0?".":"")+(n=2,u);return t}var i=[];for(a=1;a<e.length;a++){var u=e[a];i.push(0===u?"not("+s()+")":1===u?"("+s()+" || "+s()+")":2===u?i.pop()+" "+i.pop():o(u))}return s();function s(){return i.pop().replace(/^\((.+)\)$/,"$1")}},a=(e,r)=>{if(0 in e){r=t(r);var n=e[0],o=n<0;o&&(n=-n-1);for(var i=0,u=1,s=!0;;u++,i++){var l,f,d=u<e.length?(typeof e[u])[0]:"";if(i>=r.length||"o"==(f=(typeof(l=r[i]))[0]))return!s||("u"==d?u>n&&!o:""==d!=o);if("u"==f){if(!s||"u"!=d)return!1}else if(s)if(d==f)if(u<=n){if(l!=e[u])return!1}else{if(o?l>e[u]:l<e[u])return!1;l!=e[u]&&(s=!1)}else if("s"!=d&&"n"!=d){if(o||u<=n)return!1;s=!1,u--}else{if(u<=n||f<d!=o)return!1;s=!1}else"s"!=d&&"n"!=d&&(s=!1,u--)}}var c=[],p=c.pop.bind(c);for(i=1;i<e.length;i++){var h=e[i];c.push(1==h?p()|p():2==h?p()&p():h?a(h,r):!p())}return!!p()},i=(e,r)=>e&&_.o(e,r),u=e=>(e.loaded=1,e.get()),s=e=>Object.keys(e).reduce((r,t)=>(e[t].eager&&(r[t]=e[t]),r),{}),l=(e,r,t)=>{var o=t?s(e[r]):e[r];return(r=Object.keys(o).reduce((e,r)=>!e||n(e,r)?r:e,0))&&o[r]},f=(e,r,t,o)=>{var i=o?s(e[r]):e[r];return(r=Object.keys(i).reduce((e,r)=>!a(t,r)||e&&!n(e,r)?e:r,0))&&i[r]},d=(e,r,t,n,a)=>{var i=e[t];return"No satisfying version ("+o(n)+")"+(a?" for eager consumption":"")+" of shared module "+t+" found in shared scope "+r+".\nAvailable versions: "+Object.keys(i).map(e=>e+" from "+i[e].from).join(", ")},c=e=>{throw new Error(e)},h=(e,r,t)=>t?t():((e,r)=>c("Shared module "+r+" doesn't exist in shared scope "+e))(e,r),v=(p=e=>function(r,t,n,o,a){var i=_.I(r);return i&&i.then&&!n?i.then(e.bind(e,r,_.S[r],t,!1,o,a)):e(r,_.S[r],t,n,o,a)})((e,r,t,n,o)=>i(r,t)?u(l(r,t,n)):h(e,t,o)),g=p((e,r,t,n,o,a)=>{if(!i(r,t))return h(e,t,a);var s=f(r,t,o,n);return s?u(s):a?a():void c(d(r,e,t,o,n))}),b={},m={21490:()=>g("default","react",!1,[,[1,17,0,0],[1,16,8,0],1],()=>_.e(540).then(()=>()=>_(96540))),42417:()=>g("default","react",!1,[0,16,8,0],()=>_.e(540).then(()=>()=>_(96540))),44167:()=>v("default","react",!1,()=>_.e(540).then(()=>()=>_(96540))),57920:()=>g("default","react",!1,[,[0,17],[1,16,14,0],1],()=>_.e(540).then(()=>()=>_(96540))),61104:()=>g("default","react",!1,[,[1,16,0,0,,0],[1,15,0,0],[2,0,14,0],1,1],()=>_.e(540).then(()=>()=>_(96540))),62085:()=>g("default","react",!1,[1,16,14,0],()=>_.e(540).then(()=>()=>_(96540))),64147:()=>g("default","react",!1,[1,16,13,1],()=>_.e(540).then(()=>()=>_(96540))),87227:()=>g("default","react",!1,[0,16,6,0],()=>_.e(540).then(()=>()=>_(96540))),96932:()=>g("default","react",!1,[0,15,0,0],()=>_.e(540).then(()=>()=>_(96540))),98271:()=>g("default","react",!1,[0,0,14,0],()=>_.e(540).then(()=>()=>_(96540)))},y={764:[21490,42417,44167,57920,61104,62085,64147,87227,96932,98271]},w={},_.f.consumes=(e,r)=>{_.o(y,e)&&y[e].forEach(e=>{if(_.o(b,e))return r.push(b[e]);if(!w[e]){var t=r=>{b[e]=0,_.m[e]=t=>{delete _.c[e],t.exports=r()}};w[e]=!0;var n=r=>{delete b[e],_.m[e]=t=>{throw delete _.c[e],r}};try{var o=m[e]();o.then?r.push(b[e]=o.then(t).catch(n)):t(o)}catch(e){n(e)}}})},(()=>{var e={592:0};_.f.j=(r,t)=>{var n=_.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var o=new Promise((t,o)=>n=e[r]=[t,o]);t.push(n[2]=o);var a=_.p+_.u(r),i=new Error;_.l(a,t=>{if(_.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;i.message="Loading chunk "+r+" failed.\n("+o+": "+a+")",i.name="ChunkLoadError",i.type=o,i.request=a,n[1](i)}},"chunk-"+r,r)}};var r=(r,t)=>{var n,o,[a,i,u]=t,s=0;if(a.some(r=>0!==e[r])){for(n in i)_.o(i,n)&&(_.m[n]=i[n]);u&&u(_)}for(r&&r(t);s<a.length;s++)o=a[s],_.o(e,o)&&e[o]&&e[o][0](),e[o]=0},t=self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})();var j=_(43237);bt_sensors_plugin_sk=j})();
1
+ var bt_sensors_plugin_sk;(()=>{"use strict";var e,r,t,n,o,a,i,u,s,l,f,d,c,p,h,v,g,b,m,y,w,k={43237:(e,r,t)=>{var n={"./PluginConfigurationPanel":()=>Promise.all([t.e(698),t.e(847)]).then((()=>()=>t(62995)))},o=(e,r)=>(t.R=r,r=t.o(n,e)?n[e]():Promise.resolve().then((()=>{throw new Error('Module "'+e+'" does not exist in container.')})),t.R=void 0,r),a=(e,r)=>{if(t.S){var n="default",o=t.S[n];if(o&&o!==e)throw new Error("Container initialization failed as it has already been initialized with a different share scope");return t.S[n]=e,t.I(n,r)}};t.d(r,{get:()=>o,init:()=>a})}},S={};function _(e){var r=S[e];if(void 0!==r)return r.exports;var t=S[e]={id:e,loaded:!1,exports:{}};return k[e].call(t.exports,t,t.exports,_),t.loaded=!0,t.exports}_.m=k,_.c=S,_.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return _.d(r,{a:r}),r},_.d=(e,r)=>{for(var t in r)_.o(r,t)&&!_.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},_.f={},_.e=e=>Promise.all(Object.keys(_.f).reduce(((r,t)=>(_.f[t](e,r),r)),[])),_.u=e=>e+".js",_.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),_.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="bt-sensors-plugin-sk:",_.l=(t,n,o,a)=>{if(e[t])e[t].push(n);else{var i,u;if(void 0!==o)for(var s=document.getElementsByTagName("script"),l=0;l<s.length;l++){var f=s[l];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==r+o){i=f;break}}i||(u=!0,(i=document.createElement("script")).charset="utf-8",i.timeout=120,_.nc&&i.setAttribute("nonce",_.nc),i.setAttribute("data-webpack",r+o),i.src=t),e[t]=[n];var d=(r,n)=>{i.onerror=i.onload=null,clearTimeout(c);var o=e[t];if(delete e[t],i.parentNode&&i.parentNode.removeChild(i),o&&o.forEach((e=>e(n))),r)return r(n)},c=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),u&&document.head.appendChild(i)}},_.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},_.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),(()=>{_.S={};var e={},r={};_.I=(t,n)=>{n||(n=[]);var o=r[t];if(o||(o=r[t]={}),!(n.indexOf(o)>=0)){if(n.push(o),e[t])return e[t];_.o(_.S,t)||(_.S[t]={});var a=_.S[t],i="bt-sensors-plugin-sk",u=[];return"default"===t&&((e,r,t,n)=>{var o=a[e]=a[e]||{},u=o[r];(!u||!u.loaded&&(1!=!u.eager?n:i>u.from))&&(o[r]={get:()=>_.e(159).then((()=>()=>_(96540))),from:i,eager:!1})})("react","16.14.0"),e[t]=u.length?Promise.all(u).then((()=>e[t]=1)):1}}})(),(()=>{var e;_.g.importScripts&&(e=_.g.location+"");var r=_.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var n=t.length-1;n>-1&&(!e||!/^http(s?):/.test(e));)e=t[n--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),_.p=e})(),t=e=>{var r=e=>e.split(".").map((e=>+e==e?+e:e)),t=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(e),n=t[1]?r(t[1]):[];return t[2]&&(n.length++,n.push.apply(n,r(t[2]))),t[3]&&(n.push([]),n.push.apply(n,r(t[3]))),n},n=(e,r)=>{e=t(e),r=t(r);for(var n=0;;){if(n>=e.length)return n<r.length&&"u"!=(typeof r[n])[0];var o=e[n],a=(typeof o)[0];if(n>=r.length)return"u"==a;var i=r[n],u=(typeof i)[0];if(a!=u)return"o"==a&&"n"==u||"s"==u||"u"==a;if("o"!=a&&"u"!=a&&o!=i)return o<i;n++}},o=e=>{var r=e[0],t="";if(1===e.length)return"*";if(r+.5){t+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var n=1,a=1;a<e.length;a++)n--,t+="u"==(typeof(u=e[a]))[0]?"-":(n>0?".":"")+(n=2,u);return t}var i=[];for(a=1;a<e.length;a++){var u=e[a];i.push(0===u?"not("+s()+")":1===u?"("+s()+" || "+s()+")":2===u?i.pop()+" "+i.pop():o(u))}return s();function s(){return i.pop().replace(/^\((.+)\)$/,"$1")}},a=(e,r)=>{if(0 in e){r=t(r);var n=e[0],o=n<0;o&&(n=-n-1);for(var i=0,u=1,s=!0;;u++,i++){var l,f,d=u<e.length?(typeof e[u])[0]:"";if(i>=r.length||"o"==(f=(typeof(l=r[i]))[0]))return!s||("u"==d?u>n&&!o:""==d!=o);if("u"==f){if(!s||"u"!=d)return!1}else if(s)if(d==f)if(u<=n){if(l!=e[u])return!1}else{if(o?l>e[u]:l<e[u])return!1;l!=e[u]&&(s=!1)}else if("s"!=d&&"n"!=d){if(o||u<=n)return!1;s=!1,u--}else{if(u<=n||f<d!=o)return!1;s=!1}else"s"!=d&&"n"!=d&&(s=!1,u--)}}var c=[],p=c.pop.bind(c);for(i=1;i<e.length;i++){var h=e[i];c.push(1==h?p()|p():2==h?p()&p():h?a(h,r):!p())}return!!p()},i=(e,r)=>e&&_.o(e,r),u=e=>(e.loaded=1,e.get()),s=e=>Object.keys(e).reduce(((r,t)=>(e[t].eager&&(r[t]=e[t]),r)),{}),l=(e,r,t)=>{var o=t?s(e[r]):e[r];return(r=Object.keys(o).reduce(((e,r)=>!e||n(e,r)?r:e),0))&&o[r]},f=(e,r,t,o)=>{var i=o?s(e[r]):e[r];return(r=Object.keys(i).reduce(((e,r)=>!a(t,r)||e&&!n(e,r)?e:r),0))&&i[r]},d=(e,r,t,n,a)=>{var i=e[t];return"No satisfying version ("+o(n)+")"+(a?" for eager consumption":"")+" of shared module "+t+" found in shared scope "+r+".\nAvailable versions: "+Object.keys(i).map((e=>e+" from "+i[e].from)).join(", ")},c=e=>{throw new Error(e)},h=(e,r,t)=>t?t():((e,r)=>c("Shared module "+r+" doesn't exist in shared scope "+e))(e,r),v=(p=e=>function(r,t,n,o,a){var i=_.I(r);return i&&i.then&&!n?i.then(e.bind(e,r,_.S[r],t,!1,o,a)):e(r,_.S[r],t,n,o,a)})(((e,r,t,n,o)=>i(r,t)?u(l(r,t,n)):h(e,t,o))),g=p(((e,r,t,n,o,a)=>{if(!i(r,t))return h(e,t,a);var s=f(r,t,o,n);return s?u(s):a?a():void c(d(r,e,t,o,n))})),b={},m={21490:()=>g("default","react",!1,[,[1,17,0,0],[1,16,8,0],1],(()=>_.e(540).then((()=>()=>_(96540))))),42417:()=>g("default","react",!1,[0,16,8,0],(()=>_.e(540).then((()=>()=>_(96540))))),44167:()=>v("default","react",!1,(()=>_.e(540).then((()=>()=>_(96540))))),57920:()=>g("default","react",!1,[,[0,17],[1,16,14,0],1],(()=>_.e(540).then((()=>()=>_(96540))))),61104:()=>g("default","react",!1,[,[1,16,0,0,,0],[1,15,0,0],[2,0,14,0],1,1],(()=>_.e(540).then((()=>()=>_(96540))))),62085:()=>g("default","react",!1,[1,16,14,0],(()=>_.e(540).then((()=>()=>_(96540))))),86528:()=>g("default","react",!1,[1,16,13,1],(()=>_.e(540).then((()=>()=>_(96540))))),87227:()=>g("default","react",!1,[0,16,6,0],(()=>_.e(540).then((()=>()=>_(96540))))),96932:()=>g("default","react",!1,[0,15,0,0],(()=>_.e(540).then((()=>()=>_(96540))))),98271:()=>g("default","react",!1,[0,0,14,0],(()=>_.e(540).then((()=>()=>_(96540)))))},y={847:[21490,42417,44167,57920,61104,62085,86528,87227,96932,98271]},w={},_.f.consumes=(e,r)=>{_.o(y,e)&&y[e].forEach((e=>{if(_.o(b,e))return r.push(b[e]);if(!w[e]){var t=r=>{b[e]=0,_.m[e]=t=>{delete _.c[e],t.exports=r()}};w[e]=!0;var n=r=>{delete b[e],_.m[e]=t=>{throw delete _.c[e],r}};try{var o=m[e]();o.then?r.push(b[e]=o.then(t).catch(n)):t(o)}catch(e){n(e)}}}))},(()=>{var e={592:0};_.f.j=(r,t)=>{var n=_.o(e,r)?e[r]:void 0;if(0!==n)if(n)t.push(n[2]);else{var o=new Promise(((t,o)=>n=e[r]=[t,o]));t.push(n[2]=o);var a=_.p+_.u(r),i=new Error;_.l(a,(t=>{if(_.o(e,r)&&(0!==(n=e[r])&&(e[r]=void 0),n)){var o=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;i.message="Loading chunk "+r+" failed.\n("+o+": "+a+")",i.name="ChunkLoadError",i.type=o,i.request=a,n[1](i)}}),"chunk-"+r,r)}};var r=(r,t)=>{var n,o,[a,i,u]=t,s=0;if(a.some((r=>0!==e[r]))){for(n in i)_.o(i,n)&&(_.m[n]=i[n]);u&&u(_)}for(r&&r(t);s<a.length;s++)o=a[s],_.o(e,o)&&e[o]&&e[o][0](),e[o]=0},t=self.webpackChunkbt_sensors_plugin_sk=self.webpackChunkbt_sensors_plugin_sk||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})();var j=_(43237);bt_sensors_plugin_sk=j})();
@@ -0,0 +1,160 @@
1
+ const BTSensor = require("../BTSensor");
2
+ ({FakeDevice,FakeGATTService,FakeGATTCharacteristic }=require( "../development/FakeBTDevice.js"))
3
+ //a1000000650000000000180103440018004800640531ff8000002710000100010000000000000000000100020000ffff00000000000000000000000000000000000000000000000000000000000000000000418b
4
+ //a20000006500000000001801035600040cfb0cfd0cfb0cfaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000300cd00c000befc18fc18fc18fc18fc18fc18976a
5
+
6
+ /*
7
+ BMSdp("battery_level", 16, 2, False, lambda x: x, 0xA1),
8
+ BMSdp("voltage", 20, 2, False, lambda x: x / 100, 0xA1),
9
+ BMSdp("current", 22, 2, True, lambda x: x / 100, 0xA1),
10
+ BMSdp("problem_code", 51, 2, False, lambda x: x, 0xA1),
11
+ BMSdp("design_capacity", 26, 2, False, lambda x: x // 100, 0xA1),
12
+ BMSdp("cell_count", _CELL_POS, 2, False, lambda x: x, 0xA2),
13
+ BMSdp("temp_sensors", _TEMP_POS, 2, False, lambda x: x, 0xA2),
14
+ # ("cycles", 0xA1, 8, 2, False, lambda x: x),
15
+ */
16
+
17
+ function waitForVariable(obj, variableName, interval = 100) {
18
+ return new Promise((resolve) => {
19
+ if (obj[variableName] !== undefined) {
20
+ return resolve(obj[variableName]);
21
+ }
22
+
23
+ const intervalId = setInterval(() => {
24
+ if (obj[variableName] !== undefined) {
25
+ clearInterval(intervalId);
26
+ resolve(obj[variableName]);
27
+ }
28
+ }, interval);
29
+ });
30
+ }
31
+
32
+ class EcoWorthy extends BTSensor {
33
+ static Domain = BTSensor.SensorDomains.electrical
34
+
35
+ static TX_RX_SERVICE = "0000fff0-0000-1000-8000-00805f9b34fb"
36
+ static NOTIFY_CHAR_UUID = "0000fff1-0000-1000-8000-00805f9b34fb"
37
+
38
+ static async test(data=["a1000000650000000000180103440018004800640531ff8000002710000100010000000000000000000100020000ffff00000000000000000000000000000000000000000000000000000000000000000000418b",
39
+ "a20000006500000000001801035600040cfb0cfd0cfb0cfaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000300cd00c000befc18fc18fc18fc18fc18fc18976a"
40
+ ]){
41
+ const device = new FakeDevice(
42
+ [new FakeGATTService("0000fff0-0000-1000-8000-00805f9b34fb",
43
+ [new FakeGATTCharacteristic("0000fff1-0000-1000-8000-00805f9b34fb",
44
+ data
45
+ )]
46
+ )]
47
+ )
48
+ const obj = new EcoWorthy(device)
49
+ obj.currentProperties={Name:"Fake EcoWorthy", Address:"<mac>"}
50
+ obj.debug=(m)=>{console.log(m)}
51
+ obj.deviceConnect=()=>{}
52
+ await obj.initSchema()
53
+ for (const [tag,path] of Object.entries(obj._schema.properties.paths.properties)) {
54
+ obj.on(tag, val=>{console.log(`${tag} => ${val} `)})
55
+ }
56
+
57
+ }
58
+
59
+ static identify(device){
60
+ return null
61
+ }
62
+ static ImageFile = "EcoWorthy.webp"
63
+
64
+
65
+ async initSchema(){
66
+ super.initSchema()
67
+ this.addDefaultParam("batteryID")
68
+
69
+ this.addDefaultPath('voltage','electrical.batteries.voltage')
70
+ .read=
71
+ (buffer)=>{return buffer.readUInt16BE(20) / 100}
72
+
73
+ this.addDefaultPath('current','electrical.batteries.current')
74
+ .read=
75
+ (buffer)=>{return buffer.readInt16BE(22) / 100}
76
+
77
+ this.addDefaultPath('remainingCapacity','electrical.batteries.capacity.remaining')
78
+ //.read=(buffer)=>{return (buffer.readUInt16BE(8) / 100)*3600}
79
+
80
+ this.addDefaultPath('capacity','electrical.batteries.capacity.actual')
81
+ .read=(buffer)=>{return (buffer.readUInt16BE(26) / 100)*3600}
82
+
83
+ this.addDefaultPath('SOC','electrical.batteries.capacity.stateOfCharge')
84
+ .read=(buffer)=>{return buffer.readUInt16BE(16)/100}
85
+
86
+ await this._initGATTConnection()
87
+ await this._initGATTNotifications()
88
+ await waitForVariable(this,"numberOfTemps")
89
+ await waitForVariable(this,"numberOfCells")
90
+
91
+ for (let i=0; i<this.numberOfTemps; i++){
92
+ this.addMetadatum(`temp${i}`, 'K', `Temperature${i+1} reading`,
93
+ (buffer)=>{
94
+ return buffer.readUInt16BE(82+(i*2))/10
95
+ })
96
+ .default=`electrical.batteries.{batteryID}.Temperature${i+1}`
97
+ }
98
+
99
+ for (let i=0; i<this.numberOfCells; i++){
100
+ this.addMetadatum(`cell${i}Voltage`, 'V', `Cell ${i+1} voltage`,
101
+ (buffer)=>{return buffer.readUInt16BE((16+(i*2)))/1000} )
102
+ .default=`electrical.batteries.{batteryID}.cell${i+1}.voltage`
103
+ }
104
+ }
105
+
106
+ hasGATT(){
107
+ return true
108
+ }
109
+
110
+ async _initGATTNotifications(){
111
+ await this.rxChar.startNotifications()
112
+
113
+ this.rxChar.on("valuechanged", (buffer)=>{
114
+ if (buffer[0]==0xA1){
115
+ (["current", "voltage", "remainingCapacity", "capacity", "SOC" ]).forEach((tag) =>
116
+ this.emitData( tag, buffer )
117
+ )
118
+ } else
119
+ if (buffer[0]==0xA2){
120
+
121
+ if (!this.numberOfCells){
122
+ this.numberOfCells=buffer[15]
123
+ }
124
+ if (!this.numberOfTemps){
125
+ this.numberOfTemps=buffer[81]
126
+ }
127
+ for (let i=0;i<this.numberOfCells;i++){
128
+ this.emitData(`cell${i+1}Voltage`, buffer)
129
+ }
130
+ for (let i=0;i<this.numberOfTemps;i++){
131
+ this.emitData(`temp${i+1}`, buffer)
132
+
133
+ }
134
+ }
135
+ })
136
+ }
137
+ async _initGATTConnection() {
138
+ await this.deviceConnect()
139
+ const gattServer = await this.device.gatt()
140
+ const txRxService= await gattServer.getPrimaryService(this.constructor.TX_RX_SERVICE)
141
+ this.rxChar = await txRxService.getCharacteristic(this.constructor.NOTIFY_CHAR_UUID)
142
+ return this
143
+ }
144
+
145
+ async init(){
146
+
147
+ return await super.init()
148
+
149
+ }
150
+
151
+ async stopListening(){
152
+ super.stopListening()
153
+ if (this.rxChar)
154
+ this.rxChar.stopNotifications()
155
+ if (this.device)
156
+ await this.device.disconnect()
157
+ }
158
+
159
+ }
160
+ module.exports = EcoWorthy;
@@ -1,4 +1,3 @@
1
- const { delimiter } = require("node:path");
2
1
  const BTSensor = require("../BTSensor");
3
2
  const EventEmitter = require('node:events');
4
3
 
@@ -261,7 +261,7 @@ class GobiusCTankMeter extends BTSensor{
261
261
  else
262
262
  return null
263
263
  }
264
- static ImageFile = "GobiusCTankMeter.jpg"
264
+ static ImageFile = "GobiusCTankMeter.png"
265
265
 
266
266
  hasGATT(){
267
267
  return true
@@ -185,8 +185,8 @@ class VictronBatteryMonitor extends VictronSensor{
185
185
  const datum = this.getPaths()[tag]
186
186
  if (datum.gatt) {
187
187
  this.gattService.getCharacteristic(datum.gatt).then(async (gattCharacteristic)=>{
188
- const buffer = await gattCharacteristic.readValue()
189
- this.emitData(tag, buffer)
188
+ //const buffer = await gattCharacteristic.readValue()
189
+ //this.emitData(tag, buffer)
190
190
 
191
191
  gattCharacteristic.startNotifications().then(()=>{
192
192
  gattCharacteristic.on('valuechanged', buffer => {
@@ -4,7 +4,7 @@ import ReactHtmlParser from 'react-html-parser';
4
4
  import React from 'react'
5
5
  import {useEffect, useState} from 'react'
6
6
 
7
- import {Button, Grid } from '@material-ui/core';
7
+ import {Button, Grid, Snackbar } from '@material-ui/core';
8
8
  import { makeStyles } from '@material-ui/core/styles';
9
9
 
10
10
  import { SignalCellular0Bar, SignalCellular1Bar, SignalCellular2Bar, SignalCellular3Bar, SignalCellular4Bar, SignalCellularConnectedNoInternet0Bar } from '@material-ui/icons';
@@ -73,6 +73,9 @@ const useStyles = makeStyles((theme) => ({
73
73
  const [ uiSchema, setUISchema] = useState(_uiSchema )
74
74
 
75
75
  const [sensorData, setSensorData] = useState()
76
+ const [sensorClassChanged, setSensorClassChanged] = useState(false)
77
+
78
+ const [enableSchema, setEnableSchema] = useState(true)
76
79
  const [sensorMap, setSensorMap ] = useState(new Map())
77
80
 
78
81
  const [progress, setProgress ] = useState({
@@ -83,8 +86,11 @@ const useStyles = makeStyles((theme) => ({
83
86
 
84
87
  const [pluginState, setPluginState ] = useState("unknown")
85
88
  const [error, setError ] = useState()
89
+ const [snackbarOpen, setSnackbarOpen] = useState(false)
90
+ const [snackbarMessage, setSnackbarMessage] = useState("")
86
91
  const classes = useStyles();
87
92
 
93
+
88
94
 
89
95
  function sendJSONData(cmd, data){
90
96
 
@@ -129,8 +135,10 @@ async function fetchJSONData(path, data = {}) {
129
135
 
130
136
 
131
137
  async function getSensorInfo(mac, sensorClass){
138
+
132
139
  const response = await fetchJSONData("getSensorInfo",{mac_address: mac, class: sensorClass})
133
140
  if (response.status!=200){
141
+ debugger
134
142
  throw new Error(`Unable get sensor info: ${response.statusText} (${response.status}) `)
135
143
  }
136
144
  const json = await response.json()
@@ -185,7 +193,7 @@ async function fetchJSONData(path, data = {}) {
185
193
  setSensorMap((sm)=>{sm.delete(mac); return new Map(sm) })
186
194
  setSchema( {} )
187
195
  } catch {(e)=>
188
- setError( new Error(`Couldn't remove ${mac}: ${e}`))
196
+ setError( `Couldn't remove ${mac}: ${e}`)
189
197
  }
190
198
 
191
199
  }
@@ -196,14 +204,11 @@ async function fetchJSONData(path, data = {}) {
196
204
  //setSensorList({})
197
205
  sendJSONData("updateBaseData", data).then( (response )=>{
198
206
  if (response.status != 200) {
199
- setError(new Error(`Unable to update base data: ${response.statusText} (${response.status})`))
207
+ setError(`Unable to update base data: ${response.statusText} (${response.status})`)
200
208
  }
201
209
  })
202
210
 
203
211
  }
204
-
205
-
206
-
207
212
 
208
213
  useEffect(()=>{
209
214
  let eventSource=null
@@ -267,7 +272,7 @@ async function fetchJSONData(path, data = {}) {
267
272
 
268
273
  })
269
274
  .catch( (e) => {
270
- setError(e)
275
+ setError(e.message)
271
276
  }
272
277
  )
273
278
  return () => {
@@ -280,23 +285,39 @@ async function fetchJSONData(path, data = {}) {
280
285
 
281
286
  useEffect(()=>{
282
287
 
288
+ if (!sensorClassChanged) return
283
289
  if (!(sensorData && sensorMap) ) return
284
290
 
285
291
  const _sensor = sensorMap.get(sensorData.mac_address)
286
292
  if (_sensor && schema && sensorData &&
287
293
  Object.hasOwn(sensorData,"params" )){
288
-
289
294
  if (_sensor.info.class == "UNKNOWN" && sensorData.params.sensorClass && sensorData.params.sensorClass != "UNKNOWN") {
295
+ setEnableSchema(false)
296
+ setSnackbarMessage(`Please wait. Fetching schema for ${sensorData.params.sensorClass}...`)
290
297
  getSensorInfo(sensorData.mac_address, sensorData.params.sensorClass).then((json)=>{
291
- debugger
292
298
  setSchema(json.schema)
299
+ }).catch((e)=>{
300
+ alert(e.message)
301
+ })
302
+ .finally(()=>{
303
+ setSnackbarMessage("")
304
+ setEnableSchema(true)
305
+ setSensorClassChanged(false)
293
306
  })
294
307
  }
295
308
 
296
309
  }
297
310
 
298
- },[sensorData])
311
+ },[sensorClassChanged])
299
312
 
313
+ useEffect(()=>{
314
+ if (snackbarMessage=="")
315
+ setSnackbarOpen(false)
316
+ else {
317
+ setSnackbarOpen(true)
318
+ }
319
+
320
+ },[snackbarMessage])
300
321
 
301
322
  useEffect(()=>{
302
323
  if (pluginState=="started") {
@@ -304,13 +325,13 @@ useEffect(()=>{
304
325
  setBaseSchema(json.schema);
305
326
  setBaseData(json.data);
306
327
  }).catch((e)=>{
307
- setError(e)
328
+ setError(e.message)
308
329
  })
309
330
 
310
331
  getProgress().then((json)=>{
311
332
  setProgress(json)
312
333
  }).catch((e)=>{
313
- setError(e)
334
+ setError(e.message)
314
335
  })
315
336
 
316
337
  } else{
@@ -428,6 +449,14 @@ function devicesInDomain(domain){
428
449
  return(
429
450
 
430
451
  <div>
452
+
453
+ <Snackbar
454
+ anchorOrigin={{ horizontal: 'center', vertical: 'bottom' }}
455
+ onClose={() => setSnackbarOpen(false)}
456
+ open={snackbarOpen}
457
+ message={snackbarMessage}
458
+ key={"snackbar"}
459
+ />
431
460
  <div className={classes.root}>
432
461
 
433
462
  <Button variant="contained" onClick={()=>{openInNewTab("https://github.com/naugehyde/bt-sensors-plugin-sk/tree/1.2.0-beta#configuration")}}>Documentation</Button>
@@ -438,7 +467,7 @@ function devicesInDomain(domain){
438
467
  </div>
439
468
  <hr style={{"width":"100%","height":"1px","color":"gray","background-color":"gray","text-align":"left","margin-left":0}}></hr>
440
469
 
441
- {error?<h2 style="color: red;">{error}</h2>:""}
470
+ {error?<h2 style={{color: 'red'}}>{error}</h2>:""}
442
471
  <Form
443
472
  schema={baseSchema}
444
473
  validator={validator}
@@ -471,18 +500,23 @@ function devicesInDomain(domain){
471
500
  <Grid item><h2>{schema?.title}</h2><p></p></Grid>
472
501
  <Grid item>{ReactHtmlParser(schema?.htmlDescription)}</Grid>
473
502
  </Grid>
474
-
503
+ <fieldset disabled={!enableSchema}>
475
504
  <Form
476
505
  schema={schema}
477
506
  validator={validator}
478
507
  uiSchema={uiSchema}
479
- onChange={(e) => {
508
+ onChange={(e,id) => {
480
509
  const s = sensorMap.get(e.formData.mac_address)
481
510
  if(s) {
482
511
  s._changesMade=true
483
512
  s.config = e.formData
484
513
  setSensorData(e.formData)
485
514
  }
515
+
516
+ if (id=="root_params_sensorClass") {
517
+ setSensorClassChanged(true)
518
+ }
519
+
486
520
  }
487
521
  }
488
522
  onSubmit={({ formData }, e) => {
@@ -497,7 +531,7 @@ function devicesInDomain(domain){
497
531
  <Button variant="contained" color="secondary" onClick={(e)=>confirmDelete(sensorData.mac_address)}>Delete</Button>
498
532
  </div>
499
533
  </Form>
500
-
534
+ </fieldset>
501
535
 
502
536
  </div>
503
537
  </div>