diff --git a/src/lib/Characteristic.ts b/src/lib/Characteristic.ts index 221ae125f..63b87b7e4 100644 --- a/src/lib/Characteristic.ts +++ b/src/lib/Characteristic.ts @@ -2893,7 +2893,13 @@ export class Characteristic extends EventEmitter { } if (this.UUID === "000000E3-0000-1000-8000-0026BB765291") { - checkName("unknown", this.displayName, value); + const nameValue = value; // This should be the actual value you want to check + if (!nameValue || nameValue.trim() === "") { + console.error("Name value is empty or invalid."); + // Handle the error, e.g., by setting a default name or skipping the operation + } else { + checkName("unknown", this.displayName, value); + } } return value; diff --git a/src/lib/util/checkName.ts b/src/lib/util/checkName.ts index 78a6f75ae..b53a98e24 100644 --- a/src/lib/util/checkName.ts +++ b/src/lib/util/checkName.ts @@ -6,6 +6,11 @@ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types export function checkName(displayName: string, name: string, value: any): void { + if (!value) { + console.warn(`HAP-NodeJS WARNING: The accessory '${displayName}' is getting published with an empty '${name}'. This is not allowed.`); + return; + } + const validHK = /^[a-zA-Z0-9\s'-.]+$/; // Ensure only letter, numbers, apostrophe, or dash const startWith = /^[a-zA-Z0-9]/; // Ensure only letters or numbers are at the beginning of string const endWith = /[a-zA-Z0-9]$/; // Ensure only letters or numbers are at the end of string