Skip to content

Commit c493015

Browse files
hjdhjdbwp91
authored andcommitted
Address all open deprecations and HAP-NodeJS deprecations. (#3648)
1 parent ae06de0 commit c493015

File tree

9 files changed

+39
-247
lines changed

9 files changed

+39
-247
lines changed

src/api.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,6 @@ export interface API {
203203
updatePlatformAccessories(accessories: PlatformAccessory[]): void;
204204
unregisterPlatformAccessories(pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]): void;
205205

206-
/**
207-
* @deprecated use {@link publishExternalAccessories} directly to publish a standalone Accessory
208-
*/
209-
publishCameraAccessories(pluginIdentifier: PluginIdentifier, accessories: PlatformAccessory[]): void;
210206
publishExternalAccessories(pluginIdentifier: PluginIdentifier, accessories: PlatformAccessory[]): void;
211207

212208
on(event: "didFinishLaunching", listener: () => void): this;

src/bridgeService.ts

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
Accessory,
33
AccessoryEventTypes,
4-
AccessoryLoader,
54
Bridge,
65
Categories,
76
Characteristic,
@@ -79,12 +78,6 @@ export interface PlatformConfig extends Record<string, any> {
7978
export interface HomebridgeConfig {
8079
bridge: BridgeConfiguration;
8180

82-
/**
83-
* @deprecated
84-
*/
85-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
86-
mdns?: any; // this is deprecated and not used anymore
87-
8881
accessories: AccessoryConfig[];
8982
platforms: PlatformConfig[];
9083

@@ -203,7 +196,6 @@ export class BridgeService {
203196
pincode: bridgeConfig.pin,
204197
category: Categories.BRIDGE,
205198
bind: bridgeConfig.bind,
206-
mdns: this.config.mdns, // this is deprecated now
207199
addIdentifyingMaterial: true,
208200
advertiser: bridgeConfig.advertiser,
209201
};
@@ -446,7 +438,6 @@ export class BridgeService {
446438
category: accessory.category,
447439
port: accessoryPort,
448440
bind: this.bridgeConfig.bind,
449-
mdns: this.config.mdns, // this is deprecated and not used anymore
450441
addIdentifyingMaterial: true,
451442
advertiser: this.bridgeConfig.advertiser,
452443
};
@@ -466,55 +457,45 @@ export class BridgeService {
466457
return undefined;
467458
}
468459

469-
if (!(services[0] instanceof Service)) {
470-
// The returned "services" for this accessory is assumed to be the old style: a big array
471-
// of JSON-style objects that will need to be parsed by HAP-NodeJS's AccessoryLoader.
472-
473-
return AccessoryLoader.parseAccessoryJSON({ // Create the actual HAP-NodeJS "Accessory" instance
474-
displayName: displayName,
475-
services: services,
460+
// The returned "services" for this accessory are simply an array of new-API-style
461+
// Service instances which we can add to a created HAP-NodeJS Accessory directly.
462+
const accessoryUUID = uuid.generate(accessoryType + ":" + (uuidBase || displayName));
463+
const accessory = new Accessory(displayName, accessoryUUID);
464+
465+
// listen for the identify event if the accessory instance has defined an identify() method
466+
if (accessoryInstance.identify) {
467+
accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {
468+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
469+
// @ts-ignore
470+
// eslint-disable-next-line @typescript-eslint/no-empty-function
471+
accessoryInstance.identify!(() => { }); // empty callback for backwards compatibility
472+
callback();
476473
});
477-
} else {
478-
// The returned "services" for this accessory are simply an array of new-API-style
479-
// Service instances which we can add to a created HAP-NodeJS Accessory directly.
480-
const accessoryUUID = uuid.generate(accessoryType + ":" + (uuidBase || displayName));
481-
const accessory = new Accessory(displayName, accessoryUUID);
482-
483-
// listen for the identify event if the accessory instance has defined an identify() method
484-
if (accessoryInstance.identify) {
485-
accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {
486-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
487-
// @ts-ignore
488-
// eslint-disable-next-line @typescript-eslint/no-empty-function
489-
accessoryInstance.identify!(() => { }); // empty callback for backwards compatibility
490-
callback();
491-
});
492-
}
474+
}
493475

494-
const informationService = accessory.getService(Service.AccessoryInformation)!;
495-
services.forEach(service => {
496-
// if you returned an AccessoryInformation service, merge its values with ours
497-
if (service instanceof Service.AccessoryInformation) {
498-
service.setCharacteristic(Characteristic.Name, displayName); // ensure display name is set
499-
// ensure the plugin has not hooked already some listeners (some weird ones do).
500-
// Otherwise, they would override our identify listener registered by the HAP-NodeJS accessory
501-
service.getCharacteristic(Characteristic.Identify).removeAllListeners(CharacteristicEventTypes.SET);
502-
503-
// pull out any values and listeners (get and set) you may have defined
504-
informationService.replaceCharacteristicsFromService(service);
505-
} else {
506-
accessory.addService(service);
507-
}
508-
});
476+
const informationService = accessory.getService(Service.AccessoryInformation)!;
477+
services.forEach(service => {
478+
// if you returned an AccessoryInformation service, merge its values with ours
479+
if (service instanceof Service.AccessoryInformation) {
480+
service.setCharacteristic(Characteristic.Name, displayName); // ensure display name is set
481+
// ensure the plugin has not hooked already some listeners (some weird ones do).
482+
// Otherwise, they would override our identify listener registered by the HAP-NodeJS accessory
483+
service.getCharacteristic(Characteristic.Identify).removeAllListeners(CharacteristicEventTypes.SET);
484+
485+
// pull out any values and listeners (get and set) you may have defined
486+
informationService.replaceCharacteristicsFromService(service);
487+
} else {
488+
accessory.addService(service);
489+
}
490+
});
509491

510-
accessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory, {}));
492+
accessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory, {}));
511493

