Skip to content

Commit

Permalink
ConfigureName
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Jun 26, 2024
1 parent 9fb88e6 commit 18e9353
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/Characteristic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/util/checkName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18e9353

Please sign in to comment.