hap-nodejs 0.12.3-beta.2 → 0.12.3-beta.21
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/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 +31 -21
- 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.d.ts +0 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -28
- package/dist/index.js.map +1 -1
- package/dist/lib/Accessory.d.ts +1 -58
- package/dist/lib/Accessory.d.ts.map +1 -1
- package/dist/lib/Accessory.js +747 -1149
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/Advertiser.d.ts +1 -2
- package/dist/lib/Advertiser.d.ts.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.d.ts +2 -133
- package/dist/lib/Characteristic.d.ts.map +1 -1
- package/dist/lib/Characteristic.js +1467 -669
- package/dist/lib/Characteristic.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +0 -10
- package/dist/lib/HAPServer.d.ts.map +1 -1
- package/dist/lib/HAPServer.js +216 -280
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/Service.d.ts +1 -51
- package/dist/lib/Service.d.ts.map +1 -1
- package/dist/lib/Service.js +474 -322
- package/dist/lib/Service.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.d.ts +0 -65
- package/dist/lib/camera/RTPStreamManagement.d.ts.map +1 -1
- package/dist/lib/camera/RTPStreamManagement.js +255 -278
- 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.d.ts +0 -1
- package/dist/lib/camera/index.d.ts.map +1 -1
- package/dist/lib/camera/index.js +1 -2
- package/dist/lib/camera/index.js.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.d.ts +19 -3
- package/dist/lib/controller/AdaptiveLightingController.d.ts.map +1 -1
- package/dist/lib/controller/AdaptiveLightingController.js +217 -218
- package/dist/lib/controller/AdaptiveLightingController.js.map +1 -1
- package/dist/lib/controller/CameraController.d.ts +0 -4
- package/dist/lib/controller/CameraController.d.ts.map +1 -1
- package/dist/lib/controller/CameraController.js +189 -256
- 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.d.ts +0 -14
- package/dist/lib/controller/RemoteController.d.ts.map +1 -1
- package/dist/lib/controller/RemoteController.js +340 -415
- 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 +0 -5
- 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.d.ts +1 -106
- package/dist/lib/definitions/CharacteristicDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/CharacteristicDefinitions.js +2000 -2995
- package/dist/lib/definitions/CharacteristicDefinitions.js.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.d.ts +0 -32
- package/dist/lib/definitions/ServiceDefinitions.d.ts.map +1 -1
- package/dist/lib/definitions/ServiceDefinitions.js +820 -1147
- 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 +301 -409
- 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.d.ts +0 -27
- package/dist/lib/util/tlv.d.ts.map +1 -1
- package/dist/lib/util/tlv.js +71 -113
- package/dist/lib/util/tlv.js.map +1 -1
- package/dist/lib/util/uuid.d.ts +0 -9
- package/dist/lib/util/uuid.d.ts.map +1 -1
- package/dist/lib/util/uuid.js +15 -33
- package/dist/lib/util/uuid.js.map +1 -1
- package/dist/types.d.ts +0 -35
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +10 -10
- package/dist/BridgedCore.d.ts +0 -2
- package/dist/BridgedCore.d.ts.map +0 -1
- package/dist/BridgedCore.js +0 -43
- package/dist/BridgedCore.js.map +0 -1
- package/dist/Core.d.ts +0 -2
- package/dist/Core.d.ts.map +0 -1
- package/dist/Core.js +0 -52
- package/dist/Core.js.map +0 -1
- package/dist/lib/AccessoryLoader.d.ts +0 -28
- package/dist/lib/AccessoryLoader.d.ts.map +0 -1
- package/dist/lib/AccessoryLoader.js +0 -166
- package/dist/lib/AccessoryLoader.js.map +0 -1
- package/dist/lib/camera/Camera.d.ts +0 -43
- package/dist/lib/camera/Camera.d.ts.map +0 -1
- package/dist/lib/camera/Camera.js +0 -36
- package/dist/lib/camera/Camera.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
|
+
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";
|
|
@@ -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 an 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,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,23 +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;
|
|
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
|
-
this.colorTemperatureCharacteristic
|
|
279
|
-
this.brightnessCharacteristic
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
if (this.saturationCharacteristic) {
|
|
284
|
-
this.saturationCharacteristic.removeListener("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
285
|
-
}
|
|
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);
|
|
286
294
|
this.activeTransition = undefined;
|
|
287
|
-
|
|
295
|
+
this.stateChangeDelegate?.();
|
|
288
296
|
}
|
|
289
297
|
this.colorTemperatureCharacteristic = undefined;
|
|
290
298
|
this.brightnessCharacteristic = undefined;
|
|
@@ -296,20 +304,20 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
296
304
|
this.lastNotifiedSaturationValue = 0;
|
|
297
305
|
this.lastNotifiedHueValue = 0;
|
|
298
306
|
this.didRunFirstInitializationStep = false;
|
|
299
|
-
this.activeTransitionCount
|
|
307
|
+
this.activeTransitionCount?.sendEventNotification(0);
|
|
300
308
|
debug("[%s] Disabling adaptive lighting", this.lightbulb.displayName);
|
|
301
|
-
}
|
|
309
|
+
}
|
|
302
310
|
/**
|
|
303
311
|
* Returns the time where the current transition curve was started in epoch time millis.
|
|
304
312
|
* A transition curves is active for 24 hours typically and is renewed every 24 hours by a HomeHub.
|
|
305
313
|
* Additionally see {@link getAdaptiveLightingTimeOffset}.
|
|
306
314
|
*/
|
|
307
|
-
|
|
315
|
+
getAdaptiveLightingStartTimeOfTransition() {
|
|
308
316
|
if (!this.activeTransition) {
|
|
309
317
|
throw new Error("There is no active transition!");
|
|
310
318
|
}
|
|
311
319
|
return this.activeTransition.transitionStartMillis;
|
|
312
|
-
}
|
|
320
|
+
}
|
|
313
321
|
/**
|
|
314
322
|
* It is not necessarily given, that we have the same time (or rather the correct time) as the HomeKit controller
|
|
315
323
|
* who set up the transition schedule.
|
|
@@ -318,24 +326,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
318
326
|
* So in the case were we actually have a correct local time, it most likely will be positive (due to network latency).
|
|
319
327
|
* But of course it can also be negative.
|
|
320
328
|
*/
|
|
321
|
-
|
|
329
|
+
getAdaptiveLightingTimeOffset() {
|
|
322
330
|
if (!this.activeTransition) {
|
|
323
331
|
throw new Error("There is no active transition!");
|
|
324
332
|
}
|
|
325
333
|
return this.activeTransition.timeMillisOffset;
|
|
326
|
-
}
|
|
327
|
-
|
|
334
|
+
}
|
|
335
|
+
getAdaptiveLightingTransitionCurve() {
|
|
328
336
|
if (!this.activeTransition) {
|
|
329
337
|
throw new Error("There is no active transition!");
|
|
330
338
|
}
|
|
331
339
|
return this.activeTransition.transitionCurve;
|
|
332
|
-
}
|
|
333
|
-
|
|
340
|
+
}
|
|
341
|
+
getAdaptiveLightingBrightnessMultiplierRange() {
|
|
334
342
|
if (!this.activeTransition) {
|
|
335
343
|
throw new Error("There is no active transition!");
|
|
336
344
|
}
|
|
337
345
|
return this.activeTransition.brightnessAdjustmentRange;
|
|
338
|
-
}
|
|
346
|
+
}
|
|
339
347
|
/**
|
|
340
348
|
* This method returns the interval (in milliseconds) in which the light should update its internal color temperature
|
|
341
349
|
* (aka changes it physical color).
|
|
@@ -343,12 +351,12 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
343
351
|
*
|
|
344
352
|
* Typically this evaluates to 60000 milliseconds (60 seconds).
|
|
345
353
|
*/
|
|
346
|
-
|
|
354
|
+
getAdaptiveLightingUpdateInterval() {
|
|
347
355
|
if (!this.activeTransition) {
|
|
348
356
|
throw new Error("There is no active transition!");
|
|
349
357
|
}
|
|
350
358
|
return this.activeTransition.updateInterval;
|
|
351
|
-
}
|
|
359
|
+
}
|
|
352
360
|
/**
|
|
353
361
|
* Returns the minimum interval threshold (in milliseconds) a accessory may notify HomeKit controllers about a new
|
|
354
362
|
* color temperature value via event notifications (what happens when you call {@link Characteristic.updateValue}).
|
|
@@ -356,36 +364,47 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
356
364
|
*
|
|
357
365
|
* Typically this evaluates to 600000 milliseconds (10 minutes).
|
|
358
366
|
*/
|
|
359
|
-
|
|
367
|
+
getAdaptiveLightingNotifyIntervalThreshold() {
|
|
360
368
|
if (!this.activeTransition) {
|
|
361
369
|
throw new Error("There is no active transition!");
|
|
362
370
|
}
|
|
363
371
|
return this.activeTransition.notifyIntervalThreshold;
|
|
364
|
-
}
|
|
372
|
+
}
|
|
365
373
|
// ----------- PUBLIC API END -----------
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
+
handleActiveTransitionUpdated(calledFromDeserializer = false) {
|
|
375
|
+
if (this.activeTransitionCount) {
|
|
376
|
+
if (!calledFromDeserializer) {
|
|
377
|
+
this.activeTransitionCount.sendEventNotification(1);
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
this.activeTransitionCount.value = 1;
|
|
381
|
+
}
|
|
374
382
|
}
|
|
375
383
|
if (this.mode === 1 /* AdaptiveLightingControllerMode.AUTOMATIC */) {
|
|
376
384
|
this.scheduleNextUpdate();
|
|
377
385
|
}
|
|
378
386
|
else if (this.mode === 2 /* AdaptiveLightingControllerMode.MANUAL */) {
|
|
379
|
-
this.
|
|
387
|
+
if (!this.activeTransition) {
|
|
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);
|
|
380
399
|
}
|
|
381
400
|
else {
|
|
382
401
|
throw new Error("Unsupported adaptive lighting controller mode: " + this.mode);
|
|
383
402
|
}
|
|
384
403
|
if (!calledFromDeserializer) {
|
|
385
|
-
|
|
404
|
+
this.stateChangeDelegate?.();
|
|
386
405
|
}
|
|
387
|
-
}
|
|
388
|
-
|
|
406
|
+
}
|
|
407
|
+
handleAdaptiveLightingEnabled() {
|
|
389
408
|
if (!this.activeTransition) {
|
|
390
409
|
throw new Error("There is no active transition!");
|
|
391
410
|
}
|
|
@@ -401,15 +420,14 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
401
420
|
this.saturationCharacteristic = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.Saturation)
|
|
402
421
|
.on("change" /* CharacteristicEventTypes.CHANGE */, this.characteristicManualWrittenChangeListener);
|
|
403
422
|
}
|
|
404
|
-
}
|
|
405
|
-
|
|
423
|
+
}
|
|
424
|
+
handleAdaptiveLightingDisabled() {
|
|
406
425
|
if (this.mode === 2 /* AdaptiveLightingControllerMode.MANUAL */ && this.activeTransition) { // only emit the event if a transition is actually enabled
|
|
407
426
|
this.emit("disable" /* AdaptiveLightingControllerEvents.DISABLED */);
|
|
408
427
|
}
|
|
409
428
|
this.disableAdaptiveLighting();
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
var _this = this;
|
|
429
|
+
}
|
|
430
|
+
handleAdjustmentFactorChanged(change) {
|
|
413
431
|
if (change.newValue === change.oldValue) {
|
|
414
432
|
return;
|
|
415
433
|
}
|
|
@@ -426,24 +444,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
426
444
|
// if the reason is a read request, we expect that Hue/Saturation are also read
|
|
427
445
|
// thus we postpone our update to ColorTemperature a bit.
|
|
428
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
|
|
429
|
-
setTimeout(
|
|
430
|
-
if (!
|
|
447
|
+
setTimeout(() => {
|
|
448
|
+
if (!this.activeTransition) {
|
|
431
449
|
return; // was disabled in the mean time
|
|
432
450
|
}
|
|
433
|
-
|
|
451
|
+
this.scheduleNextUpdate(true);
|
|
434
452
|
}, 1000).unref();
|
|
435
453
|
}
|
|
436
454
|
else {
|
|
437
455
|
this.scheduleNextUpdate(true); // run a dry scheduleNextUpdate to adjust the colorTemperature using the new brightness value
|
|
438
456
|
}
|
|
439
|
-
}
|
|
457
|
+
}
|
|
440
458
|
/**
|
|
441
459
|
* This method is called when a change happens to the Hue/Saturation or ColorTemperature characteristic.
|
|
442
460
|
* When such a write happens (caused by the user changing the color/temperature) Adaptive Lighting must be disabled.
|
|
443
461
|
*
|
|
444
462
|
* @param change
|
|
445
463
|
*/
|
|
446
|
-
|
|
464
|
+
handleCharacteristicManualWritten(change) {
|
|
447
465
|
if (change.reason === "write" /* ChangeReason.WRITE */ && !(isAdaptiveLightingContext(change.context) && change.context.controller === this)) {
|
|
448
466
|
// we ignore write request which are the result of calls made to updateValue or sendEventNotification
|
|
449
467
|
// or the result of a changed value returned by a read handler
|
|
@@ -451,28 +469,27 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
451
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);
|
|
452
470
|
this.disableAdaptiveLighting();
|
|
453
471
|
}
|
|
454
|
-
}
|
|
472
|
+
}
|
|
455
473
|
/**
|
|
456
474
|
* Retrieve the {@link AdaptiveLightingTransitionPoint} for the current timestamp.
|
|
457
475
|
* Returns undefined if the current transition schedule reached its end.
|
|
458
476
|
*/
|
|
459
|
-
|
|
460
|
-
var _a, _b, _c, _d, _e;
|
|
477
|
+
getCurrentAdaptiveLightingTransitionPoint() {
|
|
461
478
|
if (!this.activeTransition) {
|
|
462
479
|
throw new Error("Cannot calculate current transition point if no transition is active!");
|
|
463
480
|
}
|
|
464
481
|
// adjustedNow is the now() date corrected to the time of the initiating controller
|
|
465
|
-
|
|
482
|
+
const adjustedNow = Date.now() - this.activeTransition.timeMillisOffset;
|
|
466
483
|
// "offset" since the start of the transition schedule
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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;
|
|
472
489
|
for (; i + 1 < this.activeTransition.transitionCurve.length; i++) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
490
|
+
const lowerBound0 = this.activeTransition.transitionCurve[i];
|
|
491
|
+
const upperBound0 = this.activeTransition.transitionCurve[i + 1];
|
|
492
|
+
const lowerBoundDuration = lowerBound0.duration ?? 0;
|
|
476
493
|
lowerBoundTimeOffset += lowerBound0.transitionTime;
|
|
477
494
|
if (offset >= lowerBoundTimeOffset) {
|
|
478
495
|
if (offset <= lowerBoundTimeOffset + lowerBoundDuration + upperBound0.transitionTime) {
|
|
@@ -507,11 +524,8 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
507
524
|
lowerBound: lowerBound,
|
|
508
525
|
upperBound: upperBound,
|
|
509
526
|
};
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
var _this = this;
|
|
513
|
-
var _a, _b, _c, _d, _e;
|
|
514
|
-
if (dryRun === void 0) { dryRun = false; }
|
|
527
|
+
}
|
|
528
|
+
scheduleNextUpdate(dryRun = false) {
|
|
515
529
|
if (!this.activeTransition) {
|
|
516
530
|
throw new Error("tried scheduling transition when no transition was active!");
|
|
517
531
|
}
|
|
@@ -522,7 +536,7 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
522
536
|
this.didRunFirstInitializationStep = true;
|
|
523
537
|
this.handleAdaptiveLightingEnabled();
|
|
524
538
|
}
|
|
525
|
-
|
|
539
|
+
const transitionPoint = this.getCurrentAdaptiveLightingTransitionPoint();
|
|
526
540
|
if (!transitionPoint) {
|
|
527
541
|
debug("[%s] Reached end of transition curve!", this.lightbulb.displayName);
|
|
528
542
|
if (!dryRun) {
|
|
@@ -531,30 +545,30 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
531
545
|
}
|
|
532
546
|
return;
|
|
533
547
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
548
|
+
const lowerBound = transitionPoint.lowerBound;
|
|
549
|
+
const upperBound = transitionPoint.upperBound;
|
|
550
|
+
let interpolatedTemperature;
|
|
551
|
+
let interpolatedAdjustmentFactor;
|
|
538
552
|
if (lowerBound.duration && transitionPoint.transitionOffset <= lowerBound.duration) {
|
|
539
553
|
interpolatedTemperature = lowerBound.temperature;
|
|
540
554
|
interpolatedAdjustmentFactor = lowerBound.brightnessAdjustmentFactor;
|
|
541
555
|
}
|
|
542
556
|
else {
|
|
543
|
-
|
|
557
|
+
const timePercentage = (transitionPoint.transitionOffset - (lowerBound.duration ?? 0)) / upperBound.transitionTime;
|
|
544
558
|
interpolatedTemperature = lowerBound.temperature + (upperBound.temperature - lowerBound.temperature) * timePercentage;
|
|
545
559
|
interpolatedAdjustmentFactor = lowerBound.brightnessAdjustmentFactor
|
|
546
560
|
+ (upperBound.brightnessAdjustmentFactor - lowerBound.brightnessAdjustmentFactor) * timePercentage;
|
|
547
561
|
}
|
|
548
|
-
|
|
549
|
-
|
|
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);
|
|
550
564
|
// apply any manually applied temperature adjustments
|
|
551
565
|
temperature += this.customTemperatureAdjustment;
|
|
552
|
-
|
|
553
|
-
|
|
566
|
+
const min = this.colorTemperatureCharacteristic?.props.minValue ?? 140;
|
|
567
|
+
const max = this.colorTemperatureCharacteristic?.props.maxValue ?? 500;
|
|
554
568
|
temperature = Math.max(min, Math.min(max, temperature));
|
|
555
|
-
|
|
569
|
+
const color = color_utils_1.ColorUtils.colorTemperatureToHueAndSaturation(temperature);
|
|
556
570
|
debug("[%s] Next temperature value is %d (for brightness %d adj: %s)", this.lightbulb.displayName, temperature, adjustmentMultiplier, this.customTemperatureAdjustment);
|
|
557
|
-
|
|
571
|
+
const context = {
|
|
558
572
|
controller: this,
|
|
559
573
|
omitEventUpdate: true,
|
|
560
574
|
};
|
|
@@ -579,8 +593,8 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
579
593
|
if (this.hueCharacteristic) {
|
|
580
594
|
this.hueCharacteristic.value = color.hue;
|
|
581
595
|
}
|
|
582
|
-
this.colorTemperatureCharacteristic
|
|
583
|
-
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);
|
|
584
598
|
});
|
|
585
599
|
if (!this.activeTransition) {
|
|
586
600
|
console.warn("[" + this.lightbulb.displayName + "] Adaptive Lighting was probably disable my mistake by some call in " +
|
|
@@ -588,15 +602,15 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
588
602
|
"Please check that you don't call setValue/setCharacteristic on the Hue, Saturation or ColorTemperature characteristic!");
|
|
589
603
|
return;
|
|
590
604
|
}
|
|
591
|
-
|
|
605
|
+
const now = Date.now();
|
|
592
606
|
if (!dryRun && now - this.lastEventNotificationSent >= this.activeTransition.notifyIntervalThreshold) {
|
|
593
607
|
debug("[%s] Sending event notifications for current transition!", this.lightbulb.displayName);
|
|
594
608
|
this.lastEventNotificationSent = now;
|
|
595
|
-
|
|
609
|
+
const eventContext = {
|
|
596
610
|
controller: this,
|
|
597
611
|
};
|
|
598
612
|
if (this.lastNotifiedTemperatureValue !== temperature) {
|
|
599
|
-
this.colorTemperatureCharacteristic
|
|
613
|
+
this.colorTemperatureCharacteristic?.sendEventNotification(temperature, eventContext);
|
|
600
614
|
this.lastNotifiedTemperatureValue = temperature;
|
|
601
615
|
}
|
|
602
616
|
if (this.saturationCharacteristic && this.lastNotifiedSaturationValue !== color.saturation) {
|
|
@@ -611,25 +625,24 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
611
625
|
if (!dryRun) {
|
|
612
626
|
this.updateTimeout = setTimeout(this.scheduleNextUpdate.bind(this), this.activeTransition.updateInterval);
|
|
613
627
|
}
|
|
614
|
-
}
|
|
628
|
+
}
|
|
615
629
|
/**
|
|
616
630
|
* @private
|
|
617
631
|
*/
|
|
618
|
-
|
|
632
|
+
constructServices() {
|
|
619
633
|
return {};
|
|
620
|
-
}
|
|
634
|
+
}
|
|
621
635
|
/**
|
|
622
636
|
* @private
|
|
623
637
|
*/
|
|
624
638
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
625
|
-
|
|
639
|
+
initWithServices(serviceMap) {
|
|
626
640
|
// do nothing
|
|
627
|
-
}
|
|
641
|
+
}
|
|
628
642
|
/**
|
|
629
643
|
* @private
|
|
630
644
|
*/
|
|
631
|
-
|
|
632
|
-
var _this = this;
|
|
645
|
+
configureServices() {
|
|
633
646
|
this.supportedTransitionConfiguration = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.SupportedCharacteristicValueTransitionConfiguration);
|
|
634
647
|
this.transitionControl = this.lightbulb.getCharacteristic(Characteristic_1.Characteristic.CharacteristicValueTransitionControl)
|
|
635
648
|
.updateValue("");
|
|
@@ -638,25 +651,25 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
638
651
|
this.supportedTransitionConfiguration
|
|
639
652
|
.onGet(this.handleSupportedTransitionConfigurationRead.bind(this));
|
|
640
653
|
this.transitionControl
|
|
641
|
-
.onGet(
|
|
642
|
-
return
|
|
654
|
+
.onGet(() => {
|
|
655
|
+
return this.buildTransitionControlResponseBuffer().toString("base64");
|
|
643
656
|
})
|
|
644
|
-
.onSet(
|
|
657
|
+
.onSet(value => {
|
|
645
658
|
try {
|
|
646
|
-
return
|
|
659
|
+
return this.handleTransitionControlWrite(value);
|
|
647
660
|
}
|
|
648
661
|
catch (error) {
|
|
649
|
-
console.warn(
|
|
662
|
+
console.warn(`[%s] DEBUG: '${value}'`);
|
|
650
663
|
console.warn("[%s] Encountered error on CharacteristicValueTransitionControl characteristic: " + error.stack);
|
|
651
|
-
|
|
664
|
+
this.disableAdaptiveLighting();
|
|
652
665
|
throw new hapStatusError_1.HapStatusError(-70402 /* HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
653
666
|
}
|
|
654
667
|
});
|
|
655
|
-
}
|
|
668
|
+
}
|
|
656
669
|
/**
|
|
657
670
|
* @private
|
|
658
671
|
*/
|
|
659
|
-
|
|
672
|
+
handleControllerRemoved() {
|
|
660
673
|
this.lightbulb.removeCharacteristic(this.supportedTransitionConfiguration);
|
|
661
674
|
this.lightbulb.removeCharacteristic(this.transitionControl);
|
|
662
675
|
this.lightbulb.removeCharacteristic(this.activeTransitionCount);
|
|
@@ -664,28 +677,28 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
664
677
|
this.transitionControl = undefined;
|
|
665
678
|
this.activeTransitionCount = undefined;
|
|
666
679
|
this.removeAllListeners();
|
|
667
|
-
}
|
|
680
|
+
}
|
|
668
681
|
/**
|
|
669
682
|
* @private
|
|
670
683
|
*/
|
|
671
|
-
|
|
684
|
+
handleFactoryReset() {
|
|
672
685
|
this.handleAdaptiveLightingDisabled();
|
|
673
|
-
}
|
|
686
|
+
}
|
|
674
687
|
/**
|
|
675
688
|
* @private
|
|
676
689
|
*/
|
|
677
|
-
|
|
690
|
+
serialize() {
|
|
678
691
|
if (!this.activeTransition) {
|
|
679
692
|
return undefined;
|
|
680
693
|
}
|
|
681
694
|
return {
|
|
682
695
|
activeTransition: this.activeTransition,
|
|
683
696
|
};
|
|
684
|
-
}
|
|
697
|
+
}
|
|
685
698
|
/**
|
|
686
699
|
* @private
|
|
687
700
|
*/
|
|
688
|
-
|
|
701
|
+
deserialize(serialized) {
|
|
689
702
|
this.activeTransition = serialized.activeTransition;
|
|
690
703
|
// Data migrations from beta builds
|
|
691
704
|
if (!this.activeTransition.transitionId) {
|
|
@@ -698,158 +711,145 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
698
711
|
this.activeTransition.timeMillisOffset = 0;
|
|
699
712
|
}
|
|
700
713
|
this.handleActiveTransitionUpdated(true);
|
|
701
|
-
}
|
|
714
|
+
}
|
|
702
715
|
/**
|
|
703
716
|
* @private
|
|
704
717
|
*/
|
|
705
|
-
|
|
718
|
+
setupStateChangeDelegate(delegate) {
|
|
706
719
|
this.stateChangeDelegate = delegate;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
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;
|
|
711
724
|
(0, assert_1.default)(brightnessIID, "iid for brightness characteristic is undefined");
|
|
712
725
|
(0, assert_1.default)(temperatureIID, "iid for temperature characteristic is undefined");
|
|
713
726
|
return tlv.encode(1 /* SupportedCharacteristicValueTransitionConfigurationsTypes.SUPPORTED_TRANSITION_CONFIGURATION */, [
|
|
714
727
|
tlv.encode(1 /* SupportedValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(brightnessIID), 2 /* SupportedValueTransitionConfigurationTypes.TRANSITION_TYPE */, 1 /* TransitionType.BRIGHTNESS */),
|
|
715
728
|
tlv.encode(1 /* SupportedValueTransitionConfigurationTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(temperatureIID), 2 /* SupportedValueTransitionConfigurationTypes.TRANSITION_TYPE */, 2 /* TransitionType.COLOR_TEMPERATURE */),
|
|
716
729
|
]).toString("base64");
|
|
717
|
-
}
|
|
718
|
-
|
|
730
|
+
}
|
|
731
|
+
buildTransitionControlResponseBuffer(time) {
|
|
719
732
|
if (!this.activeTransition) {
|
|
720
733
|
return Buffer.alloc(0);
|
|
721
734
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
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"));
|
|
726
739
|
if (active.id3) {
|
|
727
740
|
parameters = Buffer.concat([
|
|
728
741
|
parameters,
|
|
729
742
|
tlv.encode(3 /* ValueTransitionParametersTypes.UNKNOWN_3 */, Buffer.from(active.id3, "hex")),
|
|
730
743
|
]);
|
|
731
744
|
}
|
|
732
|
-
|
|
745
|
+
const status = tlv.encode(1 /* ValueTransitionConfigurationStatusTypes.CHARACTERISTIC_IID */, tlv.writeVariableUIntLE(active.iid), 2 /* ValueTransitionConfigurationStatusTypes.TRANSITION_PARAMETERS */, parameters, 3 /* ValueTransitionConfigurationStatusTypes.TIME_SINCE_START */, timeSinceStartBuffer);
|
|
733
746
|
return tlv.encode(1 /* ValueTransitionConfigurationResponseTypes.VALUE_CONFIGURATION_STATUS */, status);
|
|
734
|
-
}
|
|
735
|
-
|
|
747
|
+
}
|
|
748
|
+
handleTransitionControlWrite(value) {
|
|
736
749
|
if (typeof value !== "string") {
|
|
737
750
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
738
751
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
752
|
+
const tlvData = tlv.decode(Buffer.from(value, "base64"));
|
|
753
|
+
const responseBuffers = [];
|
|
754
|
+
const readTransition = tlvData[1 /* TransitionControlTypes.READ_CURRENT_VALUE_TRANSITION_CONFIGURATION */];
|
|
742
755
|
if (readTransition) {
|
|
743
|
-
|
|
756
|
+
const readTransitionResponse = this.handleTransitionControlReadTransition(readTransition);
|
|
744
757
|
if (readTransitionResponse) {
|
|
745
758
|
responseBuffers.push(readTransitionResponse);
|
|
746
759
|
}
|
|
747
760
|
}
|
|
748
|
-
|
|
761
|
+
const updateTransition = tlvData[2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */];
|
|
749
762
|
if (updateTransition) {
|
|
750
|
-
|
|
763
|
+
const updateTransitionResponse = this.handleTransitionControlUpdateTransition(updateTransition);
|
|
751
764
|
if (updateTransitionResponse) {
|
|
752
765
|
responseBuffers.push(updateTransitionResponse);
|
|
753
766
|
}
|
|
754
767
|
}
|
|
755
768
|
return Buffer.concat(responseBuffers).toString("base64");
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
769
|
+
}
|
|
770
|
+
handleTransitionControlReadTransition(buffer) {
|
|
771
|
+
const readTransition = tlv.decode(buffer);
|
|
772
|
+
const iid = tlv.readVariableUIntLE(readTransition[1 /* ReadValueTransitionConfiguration.CHARACTERISTIC_IID */]);
|
|
760
773
|
if (this.activeTransition) {
|
|
761
774
|
if (this.activeTransition.iid !== iid) {
|
|
762
775
|
console.warn("[" + this.lightbulb.displayName + "] iid of current adaptive lighting transition (" + this.activeTransition.iid
|
|
763
776
|
+ ") doesn't match the requested one " + iid);
|
|
764
777
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
765
778
|
}
|
|
766
|
-
|
|
779
|
+
let parameters = tlv.encode(1 /* ValueTransitionParametersTypes.TRANSITION_ID */, uuid.write(this.activeTransition.transitionId), 2 /* ValueTransitionParametersTypes.START_TIME */, Buffer.from(this.activeTransition.transitionStartBuffer, "hex"));
|
|
767
780
|
if (this.activeTransition.id3) {
|
|
768
781
|
parameters = Buffer.concat([
|
|
769
782
|
parameters,
|
|
770
783
|
tlv.encode(3 /* ValueTransitionParametersTypes.UNKNOWN_3 */, Buffer.from(this.activeTransition.id3, "hex")),
|
|
771
784
|
]);
|
|
772
785
|
}
|
|
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(
|
|
774
|
-
|
|
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:
|
|
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:
|
|
776
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));
|
|
777
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)));
|
|
778
790
|
}
|
|
779
791
|
else {
|
|
780
792
|
return undefined; // returns empty string
|
|
781
793
|
}
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
var transitionConfiguration = tlv.decode(updateTransition[1 /* UpdateValueTransitionConfigurationsTypes.VALUE_TRANSITION_CONFIGURATION */]);
|
|
788
|
-
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 */]);
|
|
789
799
|
if (!this.lightbulb.getCharacteristicByIID(iid)) {
|
|
790
800
|
throw new hapStatusError_1.HapStatusError(-70410 /* HAPStatus.INVALID_VALUE_IN_REQUEST */);
|
|
791
801
|
}
|
|
792
|
-
|
|
802
|
+
const param3 = transitionConfiguration[3 /* ValueTransitionConfigurationTypes.UNKNOWN_3 */]?.readUInt8(0); // when present it is always 1
|
|
793
803
|
if (!param3) { // if HomeKit just sends the iid, we consider that as "disable adaptive lighting" (assumption)
|
|
794
804
|
this.handleAdaptiveLightingDisabled();
|
|
795
805
|
return tlv.encode(2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */, Buffer.alloc(0));
|
|
796
806
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
if (previous) {
|
|
818
|
-
previous.duration = duration;
|
|
819
|
-
}
|
|
820
|
-
previous = {
|
|
821
|
-
temperature: value,
|
|
822
|
-
brightnessAdjustmentFactor: adjustmentFactor,
|
|
823
|
-
transitionTime: transitionOffset,
|
|
824
|
-
};
|
|
825
|
-
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;
|
|
826
827
|
}
|
|
828
|
+
previous = {
|
|
829
|
+
temperature: value,
|
|
830
|
+
brightnessAdjustmentFactor: adjustmentFactor,
|
|
831
|
+
transitionTime: transitionOffset,
|
|
832
|
+
};
|
|
833
|
+
transitionCurve.push(previous);
|
|
827
834
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
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);
|
|
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);
|
|
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?.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 ?? 60000,
|
|
853
853
|
notifyIntervalThreshold: notifyIntervalThreshold,
|
|
854
854
|
};
|
|
855
855
|
if (this.updateTimeout) {
|
|
@@ -862,8 +862,7 @@ var AdaptiveLightingController = /** @class */ (function (_super) {
|
|
|
862
862
|
}
|
|
863
863
|
this.handleActiveTransitionUpdated();
|
|
864
864
|
return tlv.encode(2 /* TransitionControlTypes.UPDATE_VALUE_TRANSITION_CONFIGURATION */, this.buildTransitionControlResponseBuffer(0));
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
}(events_1.EventEmitter));
|
|
865
|
+
}
|
|
866
|
+
}
|
|
868
867
|
exports.AdaptiveLightingController = AdaptiveLightingController;
|
|
869
868
|
//# sourceMappingURL=AdaptiveLightingController.js.map
|