@switchbot/homebridge-switchbot 2.14.0-beta.3 → 2.14.1-beta.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/CHANGELOG.md +9 -0
- package/config.schema.json +1 -0
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +49 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/package.json +12 -10
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
+
## [2.14.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.14.0) (2024-1-6)
|
|
6
|
+
|
|
7
|
+
### What's Changed
|
|
8
|
+
|
|
9
|
+
- Added Curtain Hold Command to OpenAPI.
|
|
10
|
+
- This will only Works in 3rd Party Home App, Like [Eve](https://apps.apple.com/us/app/eve-for-homekit/id917695792) or [Home+ 5](https://apps.apple.com/us/app/home-5/id995994352)
|
|
11
|
+
|
|
12
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/homebridge-switchbot/compare/v2.13.2...v2.14.0
|
|
13
|
+
|
|
5
14
|
## [2.13.2](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v2.13.2) (2024-1-5)
|
|
6
15
|
|
|
7
16
|
### What's Changed
|
package/config.schema.json
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
"pluginType": "platform",
|
|
4
4
|
"singular": true,
|
|
5
5
|
"customUi": true,
|
|
6
|
+
"customUiPath": "./dist/homebridge-ui",
|
|
6
7
|
"headerDisplay": "<p align='center'><img width='100px' src='https://user-images.githubusercontent.com/9875439/102681754-ac2eb800-4189-11eb-8e17-7c47c804484b.png'></p>\n\nThe **SwitchBot** plugin allows you to control SwitchBot Devices. \n\nTo get started link your SwitchBot account.\n\n1. Download SwitchBot App on App Store or Google Play Store.\n\n2. Register a SwitchBot account and log in into your account.\n\n3. Generate an Open Token within the App.\n\n4. Input your `Open Token` into the paramter below.",
|
|
7
8
|
"footerDisplay": "Please raise any issues on our [project page](https://github.com/OpenWonderLabs/homebridge-switchbot/issues).\n\nIf you would like to have other SwitchBot Devices added to this plugin fill out [Feature Request Form](https://github.com/OpenWonderLabs/homebridge-switchbot/issues/new?assignees=&labels=&template=feature_request.md).\n\n[SwitchBot Website](https://www.switch-bot.com)",
|
|
8
9
|
"schema": {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/homebridge-ui/server.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable no-console */
|
|
7
|
+
const plugin_ui_utils_1 = require("@homebridge/plugin-ui-utils");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
class PluginUiServer extends plugin_ui_utils_1.HomebridgePluginUiServer {
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
/*
|
|
13
|
+
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
14
|
+
The following is for users who have a lower version of config-ui-x
|
|
15
|
+
*/
|
|
16
|
+
this.onRequest('getCachedAccessories', () => {
|
|
17
|
+
try {
|
|
18
|
+
const plugin = 'homebridge-switchbot';
|
|
19
|
+
const devicesToReturn = [];
|
|
20
|
+
// The path and file of the cached accessories
|
|
21
|
+
const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories';
|
|
22
|
+
// Check the file exists
|
|
23
|
+
if (fs_1.default.existsSync(accFile)) {
|
|
24
|
+
// read the cached accessories file
|
|
25
|
+
const cachedAccessories = JSON.parse(fs_1.default.readFileSync(accFile, 'utf8'));
|
|
26
|
+
cachedAccessories.forEach((accessory) => {
|
|
27
|
+
// Check the accessory is from this plugin
|
|
28
|
+
if (accessory.plugin === plugin) {
|
|
29
|
+
// Add the cached accessory to the array
|
|
30
|
+
devicesToReturn.push(accessory.accessory);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// Return the array
|
|
35
|
+
return devicesToReturn;
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// Just return an empty accessory list in case of any errors
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
this.ready();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function startPluginUiServer() {
|
|
46
|
+
return new PluginUiServer();
|
|
47
|
+
}
|
|
48
|
+
startPluginUiServer();
|
|
49
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/homebridge-ui/server.ts"],"names":[],"mappings":";;;;;AAAA,+BAA+B;AAC/B,iEAAuE;AACvE,4CAAoB;AAEpB,MAAM,cAAe,SAAQ,0CAAwB;IACnD;QACE,KAAK,EAAE,CAAC;QACR;;;UAGE;QACF,IAAI,CAAC,SAAS,CAAC,sBAAsB,EAAE,GAAG,EAAE;YAC1C,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,sBAAsB,CAAC;gBACtC,MAAM,eAAe,GAAG,EAAE,CAAC;gBAE3B,8CAA8C;gBAC9C,MAAM,OAAO,GAAG,IAAI,CAAC,qBAAqB,GAAG,gCAAgC,CAAC;gBAE9E,wBAAwB;gBACxB,IAAI,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;oBAC3B,mCAAmC;oBACnC,MAAM,iBAAiB,GAAU,IAAI,CAAC,KAAK,CAAC,YAAE,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;oBAE9E,iBAAiB,CAAC,OAAO,CAAC,CAAC,SAAc,EAAE,EAAE;wBAC3C,0CAA0C;wBAC1C,IAAI,SAAS,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;4BAChC,wCAAwC;4BACxC,eAAe,CAAC,IAAI,CAAC,SAAS,CAAC,SAAkB,CAAC,CAAC;wBACrD,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;gBACD,mBAAmB;gBACnB,OAAO,eAAe,CAAC;YACzB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,4DAA4D;gBAC5D,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,cAAc,EAAE,CAAC;AAC9B,CAAC;AAED,mBAAmB,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"displayName": "SwitchBot",
|
|
3
3
|
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
-
"version": "2.14.
|
|
4
|
+
"version": "2.14.1-beta.0",
|
|
5
5
|
"description": "The SwitchBot plugin allows you to access your SwitchBot device(s) from HomeKit.",
|
|
6
6
|
"author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
|
|
7
7
|
"license": "ISC",
|
|
@@ -21,11 +21,13 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"check": "npm install && npm outdated",
|
|
23
23
|
"update": "ncu -u && npm update && npm install",
|
|
24
|
-
"
|
|
24
|
+
"update dependencies": "npm run check && npm run update",
|
|
25
25
|
"lint": "eslint src/**.ts",
|
|
26
|
-
"
|
|
26
|
+
"jlint": "eslint homebridge-ui/public/**.mjs",
|
|
27
|
+
"watch": "npm run build && npm run plugin-ui && npm link && nodemon",
|
|
28
|
+
"plugin-ui": "rsync ./src/homebridge-ui/public/index.html ./dist/homebridge-ui/public/",
|
|
27
29
|
"build": "rimraf ./dist && tsc",
|
|
28
|
-
"prepublishOnly": "npm run lint && npm run build",
|
|
30
|
+
"prepublishOnly": "npm run lint && npm run build && npm run plugin-ui ",
|
|
29
31
|
"postpublish": "npm run clean",
|
|
30
32
|
"clean": "rimraf ./dist",
|
|
31
33
|
"test": "eslint src/**.ts"
|
|
@@ -57,12 +59,12 @@
|
|
|
57
59
|
"ir"
|
|
58
60
|
],
|
|
59
61
|
"dependencies": {
|
|
60
|
-
"@homebridge/plugin-ui-utils": "^1.0.
|
|
62
|
+
"@homebridge/plugin-ui-utils": "^1.0.1",
|
|
61
63
|
"async-mqtt": "^2.6.3",
|
|
62
64
|
"fakegato-history": "^0.6.4",
|
|
63
65
|
"homebridge-lib": "^6.7.3",
|
|
64
66
|
"rxjs": "^7.8.1",
|
|
65
|
-
"undici": "^6.
|
|
67
|
+
"undici": "^6.4.0"
|
|
66
68
|
},
|
|
67
69
|
"optionalDependencies": {
|
|
68
70
|
"node-switchbot": "^1.10.0",
|
|
@@ -70,12 +72,12 @@
|
|
|
70
72
|
"@abandonware/bluetooth-hci-socket": "^0.5.3-10"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@types/node": "^20.
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
75
|
-
"@typescript-eslint/parser": "^6.
|
|
75
|
+
"@types/node": "^20.11.5",
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "^6.19.0",
|
|
77
|
+
"@typescript-eslint/parser": "^6.19.0",
|
|
76
78
|
"eslint": "^8.56.0",
|
|
77
79
|
"homebridge": "^1.7.0",
|
|
78
|
-
"nodemon": "^3.0.
|
|
80
|
+
"nodemon": "^3.0.3",
|
|
79
81
|
"npm-check-updates": "^16.14.12",
|
|
80
82
|
"rimraf": "^5.0.5",
|
|
81
83
|
"ts-node": "^10.9.2",
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
<p class="text-center">
|
|
2
|
+
<img
|
|
3
|
+
src="https://raw.githubusercontent.com/OpenWonderLabs/homebridge-switchbot/latest/branding/Homebridge_x_SwitchBot.svg"
|
|
4
|
+
alt="homebridge-switchbot logo"
|
|
5
|
+
style="width: 50%" />
|
|
6
|
+
</p>
|
|
7
|
+
<div id="pageIntro" style="display: none">
|
|
8
|
+
<p class="lead text-center">Thank you for installing <strong>homebridge-switchbot</strong></p>
|
|
9
|
+
<p class="lead text-center">Before continuing:</p>
|
|
10
|
+
<ol>
|
|
11
|
+
<li class="mb-3">
|
|
12
|
+
Download the SwitchBot App from either the
|
|
13
|
+
<a href="https://apps.apple.com/us/app/switchbot/id1087374760" target="_blank" rel="noreferrer noopener">App Store</a> or the
|
|
14
|
+
<a href="https://play.google.com/store/apps/details?id=com.theswitchbot.switchbot&hl=en_US&gl=US" target="_blank" rel="noreferrer noopener"
|
|
15
|
+
>Play Store</a
|
|
16
|
+
>.
|
|
17
|
+
</li>
|
|
18
|
+
<li class="mb-3">Select <strong>Profile</strong>.</li>
|
|
19
|
+
<li class="mb-3">Select <strong>Preferences</strong>.</li>
|
|
20
|
+
<li class="mb-3">Tap the <strong>App version</strong> 10 times, this will enable Developer Options.</li>
|
|
21
|
+
<li class="mb-3">Select <strong>Developer Options</strong>.</li>
|
|
22
|
+
<li class="mb-3">Copy your token by hitting <strong>Copy to Clipboard</strong>.</li>
|
|
23
|
+
<li class="mb-3">Paste the Token into the Token parameter on the next page.</li>
|
|
24
|
+
</ol>
|
|
25
|
+
<div class="text-center">
|
|
26
|
+
<button type="button" class="btn btn-primary" id="introLink">Continue →</button>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<div id="menuWrapper" class="btn-group w-100 mb-0" role="group" aria-label="UI Menu" style="display: none">
|
|
30
|
+
<button type="button" class="btn btn-primary" id="menuSettings">Settings</button>
|
|
31
|
+
<button type="button" class="btn btn-primary" id="menuDevices">Devices</button>
|
|
32
|
+
<button type="button" class="btn btn-primary mr-0" id="menuHome">Support</button>
|
|
33
|
+
</div>
|
|
34
|
+
<div id="disabledBanner" class="alert alert-secondary mb-0 mt-3" role="alert" style="display: none">
|
|
35
|
+
Plugin is currently disabled
|
|
36
|
+
<button id="disabledEnable" type="button" class="btn btn-link p-0 m-0 float-right">Enable</button>
|
|
37
|
+
</div>
|
|
38
|
+
<div id="pageDevices" class="mt-4" style="display: none">
|
|
39
|
+
<div id="deviceInfo">
|
|
40
|
+
<form>
|
|
41
|
+
<div class="form-group">
|
|
42
|
+
<select class="form-control" id="deviceSelect"></select>
|
|
43
|
+
</div>
|
|
44
|
+
</form>
|
|
45
|
+
<table class="table w-100" id="deviceTable" style="display: none">
|
|
46
|
+
<thead>
|
|
47
|
+
<tr class="table-active">
|
|
48
|
+
<th scope="col" style="width: 40%">Device Name</th>
|
|
49
|
+
<th scope="col" style="width: 60%" id="displayName"></th>
|
|
50
|
+
</tr>
|
|
51
|
+
</thead>
|
|
52
|
+
<tbody>
|
|
53
|
+
<tr>
|
|
54
|
+
<th scope="row">Device ID</th>
|
|
55
|
+
<td id="deviceID"></td>
|
|
56
|
+
</tr>
|
|
57
|
+
<tr>
|
|
58
|
+
<th scope="row">Model</th>
|
|
59
|
+
<td id="model"></td>
|
|
60
|
+
</tr>
|
|
61
|
+
<tr>
|
|
62
|
+
<th scope="row">Firmware Version</th>
|
|
63
|
+
<td id="firmwareRevision"></td>
|
|
64
|
+
</tr>
|
|
65
|
+
<tr>
|
|
66
|
+
<th scope="row">Device Type</th>
|
|
67
|
+
<td id="deviceType"></td>
|
|
68
|
+
</tr>
|
|
69
|
+
<tr>
|
|
70
|
+
<th scope="row">Connection Type</th>
|
|
71
|
+
<td id="connectionType"></td>
|
|
72
|
+
</tr>
|
|
73
|
+
</tbody>
|
|
74
|
+
</table>
|
|
75
|
+
<p class="text-center">External Accessories Will Not Display Here.</p>
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
<div id="pageSupport" class="mt-4" style="display: none">
|
|
79
|
+
<p class="text-center lead">Thank you for using <strong>homebridge-switchbot</strong></p>
|
|
80
|
+
<p class="text-center">The links below will take you to our GitHub wiki</p>
|
|
81
|
+
<h5>Setup</h5>
|
|
82
|
+
<ul>
|
|
83
|
+
<li>
|
|
84
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki" target="_blank">Wiki Home</a>
|
|
85
|
+
</li>
|
|
86
|
+
<li>
|
|
87
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Configuration" target="_blank">Configuration</a>
|
|
88
|
+
</li>
|
|
89
|
+
<li>
|
|
90
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Beta-Version" target="_blank">Beta Version</a>
|
|
91
|
+
</li>
|
|
92
|
+
<li>
|
|
93
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Node-Version" target="_blank">Node Version</a>
|
|
94
|
+
</li>
|
|
95
|
+
<li>
|
|
96
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Uninstallation" target="_blank">Uninstallation</a>
|
|
97
|
+
</li>
|
|
98
|
+
</ul>
|
|
99
|
+
<h5>Features</h5>
|
|
100
|
+
<ul>
|
|
101
|
+
<li>
|
|
102
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/wiki/Supported-Devices" target="_blank">Supported Devices</a>
|
|
103
|
+
</li>
|
|
104
|
+
</ul>
|
|
105
|
+
<h5>Help/About</h5>
|
|
106
|
+
<ul>
|
|
107
|
+
<li>
|
|
108
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/issues/new/choose" target="_blank">Support Request</a>
|
|
109
|
+
</li>
|
|
110
|
+
<li>
|
|
111
|
+
<a href="https://github.com/OpenWonderLabs/homebridge-switchbot/blob/latest/CHANGELOG.md" target="_blank">Changelog</a>
|
|
112
|
+
</li>
|
|
113
|
+
</ul>
|
|
114
|
+
</div>
|
|
115
|
+
<script>
|
|
116
|
+
(async () => {
|
|
117
|
+
try {
|
|
118
|
+
const currentConfig = await homebridge.getPluginConfig();
|
|
119
|
+
showIntro = () => {
|
|
120
|
+
const introLink = document.getElementById('introLink');
|
|
121
|
+
introLink.addEventListener('click', () => {
|
|
122
|
+
homebridge.showSpinner();
|
|
123
|
+
document.getElementById('pageIntro').style.display = 'none';
|
|
124
|
+
document.getElementById('menuWrapper').style.display = 'inline-flex';
|
|
125
|
+
showSettings();
|
|
126
|
+
homebridge.hideSpinner();
|
|
127
|
+
});
|
|
128
|
+
document.getElementById('pageIntro').style.display = 'block';
|
|
129
|
+
};
|
|
130
|
+
showDevices = async () => {
|
|
131
|
+
homebridge.showSpinner();
|
|
132
|
+
homebridge.hideSchemaForm();
|
|
133
|
+
document.getElementById('menuHome').classList.remove('btn-elegant');
|
|
134
|
+
document.getElementById('menuHome').classList.add('btn-primary');
|
|
135
|
+
document.getElementById('menuDevices').classList.add('btn-elegant');
|
|
136
|
+
document.getElementById('menuDevices').classList.remove('btn-primary');
|
|
137
|
+
document.getElementById('menuSettings').classList.remove('btn-elegant');
|
|
138
|
+
document.getElementById('menuSettings').classList.add('btn-primary');
|
|
139
|
+
document.getElementById('pageSupport').style.display = 'none';
|
|
140
|
+
document.getElementById('pageDevices').style.display = 'block';
|
|
141
|
+
const cachedAccessories =
|
|
142
|
+
typeof homebridge.getCachedAccessories === 'function'
|
|
143
|
+
? await homebridge.getCachedAccessories()
|
|
144
|
+
: await homebridge.request('/getCachedAccessories');
|
|
145
|
+
if (cachedAccessories.length > 0) {
|
|
146
|
+
cachedAccessories.sort((a, b) => {
|
|
147
|
+
return a.displayName.toLowerCase() > b.displayName.toLowerCase() ? 1 : b.displayName.toLowerCase() > a.displayName.toLowerCase() ? -1 : 0;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const deviceSelect = document.getElementById('deviceSelect');
|
|
151
|
+
deviceSelect.innerHTML = '';
|
|
152
|
+
cachedAccessories.forEach((a) => {
|
|
153
|
+
const option = document.createElement('option');
|
|
154
|
+
option.text = a.displayName;
|
|
155
|
+
option.value = a.UUID;
|
|
156
|
+
deviceSelect.add(option);
|
|
157
|
+
});
|
|
158
|
+
showDeviceInfo = async (UUID) => {
|
|
159
|
+
homebridge.showSpinner();
|
|
160
|
+
const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
|
|
161
|
+
const context = thisAcc.context;
|
|
162
|
+
document.getElementById('displayName').innerHTML = thisAcc.displayName;
|
|
163
|
+
document.getElementById('deviceID').innerHTML = context.deviceID;
|
|
164
|
+
document.getElementById('model').innerHTML = context.model;
|
|
165
|
+
document.getElementById('firmwareRevision').innerHTML = context.firmwareRevision || 'N/A';
|
|
166
|
+
document.getElementById('deviceType').innerHTML = context.deviceType;
|
|
167
|
+
document.getElementById('connectionType').innerHTML = context.connectionType;
|
|
168
|
+
document.getElementById('deviceTable').style.display = 'inline-table';
|
|
169
|
+
homebridge.hideSpinner();
|
|
170
|
+
};
|
|
171
|
+
deviceSelect.addEventListener('change', (event) => showDeviceInfo(event.target.value));
|
|
172
|
+
if (cachedAccessories.length > 0) {
|
|
173
|
+
showDeviceInfo(cachedAccessories[0].UUID);
|
|
174
|
+
} else {
|
|
175
|
+
const option = document.createElement('option');
|
|
176
|
+
option.text = 'No Devices';
|
|
177
|
+
deviceSelect.add(option);
|
|
178
|
+
deviceSelect.disabled = true;
|
|
179
|
+
}
|
|
180
|
+
homebridge.hideSpinner();
|
|
181
|
+
};
|
|
182
|
+
showSupport = () => {
|
|
183
|
+
homebridge.showSpinner();
|
|
184
|
+
homebridge.hideSchemaForm();
|
|
185
|
+
document.getElementById('menuHome').classList.add('btn-elegant');
|
|
186
|
+
document.getElementById('menuHome').classList.remove('btn-primary');
|
|
187
|
+
document.getElementById('menuDevices').classList.remove('btn-elegant');
|
|
188
|
+
document.getElementById('menuDevices').classList.add('btn-primary');
|
|
189
|
+
document.getElementById('menuSettings').classList.remove('btn-elegant');
|
|
190
|
+
document.getElementById('menuSettings').classList.add('btn-primary');
|
|
191
|
+
document.getElementById('pageSupport').style.display = 'block';
|
|
192
|
+
document.getElementById('pageDevices').style.display = 'none';
|
|
193
|
+
homebridge.hideSpinner();
|
|
194
|
+
};
|
|
195
|
+
showSettings = () => {
|
|
196
|
+
homebridge.showSpinner();
|
|
197
|
+
document.getElementById('menuHome').classList.remove('btn-elegant');
|
|
198
|
+
document.getElementById('menuHome').classList.add('btn-primary');
|
|
199
|
+
document.getElementById('menuDevices').classList.remove('btn-elegant');
|
|
200
|
+
document.getElementById('menuDevices').classList.add('btn-primary');
|
|
201
|
+
document.getElementById('menuSettings').classList.add('btn-elegant');
|
|
202
|
+
document.getElementById('menuSettings').classList.remove('btn-primary');
|
|
203
|
+
document.getElementById('pageSupport').style.display = 'none';
|
|
204
|
+
document.getElementById('pageDevices').style.display = 'none';
|
|
205
|
+
homebridge.showSchemaForm();
|
|
206
|
+
homebridge.hideSpinner();
|
|
207
|
+
};
|
|
208
|
+
showDisabledBanner = () => {
|
|
209
|
+
document.getElementById('disabledBanner').style.display = 'block';
|
|
210
|
+
};
|
|
211
|
+
enablePlugin = async () => {
|
|
212
|
+
homebridge.showSpinner();
|
|
213
|
+
document.getElementById('disabledBanner').style.display = 'none';
|
|
214
|
+
currentConfig[0].disablePlugin = false;
|
|
215
|
+
await homebridge.updatePluginConfig(currentConfig);
|
|
216
|
+
await homebridge.savePluginConfig();
|
|
217
|
+
homebridge.hideSpinner();
|
|
218
|
+
};
|
|
219
|
+
menuHome.addEventListener('click', () => showSupport());
|
|
220
|
+
menuDevices.addEventListener('click', () => showDevices());
|
|
221
|
+
menuSettings.addEventListener('click', () => showSettings());
|
|
222
|
+
disabledEnable.addEventListener('click', () => enablePlugin());
|
|
223
|
+
if (currentConfig.length) {
|
|
224
|
+
document.getElementById('menuWrapper').style.display = 'inline-flex';
|
|
225
|
+
showSettings();
|
|
226
|
+
if (currentConfig[0].disablePlugin) {
|
|
227
|
+
showDisabledBanner();
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
currentConfig.push({ name: 'SwitchBot' });
|
|
231
|
+
await homebridge.updatePluginConfig(currentConfig);
|
|
232
|
+
showIntro();
|
|
233
|
+
}
|
|
234
|
+
} catch (err) {
|
|
235
|
+
homebridge.toast.error(err.message, 'Error');
|
|
236
|
+
} finally {
|
|
237
|
+
homebridge.hideSpinner();
|
|
238
|
+
}
|
|
239
|
+
})();
|
|
240
|
+
</script>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
|
|
5
|
+
class PluginUiServer extends HomebridgePluginUiServer {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
/*
|
|
9
|
+
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
10
|
+
The following is for users who have a lower version of config-ui-x
|
|
11
|
+
*/
|
|
12
|
+
this.onRequest('getCachedAccessories', () => {
|
|
13
|
+
try {
|
|
14
|
+
const plugin = 'homebridge-switchbot';
|
|
15
|
+
const devicesToReturn = [];
|
|
16
|
+
|
|
17
|
+
// The path and file of the cached accessories
|
|
18
|
+
const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories';
|
|
19
|
+
|
|
20
|
+
// Check the file exists
|
|
21
|
+
if (fs.existsSync(accFile)) {
|
|
22
|
+
// read the cached accessories file
|
|
23
|
+
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'));
|
|
24
|
+
|
|
25
|
+
cachedAccessories.forEach((accessory: any) => {
|
|
26
|
+
// Check the accessory is from this plugin
|
|
27
|
+
if (accessory.plugin === plugin) {
|
|
28
|
+
// Add the cached accessory to the array
|
|
29
|
+
devicesToReturn.push(accessory.accessory as never);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// Return the array
|
|
34
|
+
return devicesToReturn;
|
|
35
|
+
} catch (err) {
|
|
36
|
+
// Just return an empty accessory list in case of any errors
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
this.ready();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function startPluginUiServer(): PluginUiServer {
|
|
45
|
+
return new PluginUiServer();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
startPluginUiServer();
|
package/homebridge-ui/server.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
-
/* jshint node: true,esversion: 9, -W014, -W033 */
|
|
4
|
-
/* eslint-disable new-cap */
|
|
5
|
-
'use strict';
|
|
6
|
-
|
|
7
|
-
const { HomebridgePluginUiServer } = require('@homebridge/plugin-ui-utils');
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
|
|
10
|
-
class PluginUiServer extends HomebridgePluginUiServer {
|
|
11
|
-
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
|
|
14
|
-
/*
|
|
15
|
-
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
16
|
-
The following is for users who have a lower version of config-ui-x
|
|
17
|
-
*/
|
|
18
|
-
this.onRequest('/getCachedAccessories', async () => {
|
|
19
|
-
try {
|
|
20
|
-
// Define the plugin and create the array to return
|
|
21
|
-
const plugin = 'homebridge-switchbot';
|
|
22
|
-
const devicesToReturn = [];
|
|
23
|
-
|
|
24
|
-
// The path and file of the cached accessories
|
|
25
|
-
const accFile = this.homebridgeStoragePath + '/accessories/cachedAccessories';
|
|
26
|
-
|
|
27
|
-
// Check the file exists
|
|
28
|
-
if (fs.existsSync(accFile)) {
|
|
29
|
-
// Read the cached accessories file
|
|
30
|
-
let cachedAccessories = await fs.promises.readFile(accFile);
|
|
31
|
-
|
|
32
|
-
// Parse the JSON
|
|
33
|
-
cachedAccessories = JSON.parse(cachedAccessories);
|
|
34
|
-
|
|
35
|
-
// We only want the accessories for this plugin
|
|
36
|
-
cachedAccessories.filter((accessory) => accessory.plugin === plugin).forEach((accessory) => devicesToReturn.push(accessory));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Return the array
|
|
40
|
-
return devicesToReturn;
|
|
41
|
-
} catch (err) {
|
|
42
|
-
// Just return an empty accessory list in case of any errors
|
|
43
|
-
return [];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
this.ready();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
(() => new PluginUiServer())();
|
|
File without changes
|