PhilipsHue / PhilipsHueSDK-iOS-OSX

The Software Development Kit for Philips Hue on iOS and OS X (beta)
579 stars 168 forks source link

PHSchedule creation crash when using sceneIdentifier #56

Closed lightbow closed 10 years ago

lightbow commented 10 years ago

I'm getting * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* setObjectForKey: object cannot be nil (key: address)'

I saw a previous post on this but he was using lightIdentifier. I'm trying to use sceneIdentifier, and according to the header file, I should be able to have a nil lightIdentifier and nil groupIdentifier if I provide a valid sceneIdentifier.

Still, even if the request isn't formed correctly, the SDK should produce an error, not crash. Any suggestions?

2 0x00016d68 in -[PHBridgeSendAPI2 createSchedule:completionHandler:] at /Library/Server/Xcode/Data/BotRuns/Cache/c5ea3bc5-5e62-5e62-453d-f1fa5ca3092c/source/HueSDK/HueSDK/BridgeSendAPI/PHBridgeSendAPI2.m:196

lightbow commented 10 years ago

Though maybe it's possible the scene isn't getting saved properly. Is it a reasonable practice to create a scene, save out the necessary light states, and create a new schedule all in the same run loop? No errors are reported in any of the completion blocks, just this crash.

jhvdb87 commented 10 years ago

This is error is caused because no group identifier is set when you set the scene identifier in the schedule object. Recalling a scene requires also a group identifier, which means the scene will be activated on the lights that are both part of the scene and group. Consider the following examples:

Example1: Scene "1": lights: "1","2","3" Group "0": contains all lights. This group is by default available

When you recall scene "1" on group "0" then all the lights will go the state defined for that scene.

Example2: Scene "1": lights: "1","2","3" Group "1": lights: "1"

When you recall scene "1" on group "1" then only light "1" will go to the defined state for that scene.

Example3: Scene "1": lights: "1","2","3" Group "1": lights: "4"

When you recall scene "1" on group "1", the scene won't be activated on any of the lights because they are not part of the group.

I agree with you that this shouldn't crash the SDK, but rather produce an error. We'll create a ticket for this on our backlog.

lightbow commented 10 years ago

Thanks for that information. The comment in the header file seems to contradict that though, implying that if you have a scene identifier set for a schedule meant to change an entire scene at once, a group identifier is not needed.

It sounds like I should just be able to set a group identifier of 0 (which includes all lights) and it should work?

/* The identifier of the group this schedule should have effect on, this is only set if this schedule is meant to change a group and not a scene or light. / @property (nonatomic, strong) NSString *groupIdentifier;

pverh commented 10 years ago

Thanks for reporting, in 1.3beta we have improved the header documentation with regard to using the scene and group identifiers.