8000 Bridged core and core cleanup (#1048) · homebridge/HAP-NodeJS@3b7cad3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3b7cad3

Browse files
Shaquudonavanbecker
authored andcommitted
Bridged core and core cleanup (#1048)
* BridgedCore.ts and Core.ts cleanup (updated deprecation date from year 2022 to 2024). * Removed not allowed char from Sprinkler accessory example * Code review remarks
1 parent feb82d8 commit 3b7cad3

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to `hap-nodejs` will be documented in this file. This projec
1111
- AdaptiveLightingController fix & improvement (#1038) (@Shaquu)
1212
- Minor fixes to recording logging and one change in logging. (#1040) (@hjdhjd)
1313
- Fix Build Issues (#1041) (@NorthernMan54)
14+
- Bridged core and core cleanup (#1048) (@Shaquu)
1415
- Correct log spacing
1516
- Updated and fixed `typedoc` config file
1617
- Updated dependencies

src/BridgedCore.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { Accessory, AccessoryEventTypes, AccessoryLoader, Bridge, Categories, HA
66

77
console.log(`HAP-NodeJS v${HAPLibraryVersion()} starting...`);
88

9-
console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore are deprecated and are scheduled to be remove in October 2020. " +
10-
"For more information and some guidance on how to migrate, have a look at https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore");
9+
console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore is deprecated and is scheduled to be removed in a future version.");
10+
console.warn("For more information and some guidance on how to migrate, have a look at"
11+
+ " https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore");
1112

1213
// Initialize our storage system
1314
storage.initSync();
@@ -42,9 +43,7 @@ const signals = { "SIGINT": 2, "SIGTERM": 15 } as Record<string, number>;
4243
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4344
Object.keys(signals).forEach((signal: any) => {
4445
process.on(signal, () => {
45-
bridge.unpublish();
46-
setTimeout(()=> {
47-
process.exit(128 + signals[signal]);
48-
}, 1000);
46+
bridge.unpublish()
47+
.then(() => setTimeout(() => process.exit(128 + signals[signal]), 1000));
4948
});
5049
});

src/Core.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { AccessoryLoader, HAPLibraryVersion } from "./";
66

77
console.log(`HAP-NodeJS v${HAPLibraryVersion()} starting...`);
88

9-
console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore are deprecated and are scheduled to be remove in October 2020. " +
10-
"For more information and some guidance on how to migrate, have a look at https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore");
9+
console.warn("DEPRECATION NOTICE: The use of Core and BridgeCore is deprecated and is scheduled to be removed in a future version.");
10+
console.warn("For more information and some guidance on how to migrate, have a look at"
11+
+ " https://github.com/homebridge/HAP-NodeJS/wiki/Deprecation-of-Core-and-BridgeCore");
1112

1213
// Initialize our storage system
1314
storage.initSync();
@@ -26,13 +27,13 @@ accessories.forEach((accessory) => {
2627
// @ts-expect-error: Core/BridgeCore API
2728
if (!accessory.username) {
2829
throw new Error("Username not found on accessory '" + accessory.displayName +
29-
"'. Core.js requires all accessories to define a unique 'username' property.");
30+
"'. Core.js requires all accessories to define a unique 'username' property.");
3031
}
3132

3233
// @ts-expect-error: Core/BridgeCore API
3334
if (!accessory.pincode) {
3435
throw new Error("Pincode not found on accessory '" + accessory.displayName +
35-
"'. Core.js requires all accessories to define a 'pincode' property.");
36+
"'. Core.js requires all accessories to define a 'pincode' property.");
3637
}
3738

3839
// publish this Accessory on the local network
@@ -50,12 +51,7 @@ const signals = { "SIGINT": 2, "SIGTERM": 15 } as Record<string, number>;
5051
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5152
Object.keys(signals).forEach((signal: any) => {
5253
process.on(signal, () => {
53-
for (let i = 0; i < accessories.length; i++) {
54-
accessories[i].unpublish();
55-
}
56-
57-
setTimeout(() => {
58-
process.exit(128 + signals[signal]);
59-
}, 1000);
54+
Promise.all(accessories.map(a => a.unpublish()))
55+
.then(() => setTimeout(() => process.exit(128 + signals[signal]), 1000));
6056
});
6157
});

src/accessories/Sprinkler_accessory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const SPRINKLER = {
3434
const sprinklerUUID = uuid.generate("hap-nodejs:accessories:sprinkler");
3535

3636
// This is the Accessory that we'll return to HAP-NodeJS that represents our fake motionSensor.
37-
const sprinkler = exports.accessory = new Accessory("💦 Sprinkler", sprinklerUUID);
37+
const sprinkler = exports.accessory = new Accessory("Sprinkler", sprinklerUUID);
3838

3939
// Add properties for publishing (in case we're using Core.js and not BridgedCore.js)
4040
// @ts-expect-error: Core/BridgeCore API
@@ -44,7 +44,7 @@ sprinkler.pincode = "123-44-567";
4444
sprinkler.category = Categories.SPRINKLER;
4545

4646
// Add the actual Valve Service and listen for change events from iOS.
47-
const sprinklerService = sprinkler.addService(Service.Valve, "💦 Sprinkler");
47+
const sprinklerService = sprinkler.addService(Service.Valve, "Sprinkler");
4848

4949
// Sprinkler Controll
5050
function openVentile() {

0 commit comments

Comments
 (0)
0