homebridge / HAP-NodeJS

Node.js implementation of the HomeKit Accessory Protocol (HAP)
Apache License 2.0
2.68k stars 630 forks source link

fix: Update characteristic naming convention warning message text and associated tests. #1054

Closed hjdhjd closed 3 months ago

hjdhjd commented 3 months ago

This PR:

n0rt0nthec4t commented 2 months ago

The regex in here "/^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u" is too tightly limited and is excluding/warning on valid HomeKit characters in names ie: - Try running the sample accessories such as Wi-Fi Router and Wi-Fi Satellite will complain about the naming

Suggest maybe /^[\p{L}\p{N}][\p{L}\p{N} -,.']*[\p{L}\p{N}]$/u

-,. are still valid in HomeKit Names

hjdhjd commented 2 months ago

The regex in here "/^[\p{L}\p{N}][\p{L}\p{N} ']*[\p{L}\p{N}]$/u" is too tightly limited and is excluding/warning on valid HomeKit characters in names ie: - Try running the sample accessories such as Wi-Fi Router and Wi-Fi Satellite will complain about the naming

Suggest maybe /^[\p{L}\p{N}][\p{L}\p{N} -,.']*[\p{L}\p{N}]$/u

-,. are still valid in HomeKit Names

They are not valid characters in names. The examples should be updated. While HomeKit may accept stuff that is invalid, it’s still invalid and it is correct to warn users accordingly. 😄 The only valid names within HomeKit, straight from the source:

Check that the names people provide follow HomeKit naming rules. If your app lets people rename services, make sure that the new names follow the rules. (The system-provided setup flow automatically checks the original names.) If people enter a name that breaks one or more rules, briefly explain the problem and suggest some alternative names that work. Here are the rules:

  • Use only alphanumeric, space, and apostrophe characters.
  • Start and end with an alphabetic or numeric character.
  • Don’t include emojis.

If you can point me to more current documentation from Apple that explicitly states differently, happy to look into it, but for the time being, we’re following the north star Apple’s laid out here. Just because HomeKit will accept a character, in general, Apple sets these guidelines up for a reason…sometimes with clear reasons, often times not, but over time the reasons for those guidelines typically become clear.

Appreciate you highlighting that we have examples that need to be updated and we’ll do so.

n0rt0nthec4t commented 2 months ago

I actually disagree that what I highlight a not valid names. While HomeKit accepts those characters in names (as it does so far in iOS 17 and iOS 18) Hapnodejs should still allow those characters.

If we're going to be "stubborn" on this, then at least provide a mechanism for the accessory developer to disable this warning

hjdhjd commented 2 months ago

We have no plans to do so. What you refer to as “valid names” are explicitly not valid. Just because HomeKit may accept them currently doesn’t make them valid.

You’re always welcome to use earlier versions of HAP-NodeJS if you prefer, but our goal is to be compliant with Apple conventions and guidelines, not merely what HomeKit will or won’t accept in a given version of the ecosystem.