512-
controllers.forEach(controller => {
513-
accessory.configureController(controller);
514-
});
494+
controllers.forEach(controller => {
495+
accessory.configureController(controller);
496+
});
515497

516-
return accessory;
517-
}
498+
return accessory;
518499
}
519500

520501
public async loadPlatformAccessories(plugin: Plugin, platformInstance: StaticPlatformPlugin, platformType: PlatformName | PlatformIdentifier, logger: Logging): Promise<void> {

src/childBridgeService.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ export class ChildBridgeService {
380380
bridgeOptions,
381381
homebridgeConfig: { // need to break this out to avoid a circular structure to JSON from other plugins modifying their config at runtime.
382382
bridge: this.homebridgeConfig.bridge,
383-
mdns: this.homebridgeConfig.mdns,
384383
ports: this.homebridgeConfig.ports,
385384
disabledPlugins: [], // not used by child bridges
386385
accessories: [], // not used by child bridges

src/index.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export {
122122
Categories,
123123
ChangeReason,
124124
CharacteristicEventTypes,
125-
// CharacteristicWarningType,
126125
DataFormatTags,
127126
DataStreamConnectionEvent,
128127
DataStreamServerEvent,
@@ -132,8 +131,6 @@ export {
132131
Formats,
133132
H264Level,
134133
H264Profile,
135-
// HAPHTTPCode,
136-
// HAPPairingHTTPCode,
137134
HAPServerEventTypes,
138135
HAPStatus,
139136
HDSProtocolSpecificErrorReason,
@@ -166,9 +163,7 @@ export type {
166163
*/
167164
export type {
168165
AccessControlManagement,
169-
// Accessory,
170166
AdaptiveLightingController,
171-
// Bridge,
172167
CameraController,
173168
Characteristic,
174169
ColorUtils,
@@ -178,27 +173,15 @@ export type {
178173
DataStreamServer,
179174
DataStreamWriter,
180175
DoorbellController,
181-
// Float32,
182-
// Float64,
183176
HAPServer,
184177
HAPStorage,
185178
HapStatusError,
186-
HomeKitRemoteController,
187-
// Int16,
188-
// Int32,
189-
// Int64,
190-
// Int8,
191179
HDSProtocolError,
192-
LegacyCameraSourceAdapter,
193180
RecordingManagement,
194181
RemoteController,
195182
RTPStreamManagement,
196-
// SecondsSince2001,
197183
Service,
198184
SiriAudioSession,
199-
StreamController,
200-
// UUID,
201-
// ValueWrapper,
202185
} from "hap-nodejs";
203186

204187
/**
@@ -222,7 +205,6 @@ export type {
222205
DataStreamProtocolHandler,
223206
DoorbellOptions,
224207
H264CodecParameters,
225-
LegacyCameraSource,
226208
MediaContainerConfiguration,
227209
ProxiedSourceResponse,
228210
PublishInfo,
@@ -247,8 +229,6 @@ export type {
247229
AccessoryCharacteristicChange,
248230
AddPairingCallback,
249231
AdditionalAuthorizationHandler,
250-
Address,
251-
AudioCodec,
252232
AudioCodecConfiguration,
253233
AudioCodecParameters,
254234
AudioFrame,
@@ -258,7 +238,6 @@ export type {
258238
AudioStreamingCodec,
259239
AudioStreamingOptions,
260240
ButtonConfiguration,
261-
Camera,
262241
CameraRecordingOptions,
263242
CameraStreamingOptions,
264243
CharacteristicChange,
@@ -269,7 +248,6 @@ export type {
269248
CharacteristicValue,
270249
ConstructorArgs,
271250
ControllerType,
272-
DataSendCloseReason,
273251
ErrorHandler,
274252
EventHandler,
275253
FrameHandler,
@@ -294,8 +272,6 @@ export type {
294272
PrepareStreamRequest,
295273
PrepareStreamResponse,
296274
PreparedDataStreamSession,
297-
PreparedStreamRequestCallback,
298-
PreparedStreamResponse,
299275
PrimitiveTypes,
300276
RTPTime,
301277
ReadCharacteristicsCallback,
@@ -316,18 +292,13 @@ export type {
316292
StartStreamRequest,
317293
StateChangeDelegate,
318294
StopStreamRequest,
319-
StreamAudioParams,
320-
StreamControllerOptions,
321-
StreamRequest,
322295
StreamRequestCallback,
323296
StreamSessionIdentifier,
324-
StreamVideoParams,
325297
StreamingRequest,
326298
SupportedButtonConfiguration,
327299
SupportedConfiguration,
328300
TLVEncodable,
329301
TargetConfiguration,
330-
VideoCodec,
331302
VideoInfo,
332303
VideoStreamingOptions,
333304
VoidCallback,
@@ -339,10 +310,7 @@ export type {
339310
* Export HAP-NodeJS variables as type only
340311
*/
341312
export type {
342-
// AccessoryLoader,
343-
Codes,
344313
LegacyTypes,
345-
Status,
346314
uuid,
347315
} from "hap-nodejs";
348316

@@ -357,18 +325,5 @@ export type {
357325
encode,
358326
epochMillisFromMillisSince2001_01_01,
359327
epochMillisFromMillisSince2001_01_01Buffer,
360-
// init,
361-
// isSerializableController,
362-
// loadDirectory,
363328
once,
364-
// parseAccessoryJSON,
365-
// parseCharacteristicJSON,
366-
// parseServiceJSON,
367-
// readUInt16,
368-
// readUInt32,
369-
// readUInt64,
370-
// readUInt64BE,
371-
// writeUInt16,
372-
// writeUInt32,
373-
// writeUInt64,
374329
} from "hap-nodejs";

src/logger.spec.ts

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import chalk from "chalk";
2-
import {
3-
forceColor,
4-
Logger,
5-
setDebugEnabled,
6-
setTimestampEnabled,
7-
withPrefix,
8-
} from "./logger";
2+
import { Logger } from "./logger";
93

104
describe("Logger", () => {
115
let consoleLogSpy: jest.SpyInstance;
@@ -56,13 +50,6 @@ describe("Logger", () => {
5650
expect(consoleLogSpy).not.toHaveBeenCalled();
5751
});
5852

59-
it("should not log debug level messages when debug is disabled (via func)", () => {
60-
setDebugEnabled(false);
61-
const logger = Logger.withPrefix("test");
62-
logger.debug("test message");
63-
expect(consoleLogSpy).not.toHaveBeenCalled();
64-
});
65-
6653
it("should log debug level messages when debug is enabled (via method, no param)", () => {
6754
Logger.setDebugEnabled();
6855
const logger = Logger.withPrefix("test");
@@ -79,36 +66,13 @@ describe("Logger", () => {
7966
Logger.setDebugEnabled(false); // reset debug setting
8067
});
8168

82-
it("should log debug level messages when debug is enabled (via func, no param)", () => {
83-
setDebugEnabled();
84-
const logger = Logger.withPrefix("test");
85-
logger.debug("test message");
86-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("test message"));
87-
setDebugEnabled(false); // reset debug setting
88-
});
89-
90-
it("should log debug level messages when debug is enabled (via func, with param)", () => {
91-
setDebugEnabled(true);
92-
const logger = Logger.withPrefix("test");
93-
logger.debug("test message");
94-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("test message"));
95-
setDebugEnabled(false); // reset debug setting
96-
});
97-
9869
it("should not include timestamps in log messages when timestamp is disabled (via method)", () => {
9970
Logger.setTimestampEnabled(false);
10071
const logger = Logger.withPrefix("test");
10172
logger.info("test message");
10273
expect(consoleLogSpy).not.toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
10374
});
10475

105-
it("should not include timestamps in log messages when timestamp is disabled (via func)", () => {
106-
setTimestampEnabled(false);
107-
const logger = Logger.withPrefix("test");
108-
logger.info("test message");
109-
expect(consoleLogSpy).not.toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
110-
});
111-
11276
it("should include timestamps in log messages when timestamp is enabled (via method, no param)", () => {
11377
Logger.setTimestampEnabled();
11478
const logger = Logger.withPrefix("test");
@@ -125,37 +89,11 @@ describe("Logger", () => {
12589
Logger.setTimestampEnabled(false); // reset timestamp setting
12690
});
12791

128-
it("should include timestamps in log messages when timestamp is enabled (via func, no param)", () => {
129-
setTimestampEnabled();
130-
const logger = Logger.withPrefix("test");
131-
logger.info("test message");
132-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
133-
setTimestampEnabled(false); // reset timestamp setting
134-
});
135-
136-
it("should include timestamps in log messages when timestamp is enabled (via func, with param)", () => {
137-
setTimestampEnabled(true);
138-
const logger = Logger.withPrefix("test");
139-
logger.info("test message");
140-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
141-
setTimestampEnabled(false); // reset timestamp setting
142-
});
143-
14492
it("should set chalk level to 1 when forceColor is enabled (via method)", () => {
14593
Logger.forceColor();
14694
expect(chalk.level).toBe(1);
14795
});
14896

149-
it("should set chalk level to 1 when forceColor is enabled (via func)", () => {
150-
forceColor();
151-
expect(chalk.level).toBe(1);
152-
});
153-
154-
it("should create a new logger with a prefix when withPrefix is called", () => {
155-
const logger = withPrefix("test");
156-
expect(logger.prefix).toBe("test");
157-
});
158-
15997
it("should return the same logger when called with the same prefix", () => {
16098
const logger1 = Logger.withPrefix("test");
16199
const logger2 = Logger.withPrefix("test");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy