homebridge-plugin-aqara-v2 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +4 -4
- package/dist/platform.js.map +1 -1
- package/homebridge-ui/server.js +40 -85
- package/package.json +3 -2
- package/scripts/build-ui-server.mjs +46 -0
package/dist/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5H,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG1D,UAAU,mBAAoB,SAAQ,cAAc,EAAE,cAAc;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,uBAAwB,YAAW,qBAAqB;aAUvC,GAAG,EAAE,MAAM;aAAkB,MAAM,EAAE,mBAAmB;aAAkB,GAAG,EAAE,GAAG;IAT9G,SAAgB,OAAO,EAAE,OAAO,OAAO,
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5H,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAG1D,UAAU,mBAAoB,SAAQ,cAAc,EAAE,cAAc;IAClE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,uBAAwB,YAAW,qBAAqB;aAUvC,GAAG,EAAE,MAAM;aAAkB,MAAM,EAAE,mBAAmB;aAAkB,GAAG,EAAE,GAAG;IAT9G,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAC;IACxC,SAAgB,cAAc,EAAE,OAAO,cAAc,CAAC;IAEtD,SAAgB,QAAQ,EAAG,QAAQ,CAAC;IAEpC,SAAgB,WAAW,EAAE,sBAAsB,EAAE,CAAM;IAE3D,OAAO,CAAC,iBAAiB,CAAC,CAAiB;gBAEf,GAAG,EAAE,MAAM,EAAkB,MAAM,EAAE,mBAAmB,EAAkB,GAAG,EAAE,GAAG;IA6B9G,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAY/C,eAAe;IAMf,OAAO,CAAC,YAAY;IAyBpB,OAAO,CAAC,iBAAiB;CAY1B"}
|
package/dist/platform.js
CHANGED
|
@@ -5,8 +5,8 @@ export class AqaraHomebridgePlatform {
|
|
|
5
5
|
log;
|
|
6
6
|
config;
|
|
7
7
|
api;
|
|
8
|
-
Service
|
|
9
|
-
Characteristic
|
|
8
|
+
Service;
|
|
9
|
+
Characteristic;
|
|
10
10
|
aqaraApi;
|
|
11
11
|
accessories = [];
|
|
12
12
|
tokenRefreshTimer;
|
|
@@ -14,6 +14,8 @@ export class AqaraHomebridgePlatform {
|
|
|
14
14
|
this.log = log;
|
|
15
15
|
this.config = config;
|
|
16
16
|
this.api = api;
|
|
17
|
+
this.Service = this.api.hap.Service;
|
|
18
|
+
this.Characteristic = this.api.hap.Characteristic;
|
|
17
19
|
this.log.debug('Finished initializing platform:', this.config.name);
|
|
18
20
|
const { account } = this.config;
|
|
19
21
|
if (account) {
|
|
@@ -48,8 +50,6 @@ export class AqaraHomebridgePlatform {
|
|
|
48
50
|
this.accessories.push(aqaraAccessory);
|
|
49
51
|
}
|
|
50
52
|
discoverDevices() {
|
|
51
|
-
// this.aqaraApi.request('query.ir.info', { did: 'ir.1235995976809168896' }).then(console.log);
|
|
52
|
-
// this.aqaraApi.request('query.ir.keys', { did: 'ir.1235995976809168896' }).then(console.log);
|
|
53
53
|
this.aqaraApi.getAllDevices(this.config.positionId).then((devices) => {
|
|
54
54
|
devices.forEach((device) => this.handleDevice(device));
|
|
55
55
|
});
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM3D,MAAM,OAAO,uBAAuB;IAUN;IAA6B;IAA6C;IATtF,OAAO,
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAkB,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAM3D,MAAM,OAAO,uBAAuB;IAUN;IAA6B;IAA6C;IATtF,OAAO,CAAiB;IACxB,cAAc,CAAwB;IAEtC,QAAQ,CAAY;IAEpB,WAAW,GAA6B,EAAE,CAAC;IAEnD,iBAAiB,CAAkB;IAE3C,YAA4B,GAAW,EAAkB,MAA2B,EAAkB,GAAQ;QAAlF,QAAG,GAAH,GAAG,CAAQ;QAAkB,WAAM,GAAN,MAAM,CAAqB;QAAkB,QAAG,GAAH,GAAG,CAAK;QAC5G,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC;QAElD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE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YACL,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;YAC1D,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAgC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;YACzG,SAAS,CAAC,OAAO,GAAG;gBAClB,UAAU,EAAE,MAAM;aACnB,CAAC;YACF,IAAI,cAAc,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACpC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,WAAW,EAAE,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;SAC/E;IACH,CAAC;IAEO,iBAAiB,CAAC,UAA4B;QACpD,QAAQ,UAAU,CAAC,KAAK,EAAE;YACxB,KAAK,mBAAmB;gBACtB,OAAO,eAAe,CAAC;YACzB,KAAK,kBAAkB;gBACrB,OAAO,cAAc,CAAC;YACxB,KAAK,eAAe;gBAClB,OAAO,WAAW,CAAC;YACrB;gBACE,OAAO,SAAS,CAAC;SACpB;IACH,CAAC;CACF"}
|
package/homebridge-ui/server.js
CHANGED
|
@@ -1,89 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1
|
+
import { HomebridgePluginUiServer, RequestError } from '@homebridge/plugin-ui-utils';
|
|
2
|
+
// @ts-ignore
|
|
3
|
+
import { AqaraApi } from '../dist/api/index.js';
|
|
4
|
+
class UiServer extends HomebridgePluginUiServer {
|
|
5
|
+
aqaraApi;
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.onRequest('/auth-code', this.getAuthCode.bind(this));
|
|
9
|
+
this.onRequest('/token', this.getToken.bind(this));
|
|
10
|
+
this.onRequest('/token/local', this.getLocalToken.bind(this));
|
|
11
|
+
this.ready();
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var __publicField = (obj, key, value) => {
|
|
22
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
23
|
-
return value;
|
|
24
|
-
};
|
|
25
|
-
var __async = (__this, __arguments, generator) => {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
var fulfilled = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.next(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var rejected = (value) => {
|
|
35
|
-
try {
|
|
36
|
-
step(generator.throw(value));
|
|
37
|
-
} catch (e) {
|
|
38
|
-
reject(e);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
42
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// ui-src/server.ts
|
|
47
|
-
var import_plugin_ui_utils = require("@homebridge/plugin-ui-utils");
|
|
48
|
-
var import_api = require("../dist/api");
|
|
49
|
-
var UiServer = class extends import_plugin_ui_utils.HomebridgePluginUiServer {
|
|
50
|
-
constructor() {
|
|
51
|
-
super();
|
|
52
|
-
__publicField(this, "aqaraApi");
|
|
53
|
-
this.onRequest("/auth-code", this.getAuthCode.bind(this));
|
|
54
|
-
this.onRequest("/token", this.getToken.bind(this));
|
|
55
|
-
this.onRequest("/token/local", this.getLocalToken.bind(this));
|
|
56
|
-
this.ready();
|
|
57
|
-
}
|
|
58
|
-
getAuthCode(config) {
|
|
59
|
-
const aqaraApi = this.getAqaraApi(config);
|
|
60
|
-
return aqaraApi.getAuthCode(config.account);
|
|
61
|
-
}
|
|
62
|
-
getToken(config) {
|
|
63
|
-
return __async(this, null, function* () {
|
|
64
|
-
const aqaraApi = this.getAqaraApi(config);
|
|
65
|
-
try {
|
|
66
|
-
const result = yield aqaraApi.getToken(config.account, config.authCode);
|
|
67
|
-
return result;
|
|
68
|
-
} catch (error) {
|
|
69
|
-
const e = error;
|
|
70
|
-
throw new import_plugin_ui_utils.RequestError(e.message, { status: 500 });
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
getLocalToken(config) {
|
|
75
|
-
const aqaraApi = this.getAqaraApi(config);
|
|
76
|
-
return Promise.resolve(aqaraApi.accessToken);
|
|
77
|
-
}
|
|
78
|
-
getAqaraApi(config) {
|
|
79
|
-
if (!this.aqaraApi) {
|
|
80
|
-
this.aqaraApi = new import_api.AqaraApi(__spreadProps(__spreadValues({}, config), {
|
|
81
|
-
storagePath: this.homebridgeStoragePath || ""
|
|
82
|
-
}));
|
|
13
|
+
getAuthCode(config) {
|
|
14
|
+
const aqaraApi = this.getAqaraApi(config);
|
|
15
|
+
return aqaraApi.getAuthCode(config.account);
|
|
83
16
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
17
|
+
async getToken(config) {
|
|
18
|
+
const aqaraApi = this.getAqaraApi(config);
|
|
19
|
+
try {
|
|
20
|
+
const result = await aqaraApi.getToken(config.account, config.authCode);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
const e = error;
|
|
25
|
+
throw new RequestError(e.message, { status: 500 });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
getLocalToken(config) {
|
|
29
|
+
const aqaraApi = this.getAqaraApi(config);
|
|
30
|
+
return Promise.resolve(aqaraApi.accessToken);
|
|
31
|
+
}
|
|
32
|
+
getAqaraApi(config) {
|
|
33
|
+
if (!this.aqaraApi) {
|
|
34
|
+
this.aqaraApi = new AqaraApi({
|
|
35
|
+
...config,
|
|
36
|
+
storagePath: this.homebridgeStoragePath || '',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return this.aqaraApi;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
87
42
|
(() => {
|
|
88
|
-
|
|
43
|
+
return new UiServer();
|
|
89
44
|
})();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-plugin-aqara-v2",
|
|
3
3
|
"displayName": "Aqara",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "Aqara Homebridge plugin compatible with Homebridge v2.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"watch": "npm run build && npm link && nodemon",
|
|
21
21
|
"build": "rimraf ./dist && tsc && npm run build:ui",
|
|
22
|
-
"build:ui": "modern build"
|
|
22
|
+
"build:ui": "modern build && npm run build:ui-server",
|
|
23
|
+
"build:ui-server": "node scripts/build-ui-server.mjs"
|
|
23
24
|
},
|
|
24
25
|
"keywords": [
|
|
25
26
|
"homebridge-plugin",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import ts from 'typescript';
|
|
3
|
+
|
|
4
|
+
const sourcePath = 'ui-src/server.ts';
|
|
5
|
+
const outputPath = 'homebridge-ui/server.js';
|
|
6
|
+
const source = await readFile(sourcePath, 'utf8');
|
|
7
|
+
|
|
8
|
+
const result = ts.transpileModule(source, {
|
|
9
|
+
compilerOptions: {
|
|
10
|
+
module: ts.ModuleKind.ESNext,
|
|
11
|
+
target: ts.ScriptTarget.ES2022,
|
|
12
|
+
esModuleInterop: true,
|
|
13
|
+
importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
|
|
14
|
+
},
|
|
15
|
+
fileName: sourcePath,
|
|
16
|
+
reportDiagnostics: true,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const errors = (result.diagnostics ?? []).filter(
|
|
20
|
+
(diagnostic) => diagnostic.category === ts.DiagnosticCategory.Error,
|
|
21
|
+
);
|
|
22
|
+
if (errors.length) {
|
|
23
|
+
throw new Error(ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
24
|
+
getCurrentDirectory: () => process.cwd(),
|
|
25
|
+
getCanonicalFileName: (fileName) => fileName,
|
|
26
|
+
getNewLine: () => '\n',
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const output = result.outputText.replace(
|
|
31
|
+
/(['"])@api\/index\1/g,
|
|
32
|
+
"'../dist/api/index.js'",
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (!/from\s+['"]@homebridge\/plugin-ui-utils['"]/.test(output)) {
|
|
36
|
+
throw new Error('Generated UI server is missing the Homebridge UI utils ESM import');
|
|
37
|
+
}
|
|
38
|
+
if (!/from\s+['"]\.\.\/dist\/api\/index\.js['"]/.test(output)) {
|
|
39
|
+
throw new Error('Generated UI server is missing the built Aqara API ESM import');
|
|
40
|
+
}
|
|
41
|
+
if (/\brequire\s*\(/.test(output) || !/^import\s/m.test(output)) {
|
|
42
|
+
throw new Error('Generated UI server is not valid ESM');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await writeFile(outputPath, output);
|
|
46
|
+
console.log('Built homebridge-ui/server.js as ESM');
|