简体   繁体   English

更改Nest Thermostat的离开状态(Nest API)

[英]Change Away Status on Nest Thermostat (Nest API)

Using the Nest API I am trying to set the nest thermostat's away status 我正在使用Nest API尝试设置Nest API的离开状态

  • 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? 具有此API经验的人是否知道如何setting此状态?

in "FirebaseManager.h" "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"]);

    }];

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

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. 现在,如果要对通过观察具有FEventTypeChildAdded的节点而检索到的快照执行此操作,则节点名称将是用来代替structure_id_0的名称。 The is the key of the key:value pair. 是key:value对的键。

That can be obtained via snapshot.key. 可以通过snapshot.key获得。

So NSString *key = snapshot.key 所以NSString * key = snapshot.key

Substitute the key variable in for @"structure_id_0" in the path. 将密钥变量替换为路径中的@“ structure_id_0”。

Also check out Firebase Writing Data , and then the updateChildValues for another option. 还要签出Firebase编写数据 ,然后签出updateChildValues以获得另一个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM