Bouke / HAP

Swift implementation of the Homekit Accessory Protocol
https://boukehaarsma.nl/HAP/
MIT License
364 stars 50 forks source link

How to set value of characteristic in a client app? #124

Closed TheMisfit68 closed 3 years ago

TheMisfit68 commented 3 years ago

Hi,

I imported HAP into my project (using SPM). I have several accessories that read values from the field (using some hardware drivers I wrote) and now want to set these values as HAP Characteristics. However because the service of an accessory is defined Internal to HAP and can't seem to reach those characteristics.

How can I set a value of a characteristic from within a HAP-client-app?

Bouke commented 3 years ago

You should be able to do so as the Characteristic's value has a public setter. See also the example code that does just that: https://github.com/Bouke/HAP/blob/b1038b5dac7598419f7c58f54d47952385d6ecaa/Sources/hap-server/main.swift#L113

Or another example where I update my Thermostat's settings from a remote party: https://github.com/Bouke/My-Home/blob/27c8d8a390cb08bcb0e14c7e981d236fdbcac93b/Sources/ICYThermostat.swift#L111-L121

TheMisfit68 commented 3 years ago

hm, I didn't keep individual references to all my accessories. Will need to redesign my app to make this possible. thx for putting me on the right track