更改Nest恒温器(Nest API)的离开状态



使用Nest API,我正在尝试设置嵌套恒温器的离开状态

  • 阅读&温度设置工作正常。

  • 我已为两者正确配置了读写权限
    恒温器温度控制和设置恒温器离开

我可以正确读取状态。有API经验的人知道如何处理setting这种状态吗?

"FirebaseManager.h"

 Firebase *newFirebase2 = [self.rootFirebase childByAppendingPath:@"structures"];
    [newFirebase2 observeEventType:FEventTypeChildAdded withBlock:^(FDataSnapshot *snapshot) {
         // Put structures into a dictionary
         NSMutableDictionary *dict = snapshot.value;
         NSLog(@"nnn1. 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"]);
    }];

更新子值

假设这种结构

structures
   structure_id_0
      away: "home"

将away节点设置为away字符串(此代码非常冗长,因此很容易理解)

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"];

现在,如果您想对通过观察添加了FEventTypeChildAdded的节点检索到的快照执行此操作,则节点名称将是代替structure_id_0使用的任何名称。是键:值对的键。

这可以通过snapshot.key.获得

所以NSString*key=snapshot.key

将中的键变量替换为路径中的@"structure_id_0"。

另请查看Firebase Writing Data,然后查看updateChildValues以获取另一个选项。

最新更新