diff --git a/homebridge-ui/src/env.d.ts b/homebridge-ui/src/env.d.ts
index 8ca39c8..33eacbc 100644
--- a/homebridge-ui/src/env.d.ts
+++ b/homebridge-ui/src/env.d.ts
@@ -1,2 +1,3 @@
///
-///
\ No newline at end of file
+///
+///
\ No newline at end of file
diff --git a/homebridge-ui/src/server.ts b/homebridge-ui/src/server.ts
index 55a51e5..9be16eb 100644
--- a/homebridge-ui/src/server.ts
+++ b/homebridge-ui/src/server.ts
@@ -1,8 +1,18 @@
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils';
+import { AqaraApi, AqaraApiOption } from "@api/index";
class UiServer extends HomebridgePluginUiServer {
constructor() {
super()
+
+ this.onRequest('/device', this.getAuthCode.bind(this));
+
+ this.ready();
+ }
+
+ getAuthCode(config: AqaraApiOption) {
+ const aqaraApi = new AqaraApi(config);
+ return aqaraApi.getAuthCode();
}
}
diff --git a/homebridge-ui/tsconfig.json b/homebridge-ui/tsconfig.json
index 9c92322..3463382 100644
--- a/homebridge-ui/tsconfig.json
+++ b/homebridge-ui/tsconfig.json
@@ -11,7 +11,8 @@
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"paths": {
- "@/*": ["./src/*"]
+ "@/*": ["./src/*"],
+ "@api/*": ["../src/api/*"],
},
"resolveJsonModule": true,
"rootDir": "src",
diff --git a/src/api/index.ts b/src/api/index.ts
index 3b2f364..631b4cf 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -1,11 +1,9 @@
import axios, { AxiosInstance } from 'axios';
import { createHash } from 'crypto';
-export interface AqaraApiOption {
- region: 'cn' | 'us' | 'kr' | 'ru' | 'eu' | 'sg';
- appId: string;
- appKey: string;
- keyId: string;
+
+export interface AqaraApiOption extends Aqara.AppConfig {
+ region: 'cn' | 'us' | 'kr' | 'ru' | 'eu' | 'sg';
}
const API_DOMAIN = {
@@ -37,7 +35,7 @@ export class AqaraApi {
});
}
- sign(accessToken?: string) {
+ private sign(accessToken?: string) {
const { appId, keyId, appKey } = this.option;
const nonce = Math.random().toString(36).slice(2);
const timestamp = Date.now();
@@ -54,4 +52,16 @@ export class AqaraApi {
sign,
};
}
+
+ async getAuthCode() {
+ const { data } = await this.axios.post('/', {
+ "intent": "config.auth.getAuthCode",
+ "data": {
+ "account": "189000123456",
+ "accountType": 0,
+ "accessTokenValidity": "1h"
+ }
+ });
+ return data;
+ }
}
\ No newline at end of file
diff --git a/src/types.d.ts b/src/types.d.ts
new file mode 100644
index 0000000..113b257
--- /dev/null
+++ b/src/types.d.ts
@@ -0,0 +1,7 @@
+declare namespace Aqara {
+ interface AppConfig {
+ appId: string;
+ appKey: string;
+ keyId: string;
+ }
+}
\ No newline at end of file