hap-nodejs 1.0.0-alpha.3 → 1.0.0-alpha.31
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/README.md +1 -0
- package/dist/BridgedCore.d.ts +2 -0
- package/dist/BridgedCore.d.ts.map +1 -0
- package/dist/BridgedCore.js +42 -0
- package/dist/BridgedCore.js.map +1 -0
- package/dist/Core.d.ts +2 -0
- package/dist/Core.d.ts.map +1 -0
- package/dist/Core.js +49 -0
- package/dist/Core.js.map +1 -0
- package/dist/accessories/AirConditioner_accessory.js +24 -24
- package/dist/accessories/AirConditioner_accessory.js.map +1 -1
- package/dist/accessories/AppleTVRemote_accessory.js +23 -23
- package/dist/accessories/AppleTVRemote_accessory.js.map +1 -1
- package/dist/accessories/Camera_accessory.js +292 -373
- package/dist/accessories/Camera_accessory.js.map +1 -1
- package/dist/accessories/Fan_accessory.js +15 -21
- package/dist/accessories/Fan_accessory.js.map +1 -1
- package/dist/accessories/GarageDoorOpener_accessory.js +12 -12
- package/dist/accessories/GarageDoorOpener_accessory.js.map +1 -1
- package/dist/accessories/Light-AdaptiveLighting_accessory.js +26 -26
- package/dist/accessories/Light-AdaptiveLighting_accessory.js.map +1 -1
- package/dist/accessories/Light_accessory.js +45 -48
- package/dist/accessories/Light_accessory.js.map +1 -1
- package/dist/accessories/Lock_accessory.js +11 -11
- package/dist/accessories/Lock_accessory.js.map +1 -1
- package/dist/accessories/MotionSensor_accessory.js +8 -8
- package/dist/accessories/MotionSensor_accessory.js.map +1 -1
- package/dist/accessories/Outlet_accessory.js +10 -10
- package/dist/accessories/Outlet_accessory.js.map +1 -1
- package/dist/accessories/SmartSpeaker_accessory.js +11 -11
- package/dist/accessories/SmartSpeaker_accessory.js.map +1 -1
- package/dist/accessories/Sprinkler_accessory.js +19 -19
- package/dist/accessories/Sprinkler_accessory.js.map +1 -1
- package/dist/accessories/TV_accessory.js +17 -17
- package/dist/accessories/TV_accessory.js.map +1 -1
- package/dist/accessories/TemperatureSensor_accessory.js +6 -6
- package/dist/accessories/TemperatureSensor_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiRouter_accessory.js +3 -3
- package/dist/accessories/Wi-FiRouter_accessory.js.map +1 -1
- package/dist/accessories/Wi-FiSatellite_accessory.js +4 -4
- package/dist/accessories/Wi-FiSatellite_accessory.js.map +1 -1
- package/dist/accessories/gstreamer-audioProducer.js +36 -47
- package/dist/accessories/gstreamer-audioProducer.js.map +1 -1
- package/dist/accessories/types.js +2 -2
- package/dist/accessories/types.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +780 -1093
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/AccessoryLoader.js +40 -40
- package/dist/lib/AccessoryLoader.js.map +1 -1
- package/dist/lib/Advertiser.js +392 -524
- package/dist/lib/Advertiser.js.map +1 -1
- package/dist/lib/Bridge.js +6 -10
- package/dist/lib/Bridge.js.map +1 -1
- package/dist/lib/Characteristic.js +1395 -498
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.js +215 -265
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.js +486 -322
- package/dist/lib/Service.js.map +1 -1
- package/dist/lib/camera/Camera.js +14 -14
- package/dist/lib/camera/Camera.js.map +1 -1
- package/dist/lib/camera/RTPProxy.js +112 -104
- package/dist/lib/camera/RTPProxy.js.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +284 -257
- package/dist/lib/camera/RTPStreamManagement.js.map +1 -1
- package/dist/lib/camera/RecordingManagement.js +318 -381
- package/dist/lib/camera/RecordingManagement.js.map +1 -1
- package/dist/lib/camera/index.js +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +198 -209
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.js +190 -249
- package/dist/lib/controller/CameraController.js.map +1 -1
- package/dist/lib/controller/DoorbellController.js +38 -39
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/controller/RemoteController.js +343 -401
- package/dist/lib/controller/RemoteController.js.map +1 -1
- package/dist/lib/controller/index.js +1 -1
- package/dist/lib/datastream/DataStreamManagement.js +56 -57
- package/dist/lib/datastream/DataStreamManagement.js.map +1 -1
- package/dist/lib/datastream/DataStreamParser.js +259 -304
- package/dist/lib/datastream/DataStreamParser.js.map +1 -1
- package/dist/lib/datastream/DataStreamServer.d.ts.map +1 -1
- package/dist/lib/datastream/DataStreamServer.js +252 -269
- package/dist/lib/datastream/DataStreamServer.js.map +1 -1
- package/dist/lib/datastream/index.js +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +1984 -2708
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +818 -1035
- package/dist/lib/definitions/ServiceDefinitions.js.map +1 -1
- package/dist/lib/definitions/generate-definitions.js +383 -679
- package/dist/lib/definitions/generate-definitions.js.map +1 -1
- package/dist/lib/definitions/generator-configuration.js +29 -29
- package/dist/lib/definitions/generator-configuration.js.map +1 -1
- package/dist/lib/definitions/index.js +1 -1
- package/dist/lib/model/AccessoryInfo.js +101 -136
- package/dist/lib/model/AccessoryInfo.js.map +1 -1
- package/dist/lib/model/ControllerStorage.js +86 -89
- package/dist/lib/model/ControllerStorage.js.map +1 -1
- package/dist/lib/model/HAPStorage.js +15 -16
- package/dist/lib/model/HAPStorage.js.map +1 -1
- package/dist/lib/model/IdentifierCache.js +49 -49
- package/dist/lib/model/IdentifierCache.js.map +1 -1
- package/dist/lib/tv/AccessControlManagement.js +40 -44
- package/dist/lib/tv/AccessControlManagement.js.map +1 -1
- package/dist/lib/util/checkName.d.ts +2 -1
- package/dist/lib/util/checkName.d.ts.map +1 -1
- package/dist/lib/util/checkName.js +7 -11
- package/dist/lib/util/checkName.js.map +1 -1
- package/dist/lib/util/clone.js +5 -27
- package/dist/lib/util/clone.js.map +1 -1
- package/dist/lib/util/color-utils.js +8 -12
- package/dist/lib/util/color-utils.js.map +1 -1
- package/dist/lib/util/eventedhttp.d.ts.map +1 -1
- package/dist/lib/util/eventedhttp.js +309 -386
- package/dist/lib/util/eventedhttp.js.map +1 -1
- package/dist/lib/util/hapCrypto.js +31 -32
- package/dist/lib/util/hapCrypto.js.map +1 -1
- package/dist/lib/util/hapStatusError.js +9 -12
- package/dist/lib/util/hapStatusError.js.map +1 -1
- package/dist/lib/util/net-utils.js +32 -53
- package/dist/lib/util/net-utils.js.map +1 -1
- package/dist/lib/util/once.js +3 -8
- package/dist/lib/util/once.js.map +1 -1
- package/dist/lib/util/promise-utils.js +8 -13
- package/dist/lib/util/promise-utils.js.map +1 -1
- package/dist/lib/util/request-util.js +2 -3
- package/dist/lib/util/request-util.js.map +1 -1
- package/dist/lib/util/time.js +5 -5
- package/dist/lib/util/time.js.map +1 -1
- package/dist/lib/util/tlv.js +57 -75
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.js +15 -19
- package/dist/lib/util/uuid.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AdaptiveLightingController = exports.AdaptiveLightingControllerEvents = exports.AdaptiveLightingControllerMode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
6
|
+
const color_utils_1 = require("../util/color-utils");
|
|
7
|
+
const hapStatusError_1 = require("../util/hapStatusError");
|
|
8
|
+
const time_1 = require("../util/time");
|
|
9
|
+
const uuid = tslib_1.__importStar(require("../util/uuid"));
|
|
10
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
|
+
const events_1 = require("events");
|
|
12
|
+
const Characteristic_1 = require("../Characteristic");
|
|
13
|
+
const tlv = tslib_1.__importStar(require("../util/tlv"));
|
|
14
|
+
const debug = (0, debug_1.default)("HAP-NodeJS:Controller:TransitionControl");
|
|
15
15
|
var SupportedCharacteristicValueTransitionConfigurationsTypes;
|
|
16
16
|
(function (SupportedCharacteristicValueTransitionConfigurationsTypes) {
|
|
17
17
|
SupportedCharacteristicValueTransitionConfigurationsTypes[SupportedCharacteristicValueTransitionConfigurationsTypes["SUPPORTED_TRANSITION_CONFIGURATION"] = 1] = "SUPPORTED_TRANSITION_CONFIGURATION";
|
|
@@ -222,8 +222,28 @@ var AdaptiveLightingControllerEvents;
|
|
|
222
222
|
* @group Adaptive Lighting
|
|
223
223
|
*/
|
|
224
224
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
class AdaptiveLightingController extends events_1.EventEmitter {
|
|
226
|
+
stateChangeDelegate;
|
|
227
|
+
lightbulb;
|
|
228
|
+
mode;
|
|
229
|
+
customTemperatureAdjustment;
|
|
230
|
+
adjustmentFactorChangedListener;
|
|
231
|
+
characteristicManualWrittenChangeListener;
|
|
232
|
+
supportedTransitionConfiguration;
|
|
233
|
+
transitionControl;
|
|
234
|
+
activeTransitionCount;
|
|
235
|
+
colorTemperatureCharacteristic;
|
|
236
|
+
brightnessCharacteristic;
|
|
237
|
+
saturationCharacteristic;
|
|
238
|
+
hueCharacteristic;
|
|
239
|
+
activeTransition;
|
|
240
|
+
didRunFirstInitializationStep = false;
|
|
241
|
+
updateTimeout;
|
|
242
|
+
lastTransitionPointInfo;
|
|
243
|
+
lastEventNotificationSent = 0;
|
|
244
|
+
lastNotifiedTemperatureValue = 0;
|
|
245
|
+
lastNotifiedSaturationValue = 0;
|
|
246
|
+
lastNotifiedHueValue = 0;
|
|
227
247
|
/**
|
|
228
248
|
* Creates a new instance of the AdaptiveLightingController.
|
|
229
249
|
* Refer to the {@link AdaptiveLightingController} documentation on how to use it.
|
|
@@ -231,36 +251,29 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
231
251
|
* @param service - The lightbulb to which Adaptive Lighting support should be added.
|
|
232
252
|
* @param options - Optional options to define the operating mode (automatic vs manual).
|
|
233
253
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_this.mode = (_a = options === null || options === void 0 ? void 0 : options.controllerMode) !== null && _a !== void 0 ? _a : 1 /* AdaptiveLightingControllerMode.AUTOMATIC */;
|
|
244
|
-
_this.customTemperatureAdjustment = (_b = options === null || options === void 0 ? void 0 : options.customTemperatureAdjustment) !== null && _b !== void 0 ? _b : 0;
|
|
245
|
-
(0, assert_1.default)(_this.lightbulb.testCharacteristic(Characteristic_1.Characteristic.ColorTemperature), "Lightbulb must have the ColorTemperature characteristic added!");
|
|
246
|
-
(0, assert_1.default)(_this.lightbulb.testCharacteristic(Characteristic_1.Characteristic.Brightness), "Lightbulb must have the Brightness characteristic added!");
|
|
247
|
-
_this.adjustmentFactorChangedListener = _this.handleAdjustmentFactorChanged.bind(_this);
|
|
248
|
-
_this.characteristicManualWrittenChangeListener = _this.handleCharacteristicManualWritten.bind(_this);
|
|
249
|
-
return _this;
|
|
254
|
+
constructor(service, options) {
|
|
255
|
+
super();
|
|
256
|
+
this.lightbulb = service;
|
|
257
|
+
this.mode = options?.controllerMode ?? 1 /* AdaptiveLightingControllerMode.AUTOMATIC */;
|
|
258
|
+
this.customTemperatureAdjustment = options?.customTemperatureAdjustment ?? 0;
|
|
259
|
+
(0, assert_1.default)(this.lightbulb.testCharacteristic(Characteristic_1.Characteristic.ColorTemperature), "Lightbulb must have the ColorTemperature characteristic added!");
|
|
260
|
+
(0, assert_1.default)(this.lightbulb.testCharacteristic(Characteristic_1.Characteristic.Brightness), "Lightbulb must have the Brightness characteristic added!");
|
|
261
|
+
this.adjustmentFactorChangedListener = this.handleAdjustmentFactorChanged.bind(this);
|
|
262
|
+
this.characteristicManualWrittenChangeListener = this.handleCharacteristicManualWritten.bind(this);
|
|
250
263
|
}
|
|
251
264
|
/**
|
|
252
265
|
* @private
|
|
253
266
|
*/
|
|
254
|
-
|
|
267
|
+
controllerId() {
|
|
255
268
|
return "characteristic-transition" /* DefaultControllerType.CHARACTERISTIC_TRANSITION */ + "-" + this.lightbulb.getServiceId();
|
|
256
|
-
}
|
|
269
|
+
}
|
|
257
270
|
// ----------- PUBLIC API START -----------
|
|
258
271
|
/**
|
|
259
272
|
* Returns if a Adaptive Lighting transition is currently active.
|
|
260
273
|
*/
|
|
261
|
-
|
|
274
|
+
isAdaptiveLightingActive() {
|
|
262
275
|
return !!this.activeTransition;
|
|
263
|
-
}
|
|
276
|
+
}
|
|
264
277
|
/**
|
|
265
278
|
* This method can be called to manually disable the current active Adaptive Lighting transition.
|
|
266
279
|
* When using {@link AdaptiveLightingControllerMode.AUTOMATIC} you won't need to call this method.
|
|
@@ -268,19 +281,18 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
268
281
|
* This is the case when the user manually changes the value of Hue, Saturation or ColorTemperature characteristics
|
|
269
282
|
* (or if any of those values is changed by physical interaction with the lightbulb).
|
|
270
283
|
*/
|
|
271
|
-
|
|
272
|
-
var _a, _b, _c, _d, _e, _f;
|
|
284
|
+
disableAdaptiveLighting() {
|
|
273
285
|
if (this.updateTimeout) {
|
|
274
286
|
clearTimeout(this.updateTimeout);
|
|
275
287
|
this.updateTimeout = undefined;
|
|
276
288
|
}
|
|
277
289
|
if (this.activeTransition) {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
290
|
+
this.colorTemperatureCharacteristic?.removeListener("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
291
|
+
this.brightnessCharacteristic?.removeListener("change" /* CharacteristicEventTypes.CHANGE */, this.adjustmentFactorChangedListener);
|
|
292
|
+
this.hueCharacteristic?.removeListener("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
293
|
+
this.saturationCharacteristic?.removeListener("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
282
294
|
this.activeTransition = undefined;
|
|
283
|
-
|
|
295
|
+
this.stateChangeDelegate?.();
|
|
284
296
|
}
|
|
285
297
|
this.colorTemperatureCharacteristic = undefined;
|
|
286
298
|
this.brightnessCharacteristic = undefined;
|
|
@@ -292,20 +304,20 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
292
304
|
this.lastNotifiedSaturationValue = 0;
|
|
293
305
|
this.lastNotifiedHueValue = 0;
|
|
294
306
|
this.didRunFirstInitializationStep = false;
|
|
295
|
-
|
|
307
|
+
this.activeTransitionCount?.sendEventNotification(0);
|
|
296
308
|
debug("[%s] Disabling adaptive lighting", this.lightbulb.displayName);
|
|
297
|
-
}
|
|
309
|
+
}
|
|
298
310
|
/**
|
|
299
311
|
* Returns the time where the current transition curve was started in epoch time millis.
|
|
300
312
|
* A transition curves is active for 24 hours typically and is renewed every 24 hours by a HomeHub.
|
|
301
313
|
* Additionally see {@link getAdaptiveLightingTimeOffset}.
|
|
302
314
|
*/
|
|
303
|
-
|
|
315
|
+
getAdaptiveLightingStartTimeOfTransition() {
|
|
304
316
|
if (!this.activeTransition) {
|
|
305
317
|
throw new Error("There is no active transition!");
|
|
306
318
|
}
|
|
307
319
|
return this.activeTransition.transitionStartMillis;
|
|
308
|
-
}
|
|
320
|
+
}
|
|
309
321
|
/**
|
|
310
322
|
* It is not necessarily given, that we have the same time (or rather the correct time) as the HomeKit controller
|
|
311
323
|
* who set up the transition schedule.
|
|
@@ -314,24 +326,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
314
326
|
* So in the case were we actually have a correct local time, it most likely will be positive (due to network latency).
|
|
315
327
|
* But of course it can also be negative.
|
|
316
328
|
*/
|
|
317
|
-
|
|
329
|
+
getAdaptiveLightingTimeOffset() {
|
|
318
330
|
if (!this.activeTransition) {
|
|
319
331
|
throw new Error("There is no active transition!");
|
|
320
332
|
}
|
|
321
333
|
return this.activeTransition.timeMillisOffset;
|
|
322
|
-
}
|
|
323
|
-
|
|
334
|
+
}
|
|
335
|
+
getAdaptiveLightingTransitionCurve() {
|
|
324
336
|
if (!this.activeTransition) {
|
|
325
337
|
throw new Error("There is no active transition!");
|
|
326
338
|
}
|
|
327
339
|
return this.activeTransition.transitionCurve;
|
|
328
|
-
}
|
|
329
|
-
|
|
340
|
+
}
|
|
341
|
+
getAdaptiveLightingBrightnessMultiplierRange() {
|
|
330
342
|
if (!this.activeTransition) {
|
|
331
343
|
throw new Error("There is no active transition!");
|
|
332
344
|
}
|
|
333
345
|
return this.activeTransition.brightnessAdjustmentRange;
|
|
334
|
-
}
|
|
346
|
+
}
|
|
335
347
|
/**
|
|
336
348
|
* This method returns the interval (in milliseconds) in which the light should update its internal color temperature
|
|
337
349
|
* (aka changes it physical color).
|
|
@@ -339,12 +351,12 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
339
351
|
*
|
|
340
352
|
* Typically this evaluates to 60000 milliseconds (60 seconds).
|
|
341
353
|
*/
|
|
342
|
-
|
|
354
|
+
getAdaptiveLightingUpdateInterval() {
|
|
343
355
|
if (!this.activeTransition) {
|
|
344
356
|
throw new Error("There is no active transition!");
|
|
345
357
|
}
|
|
346
358
|
return this.activeTransition.updateInterval;
|
|
347
|
-
}
|
|
359
|
+
}
|
|
348
360
|
/**
|
|
349
361
|
* Returns the minimum interval threshold (in milliseconds) a accessory may notify HomeKit controllers about a new
|
|
350
362
|
* color temperature value via event notifications (what happens when you call {@link Characteristic.updateValue}).
|
|
@@ -352,16 +364,14 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
352
364
|
*
|
|
353
365
|
* Typically this evaluates to 600000 milliseconds (10 minutes).
|
|
354
366
|
*/
|
|
355
|
-
|
|
367
|
+
getAdaptiveLightingNotifyIntervalThreshold() {
|
|
356
368
|
if (!this.activeTransition) {
|
|
357
369
|
throw new Error("There is no active transition!");
|
|
358
370
|
}
|
|
359
371
|
return this.activeTransition.notifyIntervalThreshold;
|
|
360
|
-
}
|
|
372
|
+
}
|
|
361
373
|
// ----------- PUBLIC API END -----------
|
|
362
|
-
|
|
363
|
-
var _a;
|
|
364
|
-
if (calledFromDeserializer === void 0) { calledFromDeserializer = false; }
|
|
374
|
+
handleActiveTransitionUpdated(calledFromDeserializer = false) {
|
|
365
375
|
if (this.activeTransitionCount) {
|
|
366
376
|
if (!calledFromDeserializer) {
|
|
367
377
|
this.activeTransitionCount.sendEventNotification(1);
|
|
@@ -377,7 +387,7 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
377
387
|
if (!this.activeTransition) {
|
|
378
388
|
throw new Error("There is no active transition!");
|
|
379
389
|
}
|
|
380
|
-
|
|
390
|
+
const update = {
|
|
381
391
|
transitionStartMillis: this.activeTransition.transitionStartMillis,
|
|
382
392
|
timeMillisOffset: this.activeTransition.timeMillisOffset,
|
|
383
393
|
transitionCurve: this.activeTransition.transitionCurve,
|
|
@@ -391,10 +401,10 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
391
401
|
throw new Error("Unsupported adaptive lighting controller mode: " + this.mode);
|
|
392
402
|
}
|
|
393
403
|
if (!calledFromDeserializer) {
|
|
394
|
-
|
|
404
|
+
this.stateChangeDelegate?.();
|
|
395
405
|
}
|
|
396
|
-
}
|
|
397
|
-
|
|
406
|
+
}
|
|
407
|
+
handleAdaptiveLightingEnabled() {
|
|
398
408
|
if (!this.activeTransition) {
|
|
399
409
|
throw new Error("There is no active transition!");
|
|
400
410
|
}
|
|
@@ -410,15 +420,14 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
410
420
|
this.saturationCharacteristic = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.Saturation)
|
|
411
421
|
.on("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
412
422
|
}
|
|
413
|
-
}
|
|
414
|
-
|
|
423
|
+
}
|
|
424
|
+
handleAdaptiveLightingDisabled() {
|
|
415
425
|
if (this.mode === 2 /* AdaptiveLightingControllerMode.MANUAL */ && this.activeTransition) { // only emit the event if a transition is actually enabled
|
|
416
426
|
this.emit("disable" /* AdaptiveLightingControllerEvents.DISABLED */);
|
|
417
427
|
}
|
|
418
428
|
this.disableAdaptiveLighting();
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
var _this = this;
|
|
429
|
+
}
|
|
430
|
+
handleAdjustmentFactorChanged(change) {
|
|
422
431
|
if (change.newValue === change.oldValue) {
|
|
423
432
|
return;
|
|
424
433
|
}
|
|
@@ -435,24 +444,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
435
444
|
// if the reason is a read request, we expect that Hue/Saturation are also read
|
|
436
445
|
// thus we postpone our update to ColorTemperature a bit.
|
|
437
446
|
// It doesn't ensure that those race conditions do not happen anymore, but with a 1s delay it reduces the possibility by a bit
|
|
438
|
-
setTimeout(
|
|
439
|
-
if (!
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
if (!this.activeTransition) {
|
|
440
449
|
return; // was disabled in the mean time
|
|
441
450
|
}
|
|
442
|
-
|
|
451
|
+
this.scheduleNextUpdate(true);
|
|
443
452
|
}, 1000).unref();
|
|
444
453
|
}
|
|
445
454
|
else {
|
|
446
455
|
this.scheduleNextUpdate(true); // run a dry scheduleNextUpdate to adjust the colorTemperature using the new brightness value
|
|
447
456
|
}
|
|
448
|
-
}
|
|
457
|
+
}
|
|
449
458
|
/**
|
|
450
459
|
* This method is called when a change happens to the Hue/Saturation or ColorTemperature characteristic.
|
|
451
460
|
* When such a write happens (caused by the user changing the color/temperature) Adaptive Lighting must be disabled.
|
|
452
461
|
*
|
|
453
462
|
* @param change
|
|
454
463
|
*/
|
|
455
|
-
|
|
464
|
+
handleCharacteristicManualWritten(change) {
|
|
456
465
|
if (change.reason === "write" /* ChangeReason.WRITE */ && !(isAdaptiveLightingContext(change.context) && change.context.controller === this)) {
|
|
457
466
|
// we ignore write request which are the result of calls made to updateValue or sendEventNotification
|
|
458
467
|
// or the result of a changed value returned by a read handler
|
|
@@ -460,28 +469,27 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
460
469
|
debug("[%s] Received a manual write to an characteristic (newValue: %d, oldValue: %d, reason: %s). Thus disabling adaptive lighting!", this.lightbulb.displayName, change.newValue, change.oldValue, change.reason);
|
|
461
470
|
this.disableAdaptiveLighting();
|
|
462
471
|
}
|
|
463
|
-
}
|
|
472
|
+
}
|
|
464
473
|
/**
|
|
465
474
|
* Retrieve the {@link AdaptiveLightingTransitionPoint} for the current timestamp.
|
|
466
475
|
* Returns undefined if the current transition schedule reached its end.
|
|
467
476
|
*/
|
|
468
|
-
|
|
469
|
-
var _a, _b, _c, _d, _e;
|
|
477
|
+
getCurrentAdaptiveLightingTransitionPoint() {
|
|
470
478
|
if (!this.activeTransition) {
|
|
471
479
|
throw new Error("Cannot calculate current transition point if no transition is active!");
|
|
472
480
|
}
|
|
473
481
|
// adjustedNow is the now() date corrected to the time of the initiating controller
|
|
474
|
-
|
|
482
|
+
const adjustedNow = Date.now() - this.activeTransition.timeMillisOffset;
|
|
475
483
|
// "offset" since the start of the transition schedule
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
484
|
+
const offset = adjustedNow - this.activeTransition.transitionStartMillis;
|
|
485
|
+
let i = this.lastTransitionPointInfo?.curveIndex ?? 0;
|
|
486
|
+
let lowerBoundTimeOffset = this.lastTransitionPointInfo?.lowerBoundTimeOffset ?? 0; // time offset to the lowerBound transition entry
|
|
487
|
+
let lowerBound = undefined;
|
|
488
|
+
let upperBound = undefined;
|
|
481
489
|
for (; i + 1 < this.activeTransition.transitionCurve.length; i++) {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
490
|
+
const lowerBound0 = this.activeTransition.transitionCurve[i];
|
|
491
|
+
const upperBound0 = this.activeTransition.transitionCurve[i + 1];
|
|
492
|
+
const lowerBoundDuration = lowerBound0.duration ?? 0;
|
|
485
493
|
lowerBoundTimeOffset += lowerBound0.transitionTime;
|
|
486
494
|
if (offset >= lowerBoundTimeOffset) {
|
|
487
495
|
if (offset <= lowerBoundTimeOffset + lowerBoundDuration + upperBound0.transitionTime) {
|
|
@@ -516,11 +524,8 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
516
524
|
lowerBound: lowerBound,
|
|
517
525
|
upperBound: upperBound,
|
|
518
526
|
};
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
var _this = this;
|
|
522
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
523
|
-
if (dryRun === void 0) { dryRun = false; }
|
|
527
|
+
}
|
|
528
|
+
scheduleNextUpdate(dryRun = false) {
|
|
524
529
|
if (!this.activeTransition) {
|
|
525
530
|
throw new Error("tried scheduling transition when no transition was active!");
|
|
526
531
|
}
|
|
@@ -531,7 +536,7 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
531
536
|
this.didRunFirstInitializationStep = true;
|
|
532
537
|
this.handleAdaptiveLightingEnabled();
|
|
533
538
|
}
|
|
534
|
-
|
|
539
|
+
const transitionPoint = this.getCurrentAdaptiveLightingTransitionPoint();
|
|
535
540
|
if (!transitionPoint) {
|
|
536
541
|
debug("[%s] Reached end of transition curve!", this.lightbulb.displayName);
|
|
537
542
|
if (!dryRun) {
|
|
@@ -540,30 +545,30 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
540
545
|
}
|
|
541
546
|
return;
|
|
542
547
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
548
|
+
const lowerBound = transitionPoint.lowerBound;
|
|
549
|
+
const upperBound = transitionPoint.upperBound;
|
|
550
|
+
let interpolatedTemperature;
|
|
551
|
+
let interpolatedAdjustmentFactor;
|
|
547
552
|
if (lowerBound.duration && transitionPoint.transitionOffset <= lowerBound.duration) {
|
|
548
553
|
interpolatedTemperature = lowerBound.temperature;
|
|
549
554
|
interpolatedAdjustmentFactor = lowerBound.brightnessAdjustmentFactor;
|
|
550
555
|
}
|
|
551
556
|
else {
|
|
552
|
-
|
|
557
|
+
const timePercentage = (transitionPoint.transitionOffset - (lowerBound.duration ?? 0)) / upperBound.transitionTime;
|
|
553
558
|
interpolatedTemperature = lowerBound.temperature + (upperBound.temperature - lowerBound.temperature) * timePercentage;
|
|
554
559
|
interpolatedAdjustmentFactor = lowerBound.brightnessAdjustmentFactor
|
|
555
560
|
+ (upperBound.brightnessAdjustmentFactor - lowerBound.brightnessAdjustmentFactor) * timePercentage;
|
|
556
561
|
}
|
|
557
|
-
|
|
558
|
-
|
|
562
|
+
const adjustmentMultiplier = Math.max(this.activeTransition.brightnessAdjustmentRange.minBrightnessValue, Math.min(this.activeTransition.brightnessAdjustmentRange.maxBrightnessValue, this.brightnessCharacteristic?.value));
|
|
563
|
+
let temperature = Math.round(interpolatedTemperature + interpolatedAdjustmentFactor * adjustmentMultiplier);
|
|
559
564
|
// apply any manually applied temperature adjustments
|
|
560
565
|
temperature += this.customTemperatureAdjustment;
|
|
561
|
-
|
|
562
|
-
|
|
566
|
+
const min = this.colorTemperatureCharacteristic?.props.minValue ?? 140;
|
|
567
|
+
const max = this.colorTemperatureCharacteristic?.props.maxValue ?? 500;
|
|
563
568
|
temperature = Math.max(min, Math.min(max, temperature));
|
|
564
|
-
|
|
569
|
+
const color = color_utils_1.ColorUtils.colorTemperatureToHueAndSaturation(temperature);
|
|
565
570
|
debug("[%s] Next temperature value is %d (for brightness %d adj: %s)", this.lightbulb.displayName, temperature, adjustmentMultiplier, this.customTemperatureAdjustment);
|
|
566
|
-
|
|
571
|
+
const context = {
|
|
567
572
|
controller: this,
|
|
568
573
|
omitEventUpdate: true,
|
|
569
574
|
};
|
|
@@ -588,8 +593,8 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
588
593
|
if (this.hueCharacteristic) {
|
|
589
594
|
this.hueCharacteristic.value = color.hue;
|
|
590
595
|
}
|
|
591
|
-
|
|
592
|
-
debug("[%s] Failed to next adaptive lighting transition point: %d",
|
|
596
|
+
this.colorTemperatureCharacteristic?.handleSetRequest(temperature, undefined, context).catch(reason => {
|
|
597
|
+
debug("[%s] Failed to next adaptive lighting transition point: %d", this.lightbulb.displayName, reason);
|
|
593
598
|
});
|
|
594
599
|
if (!this.activeTransition) {
|
|
595
600
|
console.warn("[" + this.lightbulb.displayName + "] Adaptive Lighting was probably disable my mistake by some call in " +
|
|
@@ -597,15 +602,15 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
597
602
|
"Please check that you don't call setValue/setCharacteristic on the Hue, Saturation or ColorTemperature characteristic!");
|
|
598
603
|
return;
|
|
599
604
|
}
|
|
600
|
-
|
|
605
|
+
const now = Date.now();
|
|
601
606
|
if (!dryRun && now - this.lastEventNotificationSent >= this.activeTransition.notifyIntervalThreshold) {
|
|
602
607
|
debug("[%s] Sending event notifications for current transition!", this.lightbulb.displayName);
|
|
603
608
|
this.lastEventNotificationSent = now;
|
|
604
|
-
|
|
609
|
+
const eventContext = {
|
|
605
610
|
controller: this,
|
|
606
611
|
};
|
|
607
612
|
if (this.lastNotifiedTemperatureValue !== temperature) {
|
|
608
|
-
|
|
613
|
+
this.colorTemperatureCharacteristic?.sendEventNotification(temperature, eventContext);
|
|
609
614
|
this.lastNotifiedTemperatureValue = temperature;
|
|
610
615
|
}
|
|
611
616
|
if (this.saturationCharacteristic && this.lastNotifiedSaturationValue !== color.saturation) {
|
|
@@ -620,25 +625,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
620
625
|
if (!dryRun) {
|
|
621
626
|
this.updateTimeout = setTimeout(this.scheduleNextUpdate.bind(this), this.activeTransition.updateInterval);
|
|
622
627
|
}
|
|
623
|
-
}
|
|
628
|
+
}
|
|
624
629
|
/**
|
|
625
630
|
* @private
|
|
626
631
|
*/
|
|
627
|
-
|
|
632
|
+
constructServices() {
|
|
628
633
|
return {};
|
|
629
|
-
}
|
|
634
|
+
}
|
|
630
635
|
/**
|
|
631
636
|
* @private
|
|
632
637
|
*/
|
|
633
638
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
634
|
-
|
|
639
|
+
initWithServices(serviceMap) {
|
|
635
640
|
// do nothing
|
|
636
|
-
}
|
|
641
|
+
}
|
|
637
642
|
/**
|
|
638
643
|
* @private
|
|
639
644
|
*/
|
|
640
|
-
|
|
641
|
-
var _this = this;
|
|
645
|
+
configureServices() {
|
|
642
646
|
this.supportedTransitionConfiguration = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.SupportedCharacteristicValueTransitionConfiguration);
|
|
643
647
|
this.transitionControl = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.CharacteristicValueTransitionControl)
|
|
644
648
|
.updateValue("");
|
|
@@ -647,25 +651,25 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
647
651
|
this.supportedTransitionConfiguration
|
|
648
652
|
.onGet(this.handleSupportedTransitionConfigurationRead.bind(this));
|
|
649
653
|
this.transitionControl
|
|
650
|
-
.onGet(
|
|
651
|
-
return
|
|
654
|
+
.onGet(() => {
|
|
655
|
+
return this.buildTransitionControlResponseBuffer().toString("base64");
|
|
652
656
|
})
|
|
653
|
-
.onSet(
|
|
657
|
+
.onSet(value => {
|
|
654
658
|
try {
|
|
655
|
-
return
|
|
659
|
+
return this.handleTransitionControlWrite(value);
|
|
656
660
|
}
|
|
657
661
|
catch (error) {
|
|
658
|
-
console.warn(
|
|
662
|
+
console.warn(`[%s] DEBUG: '${value}'`);
|
|
659
663
|
console.warn("[%s] Encountered error on CharacteristicValueTransitionControl characteristic: " + error.stack);
|
|
660
|
-
|
|
664
|
+
this.disableAdaptiveLighting();
|
|
661
665
|
throw new hapStatusError_1.HapStatusError(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
662
666
|
}
|
|
663
667
|
});
|
|
664
|
-
}
|
|
668
|
+
}
|
|
665
669
|
/**
|
|
666
670
|
* @private
|
|
667
671
|
*/
|
|
668
|
-
|
|
672
|
+
handleControllerRemoved() {
|
|
669
673
|
this.lightbulb.removeCharacteristic(this.supportedTransitionConfiguration);
|
|
670
674
|
this.lightbulb.removeCharacteristic(this.transitionControl);
|
|
671
675
|
this.lightbulb.removeCharacteristic(this.activeTransitionCount);
|
|
@@ -673,28 +677,28 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
673
677
|
this.transitionControl = undefined;
|
|
674
678
|
this.activeTransitionCount = undefined;
|
|
675
679
|
this.removeAllListeners();
|
|
676
|
-
}
|
|
680
|
+
}
|
|
677
681
|
/**
|
|
678
682
|
* @private
|
|
679
683
|
*/
|
|
680
|
-
|
|
684
|
+
handleFactoryReset() {
|
|
681
685
|
this.handleAdaptiveLightingDisabled();
|
|
682
|
-
}
|
|
686
|
+
}
|
|
683
687
|
/**
|
|
684
688
|
* @private
|
|
685
689
|
*/
|
|
686
|
-
|
|
690
|
+
serialize() {
|
|
687
691
|
if (!this.activeTransition) {
|
|
688
692
|
return undefined;
|
|
689
693
|
}
|
|
690
694
|
return {
|
|
691
695
|
activeTransition: this.activeTransition,
|
|
692
696
|
};
|
|
693
|
-
}
|
|
697
|
+
}
|
|
694
698
|
/**
|
|
695
699
|
* @private
|
|
696
700
|
*/
|
|
697
|
-
|
|
701
|
+
deserialize(serialized) {
|
|
698
702
|
this.activeTransition = serialized.activeTransition;
|
|
699
703
|
// Data migrations from beta builds
|
|
700
704
|
if (!this.activeTransition.transitionId) {
|
|
@@ -707,159 +711,145 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
707
711
|
this.activeTransition.timeMillisOffset = 0;
|
|
708
712
|
}
|
|
709
713
|
this.handleActiveTransitionUpdated(true);
|
|
710
|
-
}
|
|
714
|
+
}
|
|
711
715
|
/**
|
|
712
716
|
* @private
|
|
713
717
|
*/
|
|
714
|
-
|
|
718
|
+
setupStateChangeDelegate(delegate) {
|
|
715
719
|
this.stateChangeDelegate = delegate;
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
var temperatureIID = (_b = this.lightbulb) === null || _b === void 0 ? void 0 : _b.getCharacteristic(Characteristic_1.Characteristic.ColorTemperature).iid;
|
|
720
|
+
}
|
|
721
|
+
handleSupportedTransitionConfigurationRead() {
|
|
722
|
+
const brightnessIID = this.lightbulb?.getCharacteristic(Characteristic_1.Characteristic.Brightness).iid;
|
|
723
|
+
const temperatureIID = this.lightbulb?.getCharacteristic(Characteristic_1.Characteristic.ColorTemperature).iid;
|
|
721
724
|
(0, assert_1.default)(brightnessIID, "iid for brightness characteristic is undefined");
|
|
722
725
|
(0, assert_1.default)(temperatureIID, "iid for temperature characteristic is undefined");
|
|
723
726
|
return tlv.encode(1 /* SupportedCharacteristicValueTransitionConfigurationsTypes.SUPPORTED_TRANSITION_CONFIGURATION */, [
|
|
724
727
|
tlv.encode(1 /* SupportedValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(brightnessIID), 2 /* SupportedValueTransitionConfigurationTypes.TRANSITION_TYPE */, 1 /* TransitionType.BRIGHTNESS */),
|
|
725
728
|
tlv.encode(1 /* SupportedValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(temperatureIID), 2 /* SupportedValueTransitionConfigurationTypes.TRANSITION_TYPE */, 2 /* TransitionType.COLOR_TEMPERATURE */),
|
|
726
729
|
]).toString("base64");
|
|
727
|
-
}
|
|
728
|
-
|
|
730
|
+
}
|
|
731
|
+
buildTransitionControlResponseBuffer(time) {
|
|
729
732
|
if (!this.activeTransition) {
|
|
730
733
|
return Buffer.alloc(0);
|
|
731
734
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
735
|
+
const active = this.activeTransition;
|
|
736
|
+
const timeSinceStart = time ?? (Date.now() - active.timeMillisOffset - active.transitionStartMillis);
|
|
737
|
+
const timeSinceStartBuffer = tlv.writeVariableUIntLE(timeSinceStart);
|
|
738
|
+
let parameters = tlv.encode(1 /* ValueTransitionParametersTypes.TRANSITION_ID */, uuid.write(active.transitionId), 2 /* ValueTransitionParametersTypes.START_TIME */, Buffer.from(active.transitionStartBuffer, "hex"));
|
|
736
739
|
if (active.id3) {
|
|
737
740
|
parameters = Buffer.concat([
|
|
738
741
|
parameters,
|
|
739
742
|
tlv.encode(3 /* ValueTransitionParametersTypes.UNKNOWN_3 */, Buffer.from(active.id3, "hex")),
|
|
740
743
|
]);
|
|
741
744
|
}
|
|
742
|
-
|
|
745
|
+
const status = tlv.encode(1 /* ValueTransitionConfigurationStatusTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(active.iid), 2 /* ValueTransitionConfigurationStatusTypes.TRANSITION_PARAMETERS */, parameters, 3 /* ValueTransitionConfigurationStatusTypes.TIME_SINCE_START */, timeSinceStartBuffer);
|
|
743
746
|
return tlv.encode(1 /* ValueTransitionConfigurationResponseTypes.VALUE_CONFIGURATION_STATUS */, status);
|
|
744
|
-
}
|
|
745
|
-
|
|
747
|
+
}
|
|
748
|
+
handleTransitionControlWrite(value) {
|
|
746
749
|
if (typeof value !== "string") {
|
|
747
750
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
748
751
|
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
+
const tlvData = tlv.decode(Buffer.from(value, "base64"));
|
|
753
|
+
const responseBuffers = [];
|
|
754
|
+
const readTransition = tlvData[1 /* TransitionControlTypes.READ_CURRENT_VALUE_TRANSITION_CONFIGURATION */];
|
|
752
755
|
if (readTransition) {
|
|
753
|
-
|
|
756
|
+
const readTransitionResponse = this.handleTransitionControlReadTransition(readTransition);
|
|
754
757
|
if (readTransitionResponse) {
|
|
755
758
|
responseBuffers.push(readTransitionResponse);
|
|
756
759
|
}
|
|
757
760
|
}
|
|
758
|
-
|
|
761
|
+
const updateTransition = tlvData[2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */];
|
|
759
762
|
if (updateTransition) {
|
|
760
|
-
|
|
763
|
+
const updateTransitionResponse = this.handleTransitionControlUpdateTransition(updateTransition);
|
|
761
764
|
if (updateTransitionResponse) {
|
|
762
765
|
responseBuffers.push(updateTransitionResponse);
|
|
763
766
|
}
|
|
764
767
|
}
|
|
765
768
|
return Buffer.concat(responseBuffers).toString("base64");
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
769
|
+
}
|
|
770
|
+
handleTransitionControlReadTransition(buffer) {
|
|
771
|
+
const readTransition = tlv.decode(buffer);
|
|
772
|
+
const iid = tlv.readVariableUIntLE(readTransition[1 /* ReadValueTransitionConfiguration.CHARACTERISTIC_IID */]);
|
|
770
773
|
if (this.activeTransition) {
|
|
771
774
|
if (this.activeTransition.iid !== iid) {
|
|
772
775
|
console.warn("[" + this.lightbulb.displayName + "] iid of current adaptive lighting transition (" + this.activeTransition.iid
|
|
773
776
|
+ ") doesn't match the requested one " + iid);
|
|
774
777
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
775
778
|
}
|
|
776
|
-
|
|
779
|
+
let parameters = tlv.encode(1 /* ValueTransitionParametersTypes.TRANSITION_ID */, uuid.write(this.activeTransition.transitionId), 2 /* ValueTransitionParametersTypes.START_TIME */, Buffer.from(this.activeTransition.transitionStartBuffer, "hex"));
|
|
777
780
|
if (this.activeTransition.id3) {
|
|
778
781
|
parameters = Buffer.concat([
|
|
779
782
|
parameters,
|
|
780
783
|
tlv.encode(3 /* ValueTransitionParametersTypes.UNKNOWN_3 */, Buffer.from(this.activeTransition.id3, "hex")),
|
|
781
784
|
]);
|
|
782
785
|
}
|
|
783
|
-
return tlv.encode(1 /* TransitionControlTypes.READ_CURRENT_VALUE_TRANSITION_CONFIGURATION */, tlv.encode(1 /* ValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(this.activeTransition.iid), 2 /* ValueTransitionConfigurationTypes.TRANSITION_PARAMETERS */, parameters, 3 /* ValueTransitionConfigurationTypes.UNKNOWN_3 */, 1, 5 /* ValueTransitionConfigurationTypes.TRANSITION_CURVE_CONFIGURATION */, tlv.encode(1 /* TransitionCurveConfigurationTypes.TRANSITION_ENTRY */, this.activeTransition.transitionCurve.map(
|
|
784
|
-
|
|
785
|
-
var duration = (_b = (_a = array[index - 1]) === null || _a === void 0 ? void 0 : _a.duration) !== null && _b !== void 0 ? _b : 0; // we store stuff differently :sweat_smile:
|
|
786
|
+
return tlv.encode(1 /* TransitionControlTypes.READ_CURRENT_VALUE_TRANSITION_CONFIGURATION */, tlv.encode(1 /* ValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(this.activeTransition.iid), 2 /* ValueTransitionConfigurationTypes.TRANSITION_PARAMETERS */, parameters, 3 /* ValueTransitionConfigurationTypes.UNKNOWN_3 */, 1, 5 /* ValueTransitionConfigurationTypes.TRANSITION_CURVE_CONFIGURATION */, tlv.encode(1 /* TransitionCurveConfigurationTypes.TRANSITION_ENTRY */, this.activeTransition.transitionCurve.map((entry, index, array) => {
|
|
787
|
+
const duration = array[index - 1]?.duration ?? 0; // we store stuff differently :sweat_smile:
|
|
786
788
|
return tlv.encode(1 /* TransitionEntryTypes.ADJUSTMENT_FACTOR */, tlv.writeFloat32LE(entry.brightnessAdjustmentFactor), 2 /* TransitionEntryTypes.VALUE */, tlv.writeFloat32LE(entry.temperature), 3 /* TransitionEntryTypes.TRANSITION_OFFSET */, tlv.writeVariableUIntLE(entry.transitionTime), 4 /* TransitionEntryTypes.DURATION */, tlv.writeVariableUIntLE(duration));
|
|
787
789
|
}), 2 /* TransitionCurveConfigurationTypes.ADJUSTMENT_CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(this.activeTransition.brightnessCharacteristicIID), 3 /* TransitionCurveConfigurationTypes.ADJUSTMENT_MULTIPLIER_RANGE */, tlv.encode(1 /* TransitionAdjustmentMultiplierRange.MINIMUM_ADJUSTMENT_MULTIPLIER */, tlv.writeUInt32(this.activeTransition.brightnessAdjustmentRange.minBrightnessValue), 2 /* TransitionAdjustmentMultiplierRange.MAXIMUM_ADJUSTMENT_MULTIPLIER */, tlv.writeUInt32(this.activeTransition.brightnessAdjustmentRange.maxBrightnessValue))), 6 /* ValueTransitionConfigurationTypes.UPDATE_INTERVAL */, tlv.writeVariableUIntLE(this.activeTransition.updateInterval), 8 /* ValueTransitionConfigurationTypes.NOTIFY_INTERVAL_THRESHOLD */, tlv.writeVariableUIntLE(this.activeTransition.notifyIntervalThreshold)));
|
|
788
790
|
}
|
|
789
791
|
else {
|
|
790
792
|
return undefined; // returns empty string
|
|
791
793
|
}
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
var transitionConfiguration = tlv.decode(updateTransition[1 /* UpdateValueTransitionConfigurationsTypes.VALUE_TRANSITION_CONFIGURATION */]);
|
|
798
|
-
var iid = tlv.readVariableUIntLE(transitionConfiguration[1 /* ValueTransitionConfigurationTypes.CHARACTERISTIC_IID */]);
|
|
794
|
+
}
|
|
795
|
+
handleTransitionControlUpdateTransition(buffer) {
|
|
796
|
+
const updateTransition = tlv.decode(buffer);
|
|
797
|
+
const transitionConfiguration = tlv.decode(updateTransition[1 /* UpdateValueTransitionConfigurationsTypes.VALUE_TRANSITION_CONFIGURATION */]);
|
|
798
|
+
const iid = tlv.readVariableUIntLE(transitionConfiguration[1 /* ValueTransitionConfigurationTypes.CHARACTERISTIC_IID */]);
|
|
799
799
|
if (!this.lightbulb.getCharacteristicByIID(iid)) {
|
|
800
800
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
801
801
|
}
|
|
802
|
-
|
|
802
|
+
const param3 = transitionConfiguration[3 /* ValueTransitionConfigurationTypes.UNKNOWN_3 */]?.readUInt8(0); // when present it is always 1
|
|
803
803
|
if (!param3) { // if HomeKit just sends the iid, we consider that as "disable adaptive lighting" (assumption)
|
|
804
804
|
this.handleAdaptiveLightingDisabled();
|
|
805
805
|
return tlv.encode(2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */, Buffer.alloc(0));
|
|
806
806
|
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
if (previous) {
|
|
828
|
-
previous.duration = duration;
|
|
829
|
-
}
|
|
830
|
-
previous = {
|
|
831
|
-
temperature: value,
|
|
832
|
-
brightnessAdjustmentFactor: adjustmentFactor,
|
|
833
|
-
transitionTime: transitionOffset,
|
|
834
|
-
};
|
|
835
|
-
transitionCurve.push(previous);
|
|
807
|
+
const parametersTLV = tlv.decode(transitionConfiguration[2 /* ValueTransitionConfigurationTypes.TRANSITION_PARAMETERS */]);
|
|
808
|
+
const curveConfiguration = tlv.decodeWithLists(transitionConfiguration[5 /* ValueTransitionConfigurationTypes.TRANSITION_CURVE_CONFIGURATION */]);
|
|
809
|
+
const updateInterval = transitionConfiguration[6 /* ValueTransitionConfigurationTypes.UPDATE_INTERVAL */]?.readUInt16LE(0);
|
|
810
|
+
const notifyIntervalThreshold = transitionConfiguration[8 /* ValueTransitionConfigurationTypes.NOTIFY_INTERVAL_THRESHOLD */].readUInt32LE(0);
|
|
811
|
+
const transitionId = parametersTLV[1 /* ValueTransitionParametersTypes.TRANSITION_ID */];
|
|
812
|
+
const startTime = parametersTLV[2 /* ValueTransitionParametersTypes.START_TIME */];
|
|
813
|
+
const id3 = parametersTLV[3 /* ValueTransitionParametersTypes.UNKNOWN_3 */]; // this may be undefined
|
|
814
|
+
const startTimeMillis = (0, time_1.epochMillisFromMillisSince2001_01_01Buffer)(startTime);
|
|
815
|
+
const timeMillisOffset = Date.now() - startTimeMillis;
|
|
816
|
+
const transitionCurve = [];
|
|
817
|
+
let previous = undefined;
|
|
818
|
+
const transitions = curveConfiguration[1 /* TransitionCurveConfigurationTypes.TRANSITION_ENTRY */];
|
|
819
|
+
for (const entry of transitions) {
|
|
820
|
+
const tlvEntry = tlv.decode(entry);
|
|
821
|
+
const adjustmentFactor = tlvEntry[1 /* TransitionEntryTypes.ADJUSTMENT_FACTOR */].readFloatLE(0);
|
|
822
|
+
const value = tlvEntry[2 /* TransitionEntryTypes.VALUE */].readFloatLE(0);
|
|
823
|
+
const transitionOffset = tlv.readVariableUIntLE(tlvEntry[3 /* TransitionEntryTypes.TRANSITION_OFFSET */]);
|
|
824
|
+
const duration = tlvEntry[4 /* TransitionEntryTypes.DURATION */] ? tlv.readVariableUIntLE(tlvEntry[4 /* TransitionEntryTypes.DURATION */]) : undefined;
|
|
825
|
+
if (previous) {
|
|
826
|
+
previous.duration = duration;
|
|
836
827
|
}
|
|
828
|
+
previous = {
|
|
829
|
+
temperature: value,
|
|
830
|
+
brightnessAdjustmentFactor: adjustmentFactor,
|
|
831
|
+
transitionTime: transitionOffset,
|
|
832
|
+
};
|
|
833
|
+
transitionCurve.push(previous);
|
|
837
834
|
}
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
}
|
|
843
|
-
finally { if (e_1) throw e_1.error; }
|
|
844
|
-
}
|
|
845
|
-
var adjustmentIID = tlv.readVariableUIntLE(curveConfiguration[2 /* TransitionCurveConfigurationTypes.ADJUSTMENT_CHARACTERISTIC_IID */]);
|
|
846
|
-
var adjustmentMultiplierRange = tlv.decode(curveConfiguration[3 /* TransitionCurveConfigurationTypes.ADJUSTMENT_MULTIPLIER_RANGE */]);
|
|
847
|
-
var minAdjustmentMultiplier = adjustmentMultiplierRange[1 /* TransitionAdjustmentMultiplierRange.MINIMUM_ADJUSTMENT_MULTIPLIER */].readUInt32LE(0);
|
|
848
|
-
var maxAdjustmentMultiplier = adjustmentMultiplierRange[2 /* TransitionAdjustmentMultiplierRange.MAXIMUM_ADJUSTMENT_MULTIPLIER */].readUInt32LE(0);
|
|
835
|
+
const adjustmentIID = tlv.readVariableUIntLE(curveConfiguration[2 /* TransitionCurveConfigurationTypes.ADJUSTMENT_CHARACTERISTIC_IID */]);
|
|
836
|
+
const adjustmentMultiplierRange = tlv.decode(curveConfiguration[3 /* TransitionCurveConfigurationTypes.ADJUSTMENT_MULTIPLIER_RANGE */]);
|
|
837
|
+
const minAdjustmentMultiplier = adjustmentMultiplierRange[1 /* TransitionAdjustmentMultiplierRange.MINIMUM_ADJUSTMENT_MULTIPLIER */].readUInt32LE(0);
|
|
838
|
+
const maxAdjustmentMultiplier = adjustmentMultiplierRange[2 /* TransitionAdjustmentMultiplierRange.MAXIMUM_ADJUSTMENT_MULTIPLIER */].readUInt32LE(0);
|
|
849
839
|
this.activeTransition = {
|
|
850
840
|
iid: iid,
|
|
851
841
|
transitionStartMillis: startTimeMillis,
|
|
852
842
|
timeMillisOffset: timeMillisOffset,
|
|
853
843
|
transitionId: uuid.unparse(transitionId),
|
|
854
844
|
transitionStartBuffer: startTime.toString("hex"),
|
|
855
|
-
id3: id3
|
|
845
|
+
id3: id3?.toString("hex"),
|
|
856
846
|
brightnessCharacteristicIID: adjustmentIID,
|
|
857
847
|
brightnessAdjustmentRange: {
|
|
858
848
|
minBrightnessValue: minAdjustmentMultiplier,
|
|
859
849
|
maxBrightnessValue: maxAdjustmentMultiplier,
|
|
860
850
|
},
|
|
861
851
|
transitionCurve: transitionCurve,
|
|
862
|
-
updateInterval: updateInterval
|
|
852
|
+
updateInterval: updateInterval ?? 60000,
|
|
863
853
|
notifyIntervalThreshold: notifyIntervalThreshold,
|
|
864
854
|
};
|
|
865
855
|
if (this.updateTimeout) {
|
|
@@ -872,8 +862,7 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
872
862
|
}
|
|
873
863
|
this.handleActiveTransitionUpdated();
|
|
874
864
|
return tlv.encode(2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */, this.buildTransitionControlResponseBuffer(0));
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
}(events_1.EventEmitter));
|
|
865
|
+
}
|
|
866
|
+
}
|
|
878
867
|
exports.AdaptiveLightingController = AdaptiveLightingController;
|
|
879
868
|
//# sourceMappingURL=AdaptiveLightingController.js.map
|