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