8000 Logic error in validateUserInput function causes 'out of compliance' HomeKit errors · Issue #1077 · homebridge/HAP-NodeJS · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Logic error in validateUserInput function causes 'out of compliance' HomeKit errors #1077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
adriancable opened this issue Dec 3, 2024 · 2 comments

Comments

@adriancable
Copy link
Contributor
adriancable commented Dec 3, 2024

Summary: HAP-NodeJS has a logic error / oversight in validateUserInput in Characteristic.ts which can cause accessories to fail to add to HomeKit with 'out of compliance' errors.

To reproduce, create a service with a characteristic e.g. HeatingThresholdTemperature, set up minValue, maxValue and minStep props such that the maxValue is not a multiple of the minStep, e.g. { minValue: 0, maxValue: 25, minStep: 2 }. Call updateValue on that characteristic to 25. Try to add accessory to HomeKit. Observe Apple Home produce 'out of compliance' error and accessory fails to add. If accessory is already added, it will go to 'no response' when this happens.

The cause is that validateUserInput first quantizes to the step, and then truncates to minValue and maxValue. But this isn't the logic that HK uses: instead, if maxValue - minValue isn't a multiple of the step, maxValue is adjusted as follows:

adjustedMaxValue := stepValue * Math.floor((maxValue - minValue) / stepValue) + minValue

So in the example case, if we set { minValue: 0, maxValue: 25, minStep: 2 } HK will adjust the maxValue internally to 24, and give OOC errors if larger values are sent.

So HAP-NodeJS needs to do the same adjustment, otherwise HAP-NodeJS can produce invalid characteristic updates which cause HK to fail the bounds check, even when submitted characteristic values are within the minValue to maxValue range. Search Github and you will see people reporting plug-in issues which are caused by this bug.

@adriancable adriancable added the bug label Dec 3, 2024
@hjdhjd
Copy link
Contributor
hjdhjd commented Dec 3, 2024

Thanks Adrian - great catch. Want to submit a PR for it? Otherwise, I'll address over the holiday season.

@adriancable
Copy link
Contributor Author

@hjdhjd - I'm away for the next couple of weeks and don't have access to my usual machinery to do testing prior to submitting a PR. So if you are able to do this, that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0