首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改Nest温控器的状态(Nest API)

更改Nest温控器的状态(Nest API)
EN

Stack Overflow用户
提问于 2016-03-22 18:22:49
回答 1查看 188关注 0票数 0

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

  • 温度的读数和设定很好。
  • 我的读写权限都配置正确。 恒温器温度控制及调温装置设置

我能正确地读出状态。对这个API有一定经验的人知道如何处理setting这种状态吗?

"FirebaseManager.h"

代码语言:javascript
复制
 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"]);

    }];
EN

回答 1

Stack Overflow用户

发布于 2016-03-22 19:45:13

更新子值

假设这个结构

代码语言:javascript
复制
structures
   structure_id_0
      away: "home"

将离开节点设置为一个离开字符串(这段代码非常冗长,因此很容易理解)

代码语言:javascript
复制
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。

还可以查看[消]火基写入数据,然后查看另一个选项的updateChildValues。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36162283

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档