homebridge-nanoleaf-multi 2.2.0 → 2.3.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/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +0 -13
- package/dist/platformFactory.d.ts +2 -1
- package/dist/types/devices/DeviceConfiguration.d.ts +1 -1
- package/package.json +2 -1
- package/src/Device.ts +44 -2
- package/src/platformFactory.ts +5 -11
- package/src/types/devices/DeviceConfiguration.ts +1 -1
|
@@ -2,16 +2,3 @@
|
|
|
2
2
|
* Author: Alberto La Rocca <a71104@gmail.com> (https://github.com/71104)
|
|
3
3
|
* Released under the MIT license
|
|
4
4
|
* Copyright (c) 2015 Alberto La Rocca */
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @license
|
|
8
|
-
* Lodash <https://lodash.com/>
|
|
9
|
-
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
10
|
-
* Released under MIT license <https://lodash.com/license>
|
|
11
|
-
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
12
|
-
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
//! moment.js
|
|
16
|
-
|
|
17
|
-
//! moment.js locale configuration
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Logger } from 'simple-node-logger';
|
|
1
2
|
import { PlatformConfiguration, Context } from './types';
|
|
2
3
|
import { Zone } from './Zone';
|
|
3
4
|
declare const _default: (homebridge: any) => {
|
|
4
|
-
new (
|
|
5
|
+
new (log: Logger, configuration: PlatformConfiguration): {
|
|
5
6
|
context: Context;
|
|
6
7
|
zones: Map<string, Zone>;
|
|
7
8
|
readonly allEffects: import("./Effect").Effect<any>[];
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"keywords": [
|
|
6
6
|
"homebridge-plugin"
|
|
7
7
|
],
|
|
8
|
-
"version": "2.
|
|
8
|
+
"version": "2.3.0",
|
|
9
9
|
"deprecated": false,
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "Samuel Goodell"
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@types/node": "^18.7.14",
|
|
48
48
|
"@types/rwlock": "^5.0.3",
|
|
49
49
|
"babel-loader": "^8.2.5",
|
|
50
|
+
"prettier": "^3.0.2",
|
|
50
51
|
"ts-loader": "^9.3.1",
|
|
51
52
|
"typescript": "^4.8.2",
|
|
52
53
|
"webpack-cli": "^4.10.0"
|
package/src/Device.ts
CHANGED
|
@@ -25,13 +25,55 @@ export class Device {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
public async initialize() {
|
|
28
|
+
this.context.log.debug(`Initializing <${this.name}>...`);
|
|
29
|
+
|
|
28
30
|
const ip = await lookupHost(this.configuration.host);
|
|
29
31
|
|
|
30
|
-
this.
|
|
32
|
+
this.context.log.debug(`Initializing <${this.name}> at IP ${ip}...`);
|
|
33
|
+
|
|
34
|
+
this.nanoleafClient = new NanoleafClient(ip);
|
|
35
|
+
|
|
36
|
+
if (this.configuration.token) {
|
|
37
|
+
this.context.log.debug(
|
|
38
|
+
`Initializing <${this.name}> with configured token...`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
this.nanoleafClient.authorize(this.configuration.token);
|
|
42
|
+
} else {
|
|
43
|
+
this.context.log.warn(
|
|
44
|
+
`Device <${this.name}> has no token configured, press and hold the power button on it for 5 seconds to authorize it and then copy the token into the plugin configuration!`
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
let token: string = null;
|
|
48
|
+
|
|
49
|
+
while (!token) {
|
|
50
|
+
this.context.log.debug(`Requesting token from <${this.name}>...`);
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
token = await this.nanoleafClient.authorize();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
this.context.log.debug(
|
|
56
|
+
`No token was authorized from <${this.name}>, will try again in 10 seconds`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await new Promise((resolve, reject) => setTimeout(resolve, 10 * 1000));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.nanoleafClient.authorize(token);
|
|
64
|
+
|
|
65
|
+
this.context.log.warn(
|
|
66
|
+
`Device <${this.name}> authorized a new token. Copy this into your configuration to avoid re-authorizing when the plugin restarts!`
|
|
67
|
+
);
|
|
68
|
+
this.context.log.info(`Token for device <${this.name}>: ${token}`);
|
|
69
|
+
this.context.log.debug(
|
|
70
|
+
`Initializing <${this.name}> with manually authorized token...`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
31
73
|
|
|
32
74
|
const deviceInfo = await this.nanoleafClient.getInfo();
|
|
33
75
|
|
|
34
|
-
this.context.log.info(`Initialized <${this.
|
|
76
|
+
this.context.log.info(`Initialized <${this.name}>`);
|
|
35
77
|
this.initialized = true;
|
|
36
78
|
}
|
|
37
79
|
|
package/src/platformFactory.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HomebridgeLogAppender } from 'helpers-for-homebridge';
|
|
1
|
+
import { Logger } from 'simple-node-logger';
|
|
3
2
|
import { Palette } from '@manganese/palette-kit-core';
|
|
4
3
|
import { PaletteClient } from '@manganese/palette-kit-client';
|
|
5
4
|
|
|
@@ -19,15 +18,10 @@ export default (homebridge: any) => {
|
|
|
19
18
|
);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
constructor(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
appenders: [new HomebridgeLogAppender(homebridgeLog)],
|
|
27
|
-
}),
|
|
28
|
-
],
|
|
29
|
-
});
|
|
30
|
-
|
|
21
|
+
constructor(
|
|
22
|
+
log: Logger,
|
|
23
|
+
readonly configuration: PlatformConfiguration
|
|
24
|
+
) {
|
|
31
25
|
const palette = new Palette({}, { log });
|
|
32
26
|
palette.onAnyColorChange((event) => {
|
|
33
27
|
this.allEffects.forEach((effect) => {
|