bt-sensors-plugin-sk 1.2.4-4 → 1.2.5
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/README.md +14 -7
- package/bt-sensors-plugin-sk copy.json +170 -0
- package/index.js +26 -7
- package/package.json +1 -1
- package/public/847.js +1 -1
- package/sensor_classes/MopekaTankSensor.js +1 -1
- package/src/components/PluginConfigurationPanel.js +10 -4
package/README.md
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
# Bluetooth Sensors for [Signal K](http://www.signalk.org)
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## WHAT'S NEW
|
|
4
|
+
|
|
5
|
+
# Version 1.2.5
|
|
6
|
+
|
|
7
|
+
- On initial startup, plugin saves default configuration. Fixing the "missing" configured devices after restart.
|
|
8
|
+
- Mopeka Tank Sensor configuration fix
|
|
9
|
+
- Added number of found devices in a domain in the configuration screen's domain tab
|
|
10
|
+
|
|
11
|
+
## IMPORTANT NOTE TO NEW USERS OF VERSIONS OLDER THAN 1.2.5
|
|
4
12
|
|
|
5
13
|
There's a known issue with saving the configuration after initial installation owing to current ServerAPI limitations.
|
|
6
14
|
|
|
7
15
|
Your device config after you've saved it will appear to be "missing" after restarting. It's in fact saved in the plugin config directory. All you have to do is Submit the main configuration then enable and optionally disable Debug. This, believe it or not, ensures that the config is marked as enabled. You should see your data now and upon restart.
|
|
8
16
|
|
|
9
|
-
## WHAT'S NEW
|
|
10
|
-
|
|
11
17
|
# Version 1.2.4-4
|
|
12
18
|
|
|
13
19
|
Junctek support (tested)
|
|
@@ -174,10 +180,6 @@ Finally, restart SK. Plugin should appear in your server plugins list.<br>
|
|
|
174
180
|
|
|
175
181
|
## KNOWN ISSUES
|
|
176
182
|
|
|
177
|
-
### Problems saving the configuration after installing plugin for first time
|
|
178
|
-
|
|
179
|
-
Your device config after you've saved it will appear to be "missing" after restarting. It's in fact saved in the plugin config directory. All you have to do is Submit the main configuration then enable and optionally disable Debug. This, believe it or not, ensures that the config is marked as enabled. You should see your data now and upon restart.
|
|
180
|
-
|
|
181
183
|
### Connected Devices on Raspberry Pi platform (4/4b/5/CM400/CM500)
|
|
182
184
|
|
|
183
185
|
Onboard Raspberry Pi WiFi can cause interference with the onboard Bluetooth resulting in lost connections to GATT connected devices (Renogy, JBD, etc. )
|
|
@@ -200,6 +202,11 @@ Poorly shielded USB 3.0 and HDMI (5ghz) can interfere with BT transmission (2.4g
|
|
|
200
202
|
- There's no way that I know of to remove a SK Path without restarting the server. So if any active paths are changed by the plugin, you'll still see them hanging around in the data browser growing stale until you restart the server.
|
|
201
203
|
- RPi 3/4/5/CM400s when running an Access Point on the on board Wifi can cause a problem connecting to devices through the onboard BT. The only known fix is to disable the onboard Bluetooth and use a USB BT adapter. Alternatively, you can use a USB WiFi adapter. NOTE: This only applies to _connected_ devices like Renogy devices, LiTime batteries etc.
|
|
202
204
|
|
|
205
|
+
### Problems saving the configuration after installing plugin for first time (fixed as of Version 1.2.5)
|
|
206
|
+
|
|
207
|
+
Device config after being saved will appear to be "missing" after restarting. The config is in fact saved in the plugin config directory. All you have to do is Submit the main configuration then enable and optionally disable Debug. This, believe it or not, ensures that the config is marked as enabled. You should see your data now and upon restart.
|
|
208
|
+
|
|
209
|
+
|
|
203
210
|
## CONFIGURATION
|
|
204
211
|
|
|
205
212
|
After installing and restarting Signalk you should see a "BT Sensors Plugin" option in the Signalk->Server->Plugin Config page.<br><br>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{
|
|
2
|
+
"configuration": {
|
|
3
|
+
"discoveryInterval": 10,
|
|
4
|
+
"peripherals": [
|
|
5
|
+
{
|
|
6
|
+
"active": true,
|
|
7
|
+
"discoveryTimeout": 30,
|
|
8
|
+
"params": {
|
|
9
|
+
"name": "ATC_9FF77E",
|
|
10
|
+
"zone": "inside.cabin",
|
|
11
|
+
"parser": "ATC-LE",
|
|
12
|
+
"sensorClass": "ATC"
|
|
13
|
+
},
|
|
14
|
+
"paths": {
|
|
15
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
16
|
+
"batteryStrength": "sensors.{macAndName}.battery.strength",
|
|
17
|
+
"voltage": "sensors.{macAndName}.battery.voltage",
|
|
18
|
+
"temp": "environment.{zone}.temperature",
|
|
19
|
+
"humidity": "environment.{zone}.humidity"
|
|
20
|
+
},
|
|
21
|
+
"mac_address": "A4:C1:38:9F:F7:7E"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"active": true,
|
|
25
|
+
"discoveryTimeout": 30,
|
|
26
|
+
"params": {
|
|
27
|
+
"name": "tps",
|
|
28
|
+
"zone": "inside.refrigerator",
|
|
29
|
+
"sensorClass": "Inkbird"
|
|
30
|
+
},
|
|
31
|
+
"paths": {
|
|
32
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
33
|
+
"temp": "environment.{zone}.temperature",
|
|
34
|
+
"battery": "sensors.{macAndName}.battery.strength"
|
|
35
|
+
},
|
|
36
|
+
"mac_address": "49:22:05:17:2B:AE"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"active": true,
|
|
40
|
+
"discoveryTimeout": 30,
|
|
41
|
+
"params": {
|
|
42
|
+
"name": "Ruuvi BC7E",
|
|
43
|
+
"zone": "inside.navdesk",
|
|
44
|
+
"sensorClass": "RuuviTag"
|
|
45
|
+
},
|
|
46
|
+
"paths": {
|
|
47
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
48
|
+
"temp": "environment.{zone}.temperature",
|
|
49
|
+
"humidity": "environment.{zone}.humidity",
|
|
50
|
+
"pressure": "environment.{zone}.pressure",
|
|
51
|
+
"accX": "sensors.{macAndName}.accX",
|
|
52
|
+
"accY": "sensors.{macAndName}.accY",
|
|
53
|
+
"accZ": "sensors.{macAndName}.accZ",
|
|
54
|
+
"battV": "sensors.{macAndName}.battery.voltage",
|
|
55
|
+
"mc": "sensors.{macAndName}.movementCounter",
|
|
56
|
+
"msc": "sensors.{macAndName}.measurementSequenceCounter"
|
|
57
|
+
},
|
|
58
|
+
"mac_address": "F9:B0:6E:63:BC:7E"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"active": true,
|
|
62
|
+
"discoveryTimeout": 30,
|
|
63
|
+
"params": {
|
|
64
|
+
"name": "SBMO-003Z-db1b",
|
|
65
|
+
"zone": "inside",
|
|
66
|
+
"sensorClass": "ShellySBMO003Z"
|
|
67
|
+
},
|
|
68
|
+
"paths": {
|
|
69
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
70
|
+
"motion": "environment.{zone}.motion",
|
|
71
|
+
"illuminance": "environment.{zone}.illuminance",
|
|
72
|
+
"battery": "sensors.{macAndName}.battery.strength",
|
|
73
|
+
"button": "sensors.{macAndName}.button"
|
|
74
|
+
},
|
|
75
|
+
"mac_address": "E8:E0:7E:97:DB:1B"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"active": true,
|
|
79
|
+
"discoveryTimeout": 30,
|
|
80
|
+
"params": {
|
|
81
|
+
"name": "LYWSD03MMC",
|
|
82
|
+
"zone": "inside.vberth",
|
|
83
|
+
"encryptionKey": "3985f4ebc032f276cc316f1f6ecea085",
|
|
84
|
+
"sensorClass": "XiaomiMiBeacon"
|
|
85
|
+
},
|
|
86
|
+
"paths": {
|
|
87
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
88
|
+
"temp": "environment.{zone}.temperature",
|
|
89
|
+
"humidity": "environment.{zone}.humidity",
|
|
90
|
+
"batteryStrength": "sensors.{macAndName}.battery.strength",
|
|
91
|
+
"voltage": "sensors.{macAndName}.battery.voltage"
|
|
92
|
+
},
|
|
93
|
+
"gattParams": {
|
|
94
|
+
"useGATT": false
|
|
95
|
+
},
|
|
96
|
+
"mac_address": "A4:C1:38:3E:7E:94"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"active": true,
|
|
100
|
+
"discoveryTimeout": 30,
|
|
101
|
+
"params": {
|
|
102
|
+
"name": "SmartShunt HQ2204C2GHD",
|
|
103
|
+
"batteryID": "house",
|
|
104
|
+
"encryptionKey": "8cce8529307cf9dd0c85611c4fef42d9",
|
|
105
|
+
"sensorClass": "VictronBatteryMonitor"
|
|
106
|
+
},
|
|
107
|
+
"paths": {
|
|
108
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
109
|
+
"current": "electrical.batteries.{batteryID}.current",
|
|
110
|
+
"power": "electrical.batteries.{batteryID}.power",
|
|
111
|
+
"voltage": "electrical.batteries.{batteryID}.voltage",
|
|
112
|
+
"alarm": "electrical.batteries.{batteryID}.alarm",
|
|
113
|
+
"consumed": "electrical.batteries.{batteryID}.capacity.ampHoursConsumed",
|
|
114
|
+
"soc": "electrical.batteries.{batteryID}.capacity.stateOfCharge",
|
|
115
|
+
"ttg": "electrical.batteries.{batteryID}.capacity.timeRemaining",
|
|
116
|
+
"starterVoltage": "electrical.batteries.secondary.voltage"
|
|
117
|
+
},
|
|
118
|
+
"gattParams": {
|
|
119
|
+
"useGATT": false
|
|
120
|
+
},
|
|
121
|
+
"mac_address": "D4:50:46:39:38:C5"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"active": true,
|
|
125
|
+
"discoveryTimeout": 90,
|
|
126
|
+
"params": {
|
|
127
|
+
"name": "aft propane tank",
|
|
128
|
+
"medium": "PROPANE",
|
|
129
|
+
"tankHeight": "325",
|
|
130
|
+
"id": "propane",
|
|
131
|
+
"sensorClass": "MopekaTankSensor"
|
|
132
|
+
},
|
|
133
|
+
"paths": {
|
|
134
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
135
|
+
"battVolt": "sensors.{macAndName}.battery.voltage",
|
|
136
|
+
"battStrength": "sensors.{macAndName}.battery.strength",
|
|
137
|
+
"temp": "tanks.{id}.temperature",
|
|
138
|
+
"tankLevel": "tanks.{id}.currentLevel",
|
|
139
|
+
"readingQuality": "sensors.{macAndName}.readingQuality",
|
|
140
|
+
"accX": "sensors.{macAndName}.accelerationXAxis",
|
|
141
|
+
"accY": "sensors.{macAndName}.accelerationYAxis"
|
|
142
|
+
},
|
|
143
|
+
"mac_address": "D4:40:59:BE:2A:8C"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"active": true,
|
|
147
|
+
"discoveryTimeout": 30,
|
|
148
|
+
"params": {
|
|
149
|
+
"name": "SBHT-003C",
|
|
150
|
+
"zone": "outside.deck",
|
|
151
|
+
"sensorClass": "ShellySBHT003C"
|
|
152
|
+
},
|
|
153
|
+
"paths": {
|
|
154
|
+
"RSSI": "sensors.{macAndName}.RSSI",
|
|
155
|
+
"battery": "sensors.{macAndName}.battery.strength",
|
|
156
|
+
"temp": "environment.{zone}.temperature",
|
|
157
|
+
"humidity": "environment.{zone}.humidity",
|
|
158
|
+
"button": "sensors.{macAndName}.button"
|
|
159
|
+
},
|
|
160
|
+
"mac_address": "7C:C6:B6:AF:49:5F"
|
|
161
|
+
}
|
|
162
|
+
],
|
|
163
|
+
"adapter": "hci0",
|
|
164
|
+
"transport": "le",
|
|
165
|
+
"duplicateData": false,
|
|
166
|
+
"discoveryTimeout": 30
|
|
167
|
+
},
|
|
168
|
+
"enabled": true,
|
|
169
|
+
"enableDebug": false
|
|
170
|
+
}
|
package/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const packageInfo = require("./package.json")
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
const {createBluetooth} = require('node-ble')
|
|
4
5
|
const {Variant} = require('dbus-next')
|
|
5
6
|
const {bluetooth, destroy} = createBluetooth()
|
|
@@ -138,6 +139,21 @@ module.exports = function (app) {
|
|
|
138
139
|
var adapterID=options.adapter
|
|
139
140
|
var foundConfiguredDevices=0
|
|
140
141
|
|
|
142
|
+
if (Object.keys(options).length==0){ //empty config means initial startup. save defaults and enabled=true.
|
|
143
|
+
let json = {configuration:{adapter:"hci0", transport:"le", discoveryTimeout:30, discoveryInterval:10}, enabled:true, enableDebug:false}
|
|
144
|
+
let appDataDirPath = app.getDataDirPath()
|
|
145
|
+
let jsonFile = appDataDirPath+'.json'
|
|
146
|
+
const fs = require("node:fs")
|
|
147
|
+
try {
|
|
148
|
+
fs.writeFileSync(jsonFile, JSON.stringify(json, null,2))
|
|
149
|
+
options=json
|
|
150
|
+
} catch(err){
|
|
151
|
+
console.log(`Error writing initial config: ${err.message} `)
|
|
152
|
+
console.log(err)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
141
157
|
plugin.registerWithRouter = function(router) {
|
|
142
158
|
|
|
143
159
|
router.post('/updateSensorData', async (req, res) => {
|
|
@@ -154,6 +170,7 @@ module.exports = function (app) {
|
|
|
154
170
|
} else {
|
|
155
171
|
options.peripherals[i] = req.body
|
|
156
172
|
}
|
|
173
|
+
deviceConfigs=options.peripherals
|
|
157
174
|
app.savePluginOptions(
|
|
158
175
|
options, async () => {
|
|
159
176
|
app.debug('Plugin options saved')
|
|
@@ -163,9 +180,8 @@ module.exports = function (app) {
|
|
|
163
180
|
removeSensorFromList(sensor)
|
|
164
181
|
if (sensor.isActive())
|
|
165
182
|
await sensor.stopListening()
|
|
166
|
-
initConfiguredDevice(req.body)
|
|
167
183
|
}
|
|
168
|
-
|
|
184
|
+
initConfiguredDevice(req.body)
|
|
169
185
|
}
|
|
170
186
|
)
|
|
171
187
|
|
|
@@ -240,9 +256,10 @@ module.exports = function (app) {
|
|
|
240
256
|
|
|
241
257
|
router.get('/getProgress', (req, res) => {
|
|
242
258
|
app.debug("Sending progress")
|
|
243
|
-
|
|
259
|
+
let deviceCount = deviceConfigs.filter((dc)=>dc.active).length
|
|
260
|
+
const json = {"progress":foundConfiguredDevices/deviceCount, "maxTimeout": 1,
|
|
244
261
|
"deviceCount":foundConfiguredDevices,
|
|
245
|
-
"totalDevices":
|
|
262
|
+
"totalDevices": deviceCount}
|
|
246
263
|
res.status(200).json(json)
|
|
247
264
|
|
|
248
265
|
});
|
|
@@ -576,11 +593,13 @@ module.exports = function (app) {
|
|
|
576
593
|
}
|
|
577
594
|
if (!(deviceConfigs===undefined)){
|
|
578
595
|
const maxTimeout=Math.max(...deviceConfigs.map((dc)=>dc?.discoveryTimeout??options.discoveryTimeout))
|
|
596
|
+
const totalDevices = deviceConfigs.filter((dc)=>dc.active).length
|
|
597
|
+
|
|
579
598
|
var progress = 0
|
|
580
599
|
if (progressID==null)
|
|
581
600
|
progressID = setInterval(()=>{
|
|
582
|
-
channel.broadcast({"progress":++progress, "maxTimeout": maxTimeout, "deviceCount":foundConfiguredDevices, "totalDevices":
|
|
583
|
-
if ( foundConfiguredDevices==
|
|
601
|
+
channel.broadcast({"progress":++progress, "maxTimeout": maxTimeout, "deviceCount":foundConfiguredDevices, "totalDevices": totalDevices},"progress")
|
|
602
|
+
if ( foundConfiguredDevices==totalDevices){
|
|
584
603
|
progressID,progressTimeoutID = null
|
|
585
604
|
clearTimeout(progressTimeoutID)
|
|
586
605
|
clearInterval(progressID)
|
|
@@ -593,7 +612,7 @@ module.exports = function (app) {
|
|
|
593
612
|
|
|
594
613
|
clearInterval(progressID);
|
|
595
614
|
progressID=null
|
|
596
|
-
channel.broadcast({"progress":maxTimeout, "maxTimeout": maxTimeout, "deviceCount":foundConfiguredDevices, "totalDevices":
|
|
615
|
+
channel.broadcast({"progress":maxTimeout, "maxTimeout": maxTimeout, "deviceCount":foundConfiguredDevices, "totalDevices": totalDevices},"progress")
|
|
597
616
|
}
|
|
598
617
|
}, (maxTimeout+1)*1000);
|
|
599
618
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bt-sensors-plugin-sk",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Bluetooth Sensors for Signalk - see https://www.npmjs.com/package/bt-sensors-plugin-sk#supported-sensors for a list of supported sensors",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
package/public/847.js
CHANGED
|
@@ -1 +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,{default:()=>k});var a=n(73490),o=n(74810),s=n(86528),r=n.n(s),l=n(40334),c=n(27606),i=n(86452),u=n(82096),g=n(3768),d=n(71431),m=n(39676),f=n(47041),h=n(86038),p=n(95027),E=n(43540),w=n(38250),y=n(31008),v=n(20455),S=n(23399);const b=e=>console.log.bind(console,e);var A,D={};function k(e){const t=(0,u.A)((e=>({root:{"& > *":{margin:e.spacing(1)}}}))),[n,k]=(0,s.useState)({}),[C
|
|
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,{default:()=>k});var a=n(73490),o=n(74810),s=n(86528),r=n.n(s),l=n(40334),c=n(27606),i=n(86452),u=n(82096),g=n(3768),d=n(71431),m=n(39676),f=n(47041),h=n(86038),p=n(95027),E=n(43540),w=n(38250),y=n(31008),v=n(20455),S=n(23399);const b=e=>console.log.bind(console,e);var A,D={};function k(e){const t=(0,u.A)((e=>({root:{"& > *":{margin:e.spacing(1)}}}))),[n,k]=(0,s.useState)({}),[$,C]=(0,s.useState)({}),[_,x]=(0,s.useState)({}),[T,N]=(0,s.useState)({"ui:options":{label:!1},title:{"ui:widget":"hidden"}}),[j,M]=(0,s.useState)([]),[O,U]=(0,s.useState)(),[L,J]=(0,s.useState)(new Map),[B,I]=(0,s.useState)({progress:0,maxTimeout:100,deviceCount:0,totalDevices:0}),[P,R]=(0,s.useState)("unknown"),[G,H]=(0,s.useState)(),K=t();function F(e,t){console.log(`sending ${e}`),console.log(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 W(e){var t;console.log(`fetching ${e}`);try{t=fetch(`/plugins/bt-sensors-plugin-sk/${e}`,{credentials:"include"})}catch(e){t={status:500,statusText:e.toString()}}return t}function Y(e){return Object.keys(e.config).length>0}function q(e){const t=Y(e);return r().createElement(v.A,{action:!0,onClick:()=>{e.config.mac_address=e.info.mac,x(e.schema),U(e.config)}},r().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}`,r().createElement("div",{class:"d-flex justify-content-between "},function(e){return null==e.info.lastContactDelta||e.info.lastContactDelta>e.config.discoveryTimeout?r().createElement(g.A,null):e.info.signalStrength>80?r().createElement(d.A,null):e.info.signalStrength>60?r().createElement(m.A,null):e.info.signalStrength>40?r().createElement(f.A,null):e.info.signalStrength>20?r().createElement(h.A,null):r().createElement(p.A,null)}(e))));var n}function z(){return Array.from(L.entries()).filter((e=>Y(e[1])))}function Q(e){return"_configured"===e?z():Array.from(L.entries()).filter((t=>t[1].info.domain===e))}function V(e){window.open(e,"_blank","noreferrer")}return(0,s.useEffect)((()=>{console.log("useEffect([])");let e=null;return W("getPluginState").then((async t=>{if(404==t.status)throw R("unknown"),new Error("unable to get plugin state");const n=await t.json();console.log("Setting up eventsource"),e=new EventSource("/plugins/bt-sensors-plugin-sk/sse",{withCredentials:!0}),R(n.state),await async function(){console.log("getDomains");const e=await W("getDomains");if(200!=e.status)throw new Error(`Unable get domain data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}(),e.addEventListener("newsensor",(e=>{console.log("newsensor");let t=JSON.parse(e.data);A.has(t.info.mac)||(console.log(`New sensor: ${t.info.mac}`),J(new Map(A.set(t.info.mac,t))))})),e.addEventListener("sensorchanged",(e=>{let t=JSON.parse(e.data);if(console.log("sensorchanged"),console.log(t),A.has(t.mac)){let e=A.get(t.mac);Object.assign(e.info,t),J(new Map(A))}})),e.addEventListener("progress",(e=>{console.log("progress");const t=JSON.parse(e.data);I(t),console.log(t)})),e.addEventListener("pluginstate",(e=>{console.log("pluginstate");const t=JSON.parse(e.data);R(t.state)}))})).catch((e=>{H(e)})),()=>{console.log("Closing connection to SSE"),e.close()}}),[]),(0,s.useEffect)((()=>{console.log("useEffect([pluginState])"),"started"==P?(console.log("refreshing sensor map"),async function(){console.log("getSensors");const e=await W("getSensors");if(200!=e.status)throw new Error(`Unable get sensor data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}().then((e=>{J(new Map(e.map((e=>[e.info.mac,e]))))})).catch((e=>{H(e)})),async function(){console.log("getBaseData");const e=await W("getBaseData");if(200!=e.status)throw new Error(`Unable to get base data: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t.schema.htmlDescription=r().createElement("div",null,(0,l.Ay)(t.schema.htmlDescription),r().createElement("p",null)),t}().then((e=>{k(e.schema),C(e.data)})).catch((e=>{H(e)})),async function(){console.log("getProgress");const e=await W("getProgress");if(200!=e.status)throw new Error(`Unable to get progress: ${e.statusText} (${e.status}) `);const t=await e.json();return console.log(t),t}().then((e=>{I(e)})).catch((e=>{H(e)}))):(J(new Map),k({}),C({}))}),[P]),(0,s.useEffect)((()=>{console.log("useEffect([sensorMap])"),A=L;const e=[...new Set(L.entries().map((e=>e[1].info.domain)))].sort(),t={_configured:0==z().length?"Select a device from its domain tab (Electrical etc.) and configure it.":z().map((e=>q(L.get(e[0]))))};e.forEach((e=>{t[e]=Q(e).map((e=>q(L.get(e[0]))))})),D=t}),[L]),"stopped"==P||"unknown"==P?r().createElement("h3",null,"Enable plugin to see configuration"):r().createElement("div",null,r().createElement("div",{className:K.root},r().createElement(i.A,{variant:"contained",onClick:()=>{V("https://github.com/naugehyde/bt-sensors-plugin-sk/tree/1.2.0-beta#configuration")}},"Documentation"),r().createElement(i.A,{variant:"contained",onClick:()=>{V("https://github.com/naugehyde/bt-sensors-plugin-sk/issues/new/choose")}},"Report Issue"),r().createElement(i.A,{variant:"contained",onClick:()=>{V("https://discord.com/channels/1170433917761892493/1295425963466952725")}},"Discord Thread"),r().createElement("p",null),r().createElement("p",null)),r().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),G?r().createElement("h2",{style:"color: red;"},G):"",r().createElement(a.Ay,{schema:n,validator:o.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=>C(e.formData),onSubmit:({formData:e},t)=>{var n;n=e,console.log("updateBaseData"),F("updateBaseData",n).then((e=>{200!=e.status&&H(new Error(`Unable to update base data: ${e.statusText} (${e.status})`))})),x({})},onError:b("errors"),formData:$}),r().createElement("hr",{style:{width:"100%",height:"1px",color:"gray","background-color":"gray","text-align":"left","margin-left":0}}),r().createElement("p",null),r().createElement("p",null),B.deviceCount<B.totalDevices?r().createElement(S.A,{max:B.maxTimeout,now:B.progress}):"",r().createElement("p",null),r().createElement(w.A,{defaultActiveKey:"_configured",id:"domain-tabs",className:"mb-3",onClick:()=>{x({})}},Object.keys(D).map((e=>function(e){var t=e.slice("_"===e.charAt(0)?1:0);let n=function(e){return D[e]}(e);return r().createElement(y.A,{eventKey:e,title:`${t.charAt(0).toUpperCase()}${t.slice(1)}${0==Q(e).length?"":" ("+Q(e).length+")"}`},r().createElement(E.A,{style:{maxHeight:"300px",overflowY:"auto"}},n))}(e)))),r().createElement("div",{style:{paddingLeft:10,paddingTop:10,display:0==Object.keys(_).length?"none":""}},r().createElement(c.A,{container:!0,direction:"column",style:{spacing:5}},r().createElement(c.A,{item:!0},r().createElement("h2",null,_?.title),r().createElement("p",null)),r().createElement(c.A,{item:!0},(0,l.Ay)(_?.htmlDescription))),r().createElement(a.Ay,{schema:_,validator:o.Ay,uiSchema:T,onChange:e=>{L.get(e.formData.mac_address)._changesMade=!0,U(e.formData)},onSubmit:({formData:e},t)=>{var n;n=e,console.log("updateSensorData"),F("updateSensorData",n).then((e=>{if(200!=e.status)throw new Error(e.statusText);L.get(n.mac_address)._changesMade=!1,L.get(n.mac_address).config=n})),x({}),alert("Changes saved")},onError:b("errors"),formData:O},r().createElement("div",{className:K.root},r().createElement(i.A,{type:"submit",color:"primary",variant:"contained"},"Save"),r().createElement(i.A,{variant:"contained",onClick:()=>{var e;e=O.mac_address,console.log("undoChanges"),L.get(e)._changesMade=!1,U(L.get(e).config)}},"Undo"),r().createElement(i.A,{variant:"contained",color:"secondary",onClick:e=>{return t=O.mac_address,void(window.confirm(`Delete configuration for ${t}?`)&&function(e){console.log("removeSensorData");try{F("removeSensorData",{mac_address:e}).then((e=>{if(200!=e.status)throw new Error(e.statusText)})),A.delete(e),J(new Map(A)),x({})}catch{}}(t));var t}},"Delete")))))}}}]);
|
|
@@ -381,6 +381,9 @@ function configuredDevices(){
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
function devicesInDomain(domain){
|
|
384
|
+
if (domain==="_configured")
|
|
385
|
+
return configuredDevices()
|
|
386
|
+
else
|
|
384
387
|
return Array.from(sensorMap.entries()).filter((entry)=>entry[1].info.domain===domain)
|
|
385
388
|
}
|
|
386
389
|
|
|
@@ -390,9 +393,11 @@ useEffect(()=>{
|
|
|
390
393
|
|
|
391
394
|
_sensorMap = sensorMap
|
|
392
395
|
|
|
393
|
-
const _sensorDomains = new Set(sensorMap.entries().map((entry)=>{ return entry[1].info.domain}))
|
|
396
|
+
const _sensorDomains = [... (new Set(sensorMap.entries().map((entry)=>{ return entry[1].info.domain})))].sort()
|
|
394
397
|
const sl = {
|
|
395
|
-
_configured: configuredDevices().
|
|
398
|
+
_configured: configuredDevices().length==0?
|
|
399
|
+
"Select a device from its domain tab (Electrical etc.) and configure it.":
|
|
400
|
+
configuredDevices().map((entry) => {
|
|
396
401
|
return createListGroupItem(sensorMap.get(entry[0]))
|
|
397
402
|
})
|
|
398
403
|
}
|
|
@@ -425,11 +430,12 @@ useEffect(()=>{
|
|
|
425
430
|
|
|
426
431
|
function getTab(key){
|
|
427
432
|
var title = key.slice(key.charAt(0)==="_"?1:0)
|
|
433
|
+
let sl = getSensorList(key)
|
|
428
434
|
|
|
429
|
-
return <Tab eventKey={key} title={title.charAt(0).toUpperCase()
|
|
435
|
+
return <Tab eventKey={key} title={`${title.charAt(0).toUpperCase()}${title.slice(1)}${devicesInDomain(key).length==0?'':' ('+devicesInDomain(key).length+')'}` } >
|
|
430
436
|
|
|
431
437
|
<ListGroup style={{ maxHeight: '300px', overflowY: 'auto' }}>
|
|
432
|
-
{
|
|
438
|
+
{sl}
|
|
433
439
|
</ListGroup>
|
|
434
440
|
|
|
435
441
|
|