You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
The text was updated successfully, but these errors were encountered:
@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.
Summary: HAP-NodeJS has a logic error / oversight in
validateUserInput
inCharacteristic.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
andminStep
props such that themaxValue
is not a multiple of theminStep
, e.g.{ minValue: 0, maxValue: 25, minStep: 2 }
. CallupdateValue
on that characteristic to25
. 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 tominValue
andmaxValue
. But this isn't the logic that HK uses: instead, ifmaxValue - 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 themaxValue
internally to24
, 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
tomaxValue
range. Search Github and you will see people reporting plug-in issues which are caused by this bug.The text was updated successfully, but these errors were encountered: