OpenWonderLabs / homebridge-switchbot

The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit. Homebridge.
https://openwonderlabs.github.io/homebridge-switchbot/
ISC License
239 stars 51 forks source link

Alphanumeric characters other than a-zA-Z0-9 are dropped in device names #1013

Closed maxileith closed 2 months ago

maxileith commented 2 months ago

Describe the Bug

German "Umlaute" (Ä, ä, Ö, ö, Ü, ü, ß) are allowed as characters in HomeKit device names. However, the plugin removes them every time I try to rename the device.

To Reproduce

  1. Name a Switch "Haustür"
  2. Restart the plugin
  3. The switch will be exposed as "Haustr"

Expected Behavior

Umlaute aren’t filtered

Relevant Log Output

-

Config for homebridge-switchbot

{
                        "deviceId": "AABBCCDDEEFF",
                        "configDeviceName": "Haustür",
                        "configDeviceType": "Bot",
                        "connectionType": "OpenAPI",
                        "bot": {
                            "mode": "press",
                            "deviceType": "lock"
                        },
                        "refreshRate": 3600,
                        "logging": "standard"
                    }

Screenshots

No response

Device and Model

SwitchBot

Node.js Version

v20.16.0

NPM Version

v10

Homebridge Version

v1.8.4

Homebridge Switchbot Plugin Version

v3.7.0

Homebridge Config UI X Plugin Version

No response

Operating System

Linux / Docker

donavanbecker commented 2 months ago

https://developer.apple.com/design/human-interface-guidelines/homekit#Help-people-choose-useful-names

maxileith commented 2 months ago

German "Umlaute" are alphanumeric characters. It is obvious that Apple allows "Umlaute" as other officially supported systems like Hue allow "Umlaute" as well. Even an Apple TV can be renamed to something with an Umlaut in it.

maxileith commented 2 months ago

For reference, here are all lowercase / uppercase letters that are officially part of unicode:

https://www.compart.com/en/unicode/category/Ll

https://www.compart.com/en/unicode/category/Lu

Pretty much the whole world besides the English speaking countries uses a few more characters which are just required to name things properly.

maxileith commented 2 months ago

And yes these character sets even include some emoji-like characters like ℹ. If you try to rename a native AppleTV device to this (in the home app), you will see that it does work. When you use another emoji like 🤪 (not part of Unicode Ll), you will see that it return an error.

mtressl commented 2 months ago

+1

This is another recently introduced bug, very annoying.

donavanbecker commented 2 months ago

I will add a config option to disable this, however this is not a bug. this is a recommendation by Apple which you will not be following.

donavanbecker commented 2 months ago

okay latest beta has this config.

maxileith commented 2 months ago

This is definitely a bug. You are assuming that alphanumeric characters are only ASCII characters 0-127, though there are more alphanumeric characters like I have written. The filter mechanism in the home app itself is considering all the Unicode character sets that I have mentioned above as compliant.

maxileith commented 2 months ago

Sadly the HomeKit documentation is a bit unspecific there. However, in the swift documentation which HomeKit probably builds up on, the character sets that I have mentioned above are used:

https://developer.apple.com/documentation/foundation/characterset/1779927-capitalizedletters

https://developer.apple.com/documentation/foundation/characterset/1779880-uppercaseletters

maxileith commented 2 months ago

Just for reference:

If you use a German Umlaut there won't be an error:

image

If you use an actual forbidden character, there will be the following error (which basically says that there is a bad character)

image

donavanbecker commented 2 months ago

https://developer.apple.com/design/human-interface-guidelines/homekit#Help-people-choose-useful-names

just referencing this again for you.

maxileith commented 2 months ago

@donavanbecker I don't see no conflict with my statement. But actually the documentation supports my statement. The documentation says in a very general way that the names of devices should describe the purpose of the device and should follow the rules:

The Unicode character sets I have provided don't violate a single rule. Besides the emoji-like characters maybe. But in general these are the allowed characters that are used by the original filter mechanism in the home app. At least from I what I can tell from a sample of chars.

Maybe it is difficult to understand for an English speaking person, BUT the rest of the world uses characters that aren't in the ASCII 0-127 range. E.g., it is just not possible to name a door correctly without "ü" in the German language.

maxileith commented 2 months ago

So the new filter that you have implemented will cause problems for everybody but english-speaking guys.

If I ask my Siri to open my front door: "Haustür öffnen", Siri won't open the front door as Siri knows the front door as "Haustr".

maxileith commented 2 months ago

Maybe I need to ask another way ... what makes you think based on the Documentation that you have linked that ü is not allowed?

donavanbecker commented 2 months ago

@maxileith you have the config. At this time I am not changing the plugin. If you upgraded to the beta Homebridge you would see the warning as well.

maxileith commented 2 months ago

If you upgraded to the beta Homebridge you would see the warning as well.

Yep, you are right. However, only until this fix will be rolled out with homebridge: https://github.com/homebridge/HAP-NodeJS/commit/380b879b139a8baf9febbdbb4301eb96d0e26b22

So the wrong check has already been fixed in HAP-NodeJS. I think it is time to fix it in the SwitchBot plugin as well. I should have linked the commit from the beginning. I just weren't aware of that commit until now.

donavanbecker commented 2 months ago

Yep, you are right. However, only until this fix will be rolled out with homebridge: https://github.com/homebridge/HAP-NodeJS/commit/380b879b139a8baf9febbdbb4301eb96d0e26b22

This is already in the a Latest HAP-NodeJS 1.x and in the 2.0.0-beta.8

So the wrong check has already been fixed in HAP-NodeJS. I think it is time to fix it in the SwitchBot plugin as well. I should have linked the commit from the beginning. I just weren't aware of that commit until now.

I will make this change and see if you're satisfied

maxileith commented 2 months ago

Yep, you are right. However, only until this fix will be rolled out with homebridge: homebridge/HAP-NodeJS@380b879 This is already in the Latest HAP-NodeJS 1.x and in the 2.0.0-beta.8

Yes, this is why there is no warning with the beta versions. In 1.8.4 there is still a warning as the updated regex has not been published yet.

I will make this change and see if you're satisfied.

Thank you. All the fellas which are non-english speakers and have weirdo alphanumeric characters like àáâäǎæ will thank you. I think it is good to align with the homebridge checks. I hope you are also satisfied with the change. Honestly, seems not to be the case ... I was hoping I could make clear how important the change is.

donavanbecker commented 2 months ago

Yes, this is why there is no warning with the beta versions. In 1.8.4 there is still a warning as the updated regex has not been published yet.

I was still getting warnings and so that is why I implemented this so it would automatically remove bad characters.

Thank you. All the fellas which are non-english speakers and have weirdo alphanumeric characters like àáâäǎæ will thank you. I think it is good to align with the homebridge checks. I hope you are also satisfied with the change. Honestly, seems not to be the case ... I was hoping I could make clear how important the change is.

I am satisfied as I an agree with staying inline. Looks like I didn't implement it the same way though, sorry about that. Also glad this forced me to add a config option, I wasn't thinking about that allows the end users to have bad names as that is their choice then.

Can you try the latest beta:

npm version

Click here to find out how to install Beta

maxileith commented 2 months ago

Works like a charm.

donavanbecker commented 2 months ago

Works like a charm.

Thanks for your feedback!