Change Away Status on Nest Thermostat (Nest API)

喜夏-厌秋 提交于 2019-12-25 07:28:07

问题


Using the Nest API I am trying to set the nest thermostat's away status

  • Reading & Setting for temperature is working fine.

  • I have the read and write permissions correctly configured for both
    thermostat temperature control and for setting thermostat away

I can read the status correctly. Does anyone with some experience of this API know how to go about setting this status?

in "FirebaseManager.h"

 Firebase *newFirebase2 = [self.rootFirebase childByAppendingPath:@"structures"];
    [newFirebase2 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {

         // Put structures into a dictionary
         NSMutableDictionary *dict = snapshot.value;
         NSLog(@"\n\n\n1. Away Status =  %@", [dict valueForKey:@"away"]);

         NSLog(@"Dict Contents %@", dict); // <--- Reads thermostat status.  A string either home or away

        dict[@"away"] = @"away";  //<--- Changes status string but not a correct solution, and does not set the stat to away

        //Changes status name but this is not parsed back to firebase
        NSLog(@"new status =  %@", [dict valueForKey:@"away"]);

    }];

回答1:


To update a child value

assume this structure

structures
   structure_id_0
      away: "home"

setting the away node to a string of away (this code is quite verbose so it's easy to follow)

Firebase *structuresRef = [self.rootFirebase childByAppendingPath:@"structures"];

//build a reference to where we want to write structures/structure_id/
Firebase *thisStructureRef = [structuresRef childByAppendingPath:@"structure_id_0"];
Firebase *awayRef = [thisStructureRef childByAppendingPath:@"away"];

[awayRef setValue:@"away"];

Now, if you want to do this for snapshots that have been retrieved via observing a node with FEventTypeChildAdded, the node name will be whatever is used in place of structure_id_0. The is the key of the key:value pair.

That can be obtained via snapshot.key.

So NSString *key = snapshot.key

Substitute the key variable in for @"structure_id_0" in the path.

Also check out Firebase Writing Data, and then the updateChildValues for another option.



来源:https://stackoverflow.com/questions/36162283/change-away-status-on-nest-thermostat-nest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!