سؤال

I am looking for a way to create and remove groups (PHGroup class) from the hue bridge. Reading existing groups isn't difficult, just reading out the cache for all the data. But how can I remove or add new groups to this group collection?

I am using the Philips hue iOS SDK.

هل كانت مفيدة؟

المحلول

Groups can be managed by using the PHBridgeSendAPI class, which contains all the methods to manage bridge resources like groups, scenes, lights, etc. See below for some examples.

Creating a group

PHBridgeSendAPI reference:

/**
 Creates a new Group of lights
 @param name the name of the group
 @param lightIds the array of light ids to group
 @param completionHandler completionHandler for details of created group or error handling
 */
- (void)createGroupWithName:(NSString *)name lightIds:(NSArray *)lightIds completionHandler:(PHBridgeSendGroupCompletionHandler)completionHandler

Code example:

id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI];

NSArray *lightIdentifiers = @[@"1", @"2", @"3"];

[bridgeSendAPI createGroupWithName:@"group name" lightIds:lightIdentifiers completionHandler:^(NSString *groupIdentifier, NSArray *errors){
    if (errors.count > 0) {
        // Error handling
    }
    else {
        // Get group object from the cache
        PHBridgeResourcesCache *cache = [PHBridgeResourcesReader readBridgeResourcesCache];

        PHGroup *group = [cache.groups objectForKey:groupIdentifier];

        // Other logic
        // ...
    }
}];


Removing a group

PHBridgeSendAPI reference:

/**  
 Remote the group with the given identifier  
 @param groupIdentifier the identifier of the group to remove  
 @param completionHandler completionHandler for error handling  
*/
- (void)removeGroupWithId:(NSString *)groupIdentifier completionHandler:(PHBridgeSendErrorArrayCompletionHandler)completionHandler;

Code example:

id<PHBridgeSendAPI> bridgeSendAPI = [[[PHOverallFactory alloc] init] bridgeSendAPI];

// Remove the group
[bridgeSendAPI removeGroupWithId:@"Put here the group identifier you want to delete" completionHandler:^(NSArray *errors) {
    if (errors.count > 0) {
        // Error handling
    }

    // Other logic
    // ...
}];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top