Skip to content
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

Returning get/set errors to HomeKit? #163

Open
lukescott opened this issue Feb 18, 2020 · 7 comments
Open

Returning get/set errors to HomeKit? #163

lukescott opened this issue Feb 18, 2020 · 7 comments

Comments

@lukescott
Copy link

I currently use HAP-NodeJS and looking to migrate to this library. Comparing the two, HAP-NodeJS allows a get/set to by async, and returns an error with a 207 multi status to HomeKit.

It seems it may be possible to do async requests with this package (because it supports camera), but I am unclear how to return failures.

Is it possible to report an error back to iOS?

@brutella
Copy link
Owner

In which case do you want to return an error back to iOS?
Do you have an example at hand?

@lukescott
Copy link
Author

A TV remote control is one example. When iOS issues volume up or down I send a request. It doesn't have a state value. If a failure occurs I return it back to iOS.

In most other cases (like lights), I don't. But HAP-NodeJS allows you to either store the value locally or allows you to retrieve it remotely and waits for a callback for get and set. At this point I'm trying to understand the design differences between the two libraries before I migrate everything over.

@brutella
Copy link
Owner

What error do you return to iOS when the communication to the actual device was not successful?
Is there an error code for this?

@marvelph
Copy link

I have the same issue.
I think you need to return "-70402" or "-70403" as the HAP Status Code listed in "6.7.1.4 HAP Status Codes" in "HomeKit Accessory Protocol Specification Non-Commercial Version Release R2".

@brutella
Copy link
Owner

I'm currently working on a new version of the library.
With commit brutella/hap@93fd032 you can return errors back to HomeKit if setting a characteristic value fails.

import (
    "github.com/brutella/hap"
    "github.com/brutella/hap/accessory"
)

a := accessory.NewLightbulb(accessory.Info{ Name:"My Light bulb" })

a.Lightbulb.On.SetValueRequestFunc = func(interface{}, *http.Request) int {
	return hap.JsonStatusServiceCommunicationFailure
}

https://pkg.go.dev/github.com/brutella/hap/characteristic#C


Does this solve your issue?

@lukescott
Copy link
Author

Sorry it's been a couple years so my memory on this is a little foggy, and I haven't really touched my home stuff in that time. Still meaning to rewrite some of it, which is still in JS.

On first glance I'm wondering if it's possible to return an error message as well as an error code. Possibly to provide more contextual information. I don't recall if that was possible in the HomeKit protocol or not...? So in this case should the return type be error? Then if it follows a particular interface protocol you could get the error code from that.

And then looking at my original question about async - Is it possible to respond asynchronously? Pretty much every device I have isn't going to respond synchronously. I have a mix of ZWave and Wifi devices.

@brutella
Copy link
Owner

On first glance I'm wondering if it's possible to return an error message as well as an error code. Possibly to provide more contextual information. I don't recall if that was possible in the HomeKit protocol or not...? So in this case should the return type be error? Then if it follows a particular interface protocol you could get the error code from that.

The basic characteristic types for booleans, integers, floats, bytes and strings provide the method OnSetRemoteValue, which you can use the return an error. If an error is returned, the library returns the error code -70402, which is the correct behaviour.

And then looking at my original question about async - Is it possible to respond asynchronously? Pretty much every device I have isn't going to respond synchronously. I have a mix of ZWave and Wifi devices.

The protocol requires you to return an error synchronously. This means you have to block while you communicate with your ZWave and Wifi devices. I'm sure HAP-NodeJS does this in a similar way.

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

No branches or pull requests

3 participants