diff --git a/src/lib/Characteristic.ts b/src/lib/Characteristic.ts index 6457cacd5..6aa78036e 100644 --- a/src/lib/Characteristic.ts +++ b/src/lib/Characteristic.ts @@ -2977,7 +2977,7 @@ export class Characteristic extends EventEmitter { value = value.substring(0, maxLength); } - if (this.UUID === "000000E3-0000-1000-8000-0026BB765291") { + if (value.length > 0 && this.UUID === Characteristic.ConfiguredName.UUID) { checkName(this.displayName, "ConfiguredName", value); } diff --git a/src/lib/util/checkName.ts b/src/lib/util/checkName.ts index b53a98e24..6be2e2987 100644 --- a/src/lib/util/checkName.ts +++ b/src/lib/util/checkName.ts @@ -6,18 +6,16 @@ // 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 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 + const pattern = !validHK.test(value) ? "doesn't have only letter, numbers, apostrophe, or dash" + : !startWith.test(value) ? "doesn't start with letter or number," + : !endWith.test(value) ? "doesn't end with letter or number," : "-"; if (!validHK.test(value) || !startWith.test(value) || !endWith.test(value)) { console.warn("HAP-NodeJS WARNING: The accessory '" + displayName + "' is getting published with the characteristic '" + - name + "'" + " not following HomeKit naming rules ('" + value + "'). " + + name + "'" + " not following HomeKit naming rules ('" + value + "')," + " with a pattern that ('" + pattern + "'). " + "Use only alphanumeric, space, and apostrophe characters, start and end with an alphabetic or numeric character, and don't include emojis. " + "This might prevent the accessory from being added to the Home App or leading to the accessory being unresponsive!"); }