homebridge-plejd 1.5.1 → 1.6.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/dist/PlejdHbPlatform.d.ts +6 -6
- package/dist/PlejdHbPlatform.js +22 -22
- package/dist/PlejdHbPlatform.js.map +1 -1
- package/dist/settings.d.ts +2 -6
- package/dist/settings.js +34 -26
- package/dist/settings.js.map +1 -1
- package/jest.config.js +20 -0
- package/package.json +6 -2
- package/tests/settings.spec.ts +59 -0
package/CHANGELOG.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from
|
2
|
-
import { PlejdHbAccessory } from
|
3
|
-
import { UserInputConfig } from
|
4
|
-
import { Device } from
|
5
|
-
import { PlejdService } from
|
6
|
-
import { Site } from
|
1
|
+
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from "homebridge";
|
2
|
+
import { PlejdHbAccessory } from "./PlejdHbAccessory.js";
|
3
|
+
import { UserInputConfig } from "./model/userInputConfig.js";
|
4
|
+
import { Device } from "./model/device.js";
|
5
|
+
import { PlejdService } from "./plejdService.js";
|
6
|
+
import { Site } from "./model/plejdSite.js";
|
7
7
|
export declare class PlejdHbPlatform implements DynamicPlatformPlugin {
|
8
8
|
readonly log: Logger;
|
9
9
|
readonly config: PlatformConfig;
|
package/dist/PlejdHbPlatform.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
import {
|
2
|
-
import { PlejdHbAccessory } from
|
3
|
-
import { PlejdService } from
|
4
|
-
import PlejdRemoteApi from
|
1
|
+
import { isAddon, isDimmable, PLATFORM_NAME, PLUGIN_NAME } from "./settings.js";
|
2
|
+
import { PlejdHbAccessory } from "./PlejdHbAccessory.js";
|
3
|
+
import { PlejdService } from "./plejdService.js";
|
4
|
+
import PlejdRemoteApi from "./plejdApi.js";
|
5
5
|
export class PlejdHbPlatform {
|
6
6
|
log;
|
7
7
|
config;
|
@@ -17,14 +17,14 @@ export class PlejdHbPlatform {
|
|
17
17
|
this.log = log;
|
18
18
|
this.config = config;
|
19
19
|
this.homebridgeApi = homebridgeApi;
|
20
|
-
homebridgeApi.on(
|
20
|
+
homebridgeApi.on("didFinishLaunching", this.configurePlejd);
|
21
21
|
this.Characteristic = homebridgeApi.hap.Characteristic;
|
22
22
|
this.Service = homebridgeApi.hap.Service;
|
23
23
|
}
|
24
24
|
configurePlejd = async () => {
|
25
25
|
if (this.config.password && this.config.site && this.config.username) {
|
26
|
-
this.log.info(
|
27
|
-
|
26
|
+
this.log.info("Using login information to fetch devices & crypto key\n" +
|
27
|
+
"Any devices added manually will override the remote site information");
|
28
28
|
const pApi = new PlejdRemoteApi(this.log, this.config.site, this.config.username, this.config.password, true);
|
29
29
|
const site = await pApi.getPlejdRemoteSite();
|
30
30
|
this.configureDevices(this.log, this.config, site);
|
@@ -32,11 +32,11 @@ export class PlejdHbPlatform {
|
|
32
32
|
else if (this.config.crypto_key &&
|
33
33
|
this.config.devices &&
|
34
34
|
this.config.devices.count > 0) {
|
35
|
-
this.log.info(
|
35
|
+
this.log.info("Using supplied crypto key & devices");
|
36
36
|
this.configureDevices(this.log, this.config, undefined);
|
37
37
|
}
|
38
38
|
else {
|
39
|
-
this.log.warn(
|
39
|
+
this.log.warn("No settings are prepared, either supply crypto key & devices OR username, password & site");
|
40
40
|
}
|
41
41
|
};
|
42
42
|
configureDevices = (log, config, site) => {
|
@@ -50,12 +50,12 @@ export class PlejdHbPlatform {
|
|
50
50
|
const id = item.deviceId;
|
51
51
|
const e = site.plejdDevices.find((x) => x.deviceId === id);
|
52
52
|
const dim = e.firmware.notes;
|
53
|
-
if (
|
53
|
+
if (isAddon(dim)) {
|
54
54
|
return;
|
55
55
|
}
|
56
56
|
const room = site.rooms.find((x) => x.roomId === item.roomId);
|
57
57
|
let identifier = site.inputAddress[id][0];
|
58
|
-
if (dim.endsWith(
|
58
|
+
if (dim.endsWith("-02") &&
|
59
59
|
items.find((a) => a.identifier === identifier) !== undefined) {
|
60
60
|
identifier += 1;
|
61
61
|
}
|
@@ -63,7 +63,7 @@ export class PlejdHbPlatform {
|
|
63
63
|
name: name,
|
64
64
|
model: dim,
|
65
65
|
identifier: identifier,
|
66
|
-
isDimmer:
|
66
|
+
isDimmer: isDimmable(dim),
|
67
67
|
uuid: this.generateId(identifier.toString()),
|
68
68
|
room: room?.title,
|
69
69
|
hidden: false,
|
@@ -74,7 +74,7 @@ export class PlejdHbPlatform {
|
|
74
74
|
const pre = devices.findIndex((x) => x.identifier === item.identifier);
|
75
75
|
if (pre !== -1) {
|
76
76
|
if (devices[pre].hidden) {
|
77
|
-
log.debug(
|
77
|
+
log.debug("Hiding device |", devices[pre]);
|
78
78
|
devices.splice(pre);
|
79
79
|
}
|
80
80
|
else {
|
@@ -88,28 +88,28 @@ export class PlejdHbPlatform {
|
|
88
88
|
}
|
89
89
|
for (let i = 0; i < devices.length; i++) {
|
90
90
|
if (devices[i].model) {
|
91
|
-
devices[i].isDimmer =
|
91
|
+
devices[i].isDimmer = isDimmable(devices[i].model);
|
92
92
|
}
|
93
93
|
else {
|
94
|
-
log.error(
|
94
|
+
log.error("Missing device model |", devices[i].name);
|
95
95
|
}
|
96
96
|
if (devices[i].identifier) {
|
97
97
|
devices[i].uuid = this.generateId(devices[i].identifier.toString());
|
98
98
|
}
|
99
99
|
else {
|
100
|
-
log.error(
|
100
|
+
log.error("Missing device identifier |", devices[i].name);
|
101
101
|
}
|
102
102
|
}
|
103
103
|
if (!config.crypto_key) {
|
104
|
-
log.error(
|
104
|
+
log.error("No Crypto key was found in the configuration. Check the plugin documentation for more info");
|
105
105
|
}
|
106
|
-
const cryptoKey = Buffer.from(config.crypto_key.replace(/-/g,
|
106
|
+
const cryptoKey = Buffer.from(config.crypto_key.replace(/-/g, ""), "hex");
|
107
107
|
this.userInputConfig = {
|
108
108
|
devices: devices,
|
109
109
|
cryptoKey: cryptoKey,
|
110
110
|
};
|
111
|
-
log.debug(
|
112
|
-
log.debug(
|
111
|
+
log.debug("Plejd Crypto Key:", config.crypto_key);
|
112
|
+
log.debug("Plejd Devices connected to HomeKit:", this.userInputConfig.devices);
|
113
113
|
this.plejdService = new PlejdService(this.userInputConfig, log, this.onPlejdUpdates.bind(this));
|
114
114
|
this.plejdService.configureBLE();
|
115
115
|
this.discoverDevices();
|
@@ -166,11 +166,11 @@ export class PlejdHbPlatform {
|
|
166
166
|
if (device.isDimmer) {
|
167
167
|
const ser = existingAccessory.getService(this.Service.Lightbulb);
|
168
168
|
if (!ser) {
|
169
|
-
this.log.warn(
|
169
|
+
this.log.warn("Unable to get service");
|
170
170
|
}
|
171
171
|
const on = ser?.getCharacteristic(this.Characteristic.On);
|
172
172
|
if (!on) {
|
173
|
-
this.log.warn(
|
173
|
+
this.log.warn("Unable to get Characteristic [On]");
|
174
174
|
}
|
175
175
|
on?.updateValue(isOn);
|
176
176
|
if (brightness !== undefined) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PlejdHbPlatform.js","sourceRoot":"","sources":["../src/PlejdHbPlatform.ts"],"names":[],"mappings":"AAUA,OAAO,
|
1
|
+
{"version":3,"file":"PlejdHbPlatform.js","sourceRoot":"","sources":["../src/PlejdHbPlatform.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,cAAc,MAAM,eAAe,CAAC;AAG3C,MAAM,OAAO,eAAe;IAaR;IACA;IACA;IAdF,OAAO,CAAiB;IACxB,cAAc,CAAwB;IAE/C,eAAe,CAAmB;IAClC,YAAY,CAAgB;IAEnC,oDAAoD;IACpC,WAAW,GAAwB,EAAE,CAAC;IAEtC,kBAAkB,GAAuB,EAAE,CAAC;IAE5D,YACkB,GAAW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AC,IAAI,EAAE,UAAU,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBAC1B,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACrD,CAAC,CAAC;CACH"}
|
package/dist/settings.d.ts
CHANGED
@@ -8,9 +8,5 @@ export declare const PLATFORM_NAME = "Plejd";
|
|
8
8
|
export declare const PLUGIN_NAME = "homebridge-plejd";
|
9
9
|
export declare const PLEJD_WRITE_TIMEOUT = 200;
|
10
10
|
export declare const PLEJD_PING_TIMEOUT = 3000;
|
11
|
-
|
12
|
-
|
13
|
-
*/
|
14
|
-
export declare const PLEJD_LIGHTS: string[];
|
15
|
-
export declare const PLEJD_SWITCHES: string[];
|
16
|
-
export declare const PLEJD_ADDONS: string[];
|
11
|
+
export declare const isDimmable: (type: string) => boolean;
|
12
|
+
export declare const isAddon: (type: string) => boolean;
|
package/dist/settings.js
CHANGED
@@ -1,39 +1,47 @@
|
|
1
1
|
/**
|
2
2
|
* This is the name of the platform that users will use to register the plugin in the Homebridge config.json
|
3
3
|
*/
|
4
|
-
export const PLATFORM_NAME =
|
4
|
+
export const PLATFORM_NAME = "Plejd";
|
5
5
|
/**
|
6
6
|
* This must match the name of your plugin as defined the package.json
|
7
7
|
*/
|
8
|
-
export const PLUGIN_NAME =
|
8
|
+
export const PLUGIN_NAME = "homebridge-plejd";
|
9
9
|
export const PLEJD_WRITE_TIMEOUT = 200;
|
10
10
|
export const PLEJD_PING_TIMEOUT = 3000;
|
11
|
+
export const isDimmable = (type) => {
|
12
|
+
const normalizedType = type.toLowerCase();
|
13
|
+
// Check if the model starts with any of the basic dimmer types
|
14
|
+
return PLEJD_LIGHTS.some((light) => normalizedType.startsWith(light.toLowerCase()) ||
|
15
|
+
normalizedType.includes("dim"));
|
16
|
+
};
|
17
|
+
export const isAddon = (type) => {
|
18
|
+
for (const x of PLEJD_ADDONS) {
|
19
|
+
if (type.toLowerCase().includes(x.toLowerCase())) {
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return false;
|
24
|
+
};
|
11
25
|
/**
|
12
26
|
* Lights and switches from Plejd
|
13
27
|
*/
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
'WRT-01',
|
33
|
-
'MNT-01',
|
34
|
-
'MNT-02',
|
35
|
-
'GWY-01',
|
36
|
-
'BAT-01',
|
37
|
-
'EXT-01',
|
28
|
+
const PLEJD_LIGHTS = ["DIM-01", "DIM-02", "LED-10", "DIM-01-2P", "LED-75"];
|
29
|
+
// const PLEJD_SWITCHES = [
|
30
|
+
// "REL-01",
|
31
|
+
// "REL-02",
|
32
|
+
// "REL-01-2P",
|
33
|
+
// "DAL-01",
|
34
|
+
// "SPR-01",
|
35
|
+
// "CTR-01",
|
36
|
+
// ];
|
37
|
+
const PLEJD_ADDONS = [
|
38
|
+
"RTR-01",
|
39
|
+
"WPH-01",
|
40
|
+
"WRT-01",
|
41
|
+
"MNT-01",
|
42
|
+
"MNT-02",
|
43
|
+
"GWY-01",
|
44
|
+
"BAT-01",
|
45
|
+
"EXT-01",
|
38
46
|
];
|
39
47
|
//# sourceMappingURL=settings.js.map
|
package/dist/settings.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAAA;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,CAAC,CAAC;AAE3E,2BAA2B;AAC3B,cAAc;AACd,cAAc;AACd,iBAAiB;AACjB,cAAc;AACd,cAAc;AACd,cAAc;AACd,KAAK;AAEL,MAAM,YAAY,GAAG;IACnB,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,QAAQ;CACT,CAAC"}
|
package/jest.config.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
export default {
|
2
|
+
transform: { "^.+\\.ts?$": "ts-jest" },
|
3
|
+
preset: "ts-jest",
|
4
|
+
testEnvironment: "node",
|
5
|
+
testPathIgnorePatterns: ["/node_modules/", ".next", "dist", "supabase"],
|
6
|
+
coverageDirectory: "./coverage",
|
7
|
+
coveragePathIgnorePatterns: [
|
8
|
+
"node_modules",
|
9
|
+
"tests",
|
10
|
+
"src/generated",
|
11
|
+
"dist",
|
12
|
+
"**/*/**.spec*",
|
13
|
+
],
|
14
|
+
rootDir: ".",
|
15
|
+
moduleNameMapper: {
|
16
|
+
"^src/(.*)": "<rootDir>/src/$1",
|
17
|
+
"^dto/(.*)": "<rootDir>/dto/$1",
|
18
|
+
"^dto$": "<rootDir>/dto",
|
19
|
+
},
|
20
|
+
};
|
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"displayName": "Plejd",
|
4
4
|
"name": "homebridge-plejd",
|
5
5
|
"author": "Herlix",
|
6
|
-
"version": "1.
|
6
|
+
"version": "1.6.1",
|
7
7
|
"description": "HomeKit support for the Plejd BLE platform using Homebridge",
|
8
8
|
"license": "Apache-2.0",
|
9
9
|
"type": "module",
|
@@ -23,7 +23,8 @@
|
|
23
23
|
"lint": "eslint src/**.ts --max-warnings=0",
|
24
24
|
"watch": "npm run build && npm link && nodemon",
|
25
25
|
"build": "rimraf ./dist && tsc",
|
26
|
-
"prepublishOnly": "npm run lint && npm run build"
|
26
|
+
"prepublishOnly": "npm run lint && npm run build",
|
27
|
+
"test": "jest ./**/*.spec.* --detectOpenHandles --forceExit --silent=false --runInBand"
|
27
28
|
},
|
28
29
|
"keywords": [
|
29
30
|
"homebridge-plugin",
|
@@ -35,6 +36,7 @@
|
|
35
36
|
"devDependencies": {
|
36
37
|
"@eslint/js": "^9.9.0",
|
37
38
|
"@types/eslint": "^9.6.0",
|
39
|
+
"@types/jest": "^29.5.14",
|
38
40
|
"@types/noble": "^0.0.44",
|
39
41
|
"@types/node": "^22.2.0",
|
40
42
|
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
@@ -43,8 +45,10 @@
|
|
43
45
|
"eslint-config-prettier": "^9.1.0",
|
44
46
|
"globals": "^15.9.0",
|
45
47
|
"homebridge": "^1.8.4",
|
48
|
+
"jest": "^29.7.0",
|
46
49
|
"nodemon": "^3.1.4",
|
47
50
|
"rimraf": "^6.0.1",
|
51
|
+
"ts-jest": "^29.2.5",
|
48
52
|
"ts-node": "^10.9.2",
|
49
53
|
"typescript": "^5.5.4",
|
50
54
|
"typescript-eslint": "^8.1.0"
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { isDimmable, isAddon } from "../src/settings";
|
2
|
+
|
3
|
+
describe("Device Type Detection", () => {
|
4
|
+
describe("isDimmable", () => {
|
5
|
+
const testCases = [
|
6
|
+
{ model: "DIM-01", expected: true },
|
7
|
+
{ model: "DIM-02", expected: true },
|
8
|
+
{ model: "LED-10", expected: true },
|
9
|
+
{ model: "DIM-01-2P", expected: true },
|
10
|
+
{ model: "LED-75", expected: true },
|
11
|
+
{ model: "DIM-02-LC 2024 Q2", expected: true },
|
12
|
+
{ model: "Dim 2.2.1 Release Candidate", expected: true },
|
13
|
+
{ model: "RTR-01", expected: false },
|
14
|
+
{ model: "WPH-01", expected: false },
|
15
|
+
{ model: "UNKNOWN-MODEL", expected: false },
|
16
|
+
];
|
17
|
+
|
18
|
+
testCases.forEach(({ model, expected }) => {
|
19
|
+
it(`should identify ${model} as ${expected ? "dimmable" : "non-dimmable"}`, () => {
|
20
|
+
expect(isDimmable(model)).toBe(expected);
|
21
|
+
});
|
22
|
+
});
|
23
|
+
|
24
|
+
// Test with real-world data
|
25
|
+
const realWorldDimmers = [
|
26
|
+
"DIM-02-LC 2024 Q2",
|
27
|
+
"Dim 2.2.1 Release Candidate",
|
28
|
+
"DIM-02",
|
29
|
+
"DIM-01",
|
30
|
+
];
|
31
|
+
|
32
|
+
realWorldDimmers.forEach((model) => {
|
33
|
+
it(`should identify real-world model ${model} as dimmable`, () => {
|
34
|
+
expect(isDimmable(model)).toBe(true);
|
35
|
+
});
|
36
|
+
});
|
37
|
+
});
|
38
|
+
|
39
|
+
describe("isAddon", () => {
|
40
|
+
const testCases = [
|
41
|
+
{ model: "RTR-01", expected: true },
|
42
|
+
{ model: "WPH-01", expected: true },
|
43
|
+
{ model: "WRT-01", expected: true },
|
44
|
+
{ model: "MNT-01", expected: true },
|
45
|
+
{ model: "MNT-02", expected: true },
|
46
|
+
{ model: "GWY-01", expected: true },
|
47
|
+
{ model: "BAT-01", expected: true },
|
48
|
+
{ model: "EXT-01", expected: true },
|
49
|
+
{ model: "DIM-01", expected: false },
|
50
|
+
{ model: "UNKNOWN-MODEL", expected: false },
|
51
|
+
];
|
52
|
+
|
53
|
+
testCases.forEach(({ model, expected }) => {
|
54
|
+
it(`should identify ${model} as ${expected ? "addon" : "non-addon"}`, () => {
|
55
|
+
expect(isAddon(model)).toBe(expected);
|
56
|
+
});
|
57
|
+
});
|
58
|
+
});
|
59
|
+
});
|