Skip to content

Address legacy deprecation cleanup #3648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ export interface API {
updatePlatformAccessories(accessories: PlatformAccessory[]): void;
unregisterPlatformAccessories(pluginIdentifier: PluginIdentifier, platformName: PlatformName, accessories: PlatformAccessory[]): void;

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

on(event: "didFinishLaunching", listener: () => void): this;
Expand Down
87 changes: 34 additions & 53 deletions src/bridgeService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
Accessory,
AccessoryEventTypes,
AccessoryLoader,
Bridge,
Categories,
Characteristic,
Expand Down Expand Up @@ -78,12 +77,6 @@ export interface PlatformConfig extends Record<string, any> {
export interface HomebridgeConfig {
bridge: BridgeConfiguration;

/**
* @deprecated
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
mdns?: any; // this is deprecated and not used anymore

accessories: AccessoryConfig[];
platforms: PlatformConfig[];

Expand Down Expand Up @@ -202,7 +195,6 @@ export class BridgeService {
pincode: bridgeConfig.pin,
category: Categories.BRIDGE,
bind: bridgeConfig.bind,
mdns: this.config.mdns, // this is deprecated now
addIdentifyingMaterial: true,
advertiser: bridgeConfig.advertiser,
};
Expand Down Expand Up @@ -433,7 +425,6 @@ export class BridgeService {
category: accessory.category,
port: accessoryPort,
bind: this.bridgeConfig.bind,
mdns: this.config.mdns, // this is deprecated and not used anymore
addIdentifyingMaterial: true,
advertiser: this.bridgeConfig.advertiser,
};
Expand All @@ -453,55 +444,45 @@ export class BridgeService {
return undefined;
}

if (!(services[0] instanceof Service)) {
// The returned "services" for this accessory is assumed to be the old style: a big array
// of JSON-style objects that will need to be parsed by HAP-NodeJS's AccessoryLoader.

return AccessoryLoader.parseAccessoryJSON({ // Create the actual HAP-NodeJS "Accessory" instance
displayName: displayName,
services: services,
// The returned "services" for this accessory are simply an array of new-API-style
// Service instances which we can add to a created HAP-NodeJS Accessory directly.
const accessoryUUID = uuid.generate(accessoryType + ":" + (uuidBase || displayName));
const accessory = new Accessory(displayName, accessoryUUID);

// listen for the identify event if the accessory instance has defined an identify() method
if (accessoryInstance.identify) {
accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-empty-function
accessoryInstance.identify!(() => { }); // empty callback for backwards compatibility
callback();
});
} else {
// The returned "services" for this accessory are simply an array of new-API-style
// Service instances which we can add to a created HAP-NodeJS Accessory directly.
const accessoryUUID = uuid.generate(accessoryType + ":" + (uuidBase || displayName));
const accessory = new Accessory(displayName, accessoryUUID);

// listen for the identify event if the accessory instance has defined an identify() method
if (accessoryInstance.identify) {
accessory.on(AccessoryEventTypes.IDENTIFY, (paired: boolean, callback: VoidCallback) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-empty-function
accessoryInstance.identify!(() => { }); // empty callback for backwards compatibility
callback();
});
}
}

const informationService = accessory.getService(Service.AccessoryInformation)!;
services.forEach(service => {
// if you returned an AccessoryInformation service, merge its values with ours
if (service instanceof Service.AccessoryInformation) {
service.setCharacteristic(Characteristic.Name, displayName); // ensure display name is set
// ensure the plugin has not hooked already some listeners (some weird ones do).
// Otherwise, they would override our identify listener registered by the HAP-NodeJS accessory
service.getCharacteristic(Characteristic.Identify).removeAllListeners(CharacteristicEventTypes.SET);

// pull out any values and listeners (get and set) you may have defined
informationService.replaceCharacteristicsFromService(service);
} else {
accessory.addService(service);
}
});
const informationService = accessory.getService(Service.AccessoryInformation)!;
services.forEach(service => {
// if you returned an AccessoryInformation service, merge its values with ours
if (service instanceof Service.AccessoryInformation) {
service.setCharacteristic(Characteristic.Name, displayName); // ensure display name is set
// ensure the plugin has not hooked already some listeners (some weird ones do).
// Otherwise, they would override our identify listener registered by the HAP-NodeJS accessory
service.getCharacteristic(Characteristic.Identify).removeAllListeners(CharacteristicEventTypes.SET);

// pull out any values and listeners (get and set) you may have defined
informationService.replaceCharacteristicsFromService(service);
} else {
accessory.addService(service);
}
});

accessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory, {}));
accessory.on(AccessoryEventTypes.CHARACTERISTIC_WARNING, BridgeService.printCharacteristicWriteWarning.bind(this, plugin, accessory, {}));

controllers.forEach(controller => {
accessory.configureController(controller);
});
controllers.forEach(controller => {
accessory.configureController(controller);
});

return accessory;
}
return accessory;
}

public async loadPlatformAccessories(plugin: Plugin, platformInstance: StaticPlatformPlugin, platformType: PlatformName | PlatformIdentifier, logger: Logging): Promise<void> {
Expand Down
1 change: 0 additions & 1 deletion src/childBridgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ export class ChildBridgeService {
bridgeOptions,
homebridgeConfig: { // need to break this out to avoid a circular structure to JSON from other plugins modifying their config at runtime.
bridge: this.homebridgeConfig.bridge,
mdns: this.homebridgeConfig.mdns,
ports: this.homebridgeConfig.ports,
disabledPlugins: [], // not used by child bridges
accessories: [], // not used by child bridges
Expand Down
45 changes: 0 additions & 45 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export {
Categories,
ChangeReason,
CharacteristicEventTypes,
// CharacteristicWarningType,
DataFormatTags,
DataStreamConnectionEvent,
DataStreamServerEvent,
Expand All @@ -132,8 +131,6 @@ export {
Formats,
H264Level,
H264Profile,
// HAPHTTPCode,
// HAPPairingHTTPCode,
HAPServerEventTypes,
HAPStatus,
HDSProtocolSpecificErrorReason,
Expand Down Expand Up @@ -166,9 +163,7 @@ export type {
*/
export type {
AccessControlManagement,
// Accessory,
AdaptiveLightingController,
// Bridge,
CameraController,
Characteristic,
ColorUtils,
Expand All @@ -178,27 +173,15 @@ export type {
DataStreamServer,
DataStreamWriter,
DoorbellController,
// Float32,
// Float64,
HAPServer,
HAPStorage,
HapStatusError,
HomeKitRemoteController,
// Int16,
// Int32,
// Int64,
// Int8,
HDSProtocolError,
LegacyCameraSourceAdapter,
RecordingManagement,
RemoteController,
RTPStreamManagement,
// SecondsSince2001,
Service,
SiriAudioSession,
StreamController,
// UUID,
// ValueWrapper,
} from "hap-nodejs";

/**
Expand All @@ -222,7 +205,6 @@ export type {
DataStreamProtocolHandler,
DoorbellOptions,
H264CodecParameters,
LegacyCameraSource,
MediaContainerConfiguration,
ProxiedSourceResponse,
PublishInfo,
Expand All @@ -247,8 +229,6 @@ export type {
AccessoryCharacteristicChange,
AddPairingCallback,
AdditionalAuthorizationHandler,
Address,
AudioCodec,
AudioCodecConfiguration,
AudioCodecParameters,
AudioFrame,
Expand All @@ -258,7 +238,6 @@ export type {
AudioStreamingCodec,
AudioStreamingOptions,
ButtonConfiguration,
Camera,
CameraRecordingOptions,
CameraStreamingOptions,
CharacteristicChange,
Expand All @@ -269,7 +248,6 @@ export type {
CharacteristicValue,
ConstructorArgs,
ControllerType,
DataSendCloseReason,
ErrorHandler,
EventHandler,
FrameHandler,
Expand All @@ -294,8 +272,6 @@ export type {
PrepareStreamRequest,
PrepareStreamResponse,
PreparedDataStreamSession,
PreparedStreamRequestCallback,
PreparedStreamResponse,
PrimitiveTypes,
RTPTime,
ReadCharacteristicsCallback,
Expand All @@ -316,18 +292,13 @@ export type {
StartStreamRequest,
StateChangeDelegate,
StopStreamRequest,
StreamAudioParams,
StreamControllerOptions,
StreamRequest,
StreamRequestCallback,
StreamSessionIdentifier,
StreamVideoParams,
StreamingRequest,
SupportedButtonConfiguration,
SupportedConfiguration,
TLVEncodable,
TargetConfiguration,
VideoCodec,
VideoInfo,
VideoStreamingOptions,
VoidCallback,
Expand All @@ -339,10 +310,7 @@ export type {
* Export HAP-NodeJS variables as type only
*/
export type {
// AccessoryLoader,
Codes,
LegacyTypes,
Status,
uuid,
} from "hap-nodejs";

Expand All @@ -357,18 +325,5 @@ export type {
encode,
epochMillisFromMillisSince2001_01_01,
epochMillisFromMillisSince2001_01_01Buffer,
// init,
// isSerializableController,
// loadDirectory,
once,
// parseAccessoryJSON,
// parseCharacteristicJSON,
// parseServiceJSON,
// readUInt16,
// readUInt32,
// readUInt64,
// readUInt64BE,
// writeUInt16,
// writeUInt32,
// writeUInt64,
} from "hap-nodejs";
64 changes: 1 addition & 63 deletions src/logger.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import chalk from "chalk";
import {
forceColor,
Logger,
setDebugEnabled,
setTimestampEnabled,
withPrefix,
} from "./logger";
import { Logger } from "./logger";

describe("Logger", () => {
let consoleLogSpy: jest.SpyInstance;
Expand Down Expand Up @@ -56,13 +50,6 @@ describe("Logger", () => {
expect(consoleLogSpy).not.toHaveBeenCalled();
});

it("should not log debug level messages when debug is disabled (via func)", () => {
setDebugEnabled(false);
const logger = Logger.withPrefix("test");
logger.debug("test message");
expect(consoleLogSpy).not.toHaveBeenCalled();
});

it("should log debug level messages when debug is enabled (via method, no param)", () => {
Logger.setDebugEnabled();
const logger = Logger.withPrefix("test");
Expand All @@ -79,36 +66,13 @@ describe("Logger", () => {
Logger.setDebugEnabled(false); // reset debug setting
});

it("should log debug level messages when debug is enabled (via func, no param)", () => {
setDebugEnabled();
const logger = Logger.withPrefix("test");
logger.debug("test message");
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("test message"));
setDebugEnabled(false); // reset debug setting
});

it("should log debug level messages when debug is enabled (via func, with param)", () => {
setDebugEnabled(true);
const logger = Logger.withPrefix("test");
logger.debug("test message");
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("test message"));
setDebugEnabled(false); // reset debug setting
});

it("should not include timestamps in log messages when timestamp is disabled (via method)", () => {
Logger.setTimestampEnabled(false);
const logger = Logger.withPrefix("test");
logger.info("test message");
expect(consoleLogSpy).not.toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
});

it("should not include timestamps in log messages when timestamp is disabled (via func)", () => {
setTimestampEnabled(false);
const logger = Logger.withPrefix("test");
logger.info("test message");
expect(consoleLogSpy).not.toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
});

it("should include timestamps in log messages when timestamp is enabled (via method, no param)", () => {
Logger.setTimestampEnabled();
const logger = Logger.withPrefix("test");
Expand All @@ -125,37 +89,11 @@ describe("Logger", () => {
Logger.setTimestampEnabled(false); // reset timestamp setting
});

it("should include timestamps in log messages when timestamp is enabled (via func, no param)", () => {
setTimestampEnabled();
const logger = Logger.withPrefix("test");
logger.info("test message");
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
setTimestampEnabled(false); // reset timestamp setting
});

it("should include timestamps in log messages when timestamp is enabled (via func, with param)", () => {
setTimestampEnabled(true);
const logger = Logger.withPrefix("test");
logger.info("test message");
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringMatching(/\[\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}:\d{2} (AM|PM)].*/));
setTimestampEnabled(false); // reset timestamp setting
});

it("should set chalk level to 1 when forceColor is enabled (via method)", () => {
Logger.forceColor();
expect(chalk.level).toBe(1);
});

it("should set chalk level to 1 when forceColor is enabled (via func)", () => {
forceColor();
expect(chalk.level).toBe(1);
});

it("should create a new logger with a prefix when withPrefix is called", () => {
const logger = withPrefix("test");
expect(logger.prefix).toBe("test");
});

it("should return the same logger when called with the same prefix", () => {
const logger1 = Logger.withPrefix("test");
const logger2 = Logger.withPrefix("test");
Expand Down
Loading
Loading
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