homebridge-ipark-hb 1.0.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.
Files changed (2) hide show
  1. package/index.js +54 -0
  2. package/package.json +19 -0
package/index.js ADDED
@@ -0,0 +1,54 @@
1
+ const axios = require("axios");
2
+
3
+ let Service, Characteristic;
4
+
5
+ module.exports = (api) => {
6
+ Service = api.hap.Service;
7
+ Characteristic = api.hap.Characteristic;
8
+ api.registerPlatform("ipark-hb", "IPARKHB", Platform);
9
+ };
10
+
11
+ class Platform {
12
+ constructor(log, config, api) {
13
+ this.log = log;
14
+ this.api = api;
15
+ this.config = config;
16
+ this.accessories = [];
17
+
18
+ this.http = axios.create({
19
+ baseURL: "https://idj1.hdc-smart.com/v2/api/features",
20
+ timeout: 5000,
21
+ headers: { "access-token": `${config.token}` },
22
+ });
23
+
24
+ api.on("didFinishLaunching", () => this.init());
25
+ }
26
+
27
+ configureAccessory(acc) {
28
+ this.accessories.push(acc);
29
+ }
30
+ setup(acc) {
31
+ const svc =
32
+ acc.getService(Service.Lightbulb) ||
33
+ acc.addService(Service.Lightbulb);
34
+
35
+ svc.getCharacteristic(Characteristic.On)
36
+ .onGet(async () => {
37
+ const res = await this.http.get(
38
+ `/light/${acc.context.room}/apply`,
39
+ );
40
+
41
+ const device = res.data.units.find(
42
+ (u) => u.unit === acc.context.unit,
43
+ );
44
+
45
+ return device?.state === "on";
46
+ })
47
+ .onSet(async (value) => {
48
+ await this.http.put(`/light/${acc.context.room}/apply`, {
49
+ unit: acc.context.unit,
50
+ state: value ? "on" : "off",
51
+ });
52
+ });
53
+ }
54
+ }
package/package.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "homebridge-ipark-hb",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Jonathan0827/homebridge-ipark-hb.git"
11
+ },
12
+ "author": "",
13
+ "license": "ISC",
14
+ "homepage": "https://github.com/Jonathan0827/homebridge-ipark-hb#readme",
15
+ "description": "",
16
+ "peerDependencies": {
17
+ "homebridge": "^1.11.4"
18
+ }
19
+ }