brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

Add "Valid Values" and "Valid Value Range" characteristic objects #205

Closed rblenkinsopp closed 2 years ago

rblenkinsopp commented 3 years ago

As described in "6.3.3 Characteristic Objects" section of the HAP Specification.

This is required for characteristics that are enumeration values and when a service doesn't support all the possible enumeration values.

This has been tested with the following code (for which it was required) with an iOS client and results in the expected behavior:

ss := service.NewSecuritySystem()
ss.SecuritySystemCurrentState.SetValidValues([]int{
    characteristic.SecuritySystemCurrentStateDisarmed,
    characteristic.SecuritySystemCurrentStateAwayArm,
    characteristic.SecuritySystemCurrentStateAlarmTriggered,
})
ss.SecuritySystemTargetState.SetValidValues([]int{
    characteristic.SecuritySystemTargetStateDisarm,
    characteristic.SecuritySystemTargetStateAwayArm,
})

This descriptor should only be used for UInt8 and for Apple-defined characteristics, but this is not enforced in this PR.

rblenkinsopp commented 2 years ago

Sorry to chase, but is this MR likely to be reviewed soon? I have a number of other changes which I would like to submit but wanted to see how this one progressed. If it's unlikely to be looked at soon I'll continue on a fork for the time being, and can always look to raise further MRs later.

brutella commented 2 years ago

Sorry for not looking into this earlier.

I've refactored hc and made a new library out of it. The new library is available as hap. I've included your pull request with commit brutella/hap@eec8501

brutella commented 2 years ago

Thanks for your work. 🎉

rblenkinsopp commented 2 years ago

Great, thanks! The refactor looks like it addresses a number of other issues that I wanted looked at, great work :)