更改Nest恒温器(Nest API)的离开状态 [英] Change Away Status on Nest Thermostat (Nest API)

查看:167
本文介绍了更改Nest恒温器(Nest API)的离开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Nest API 我试图设置巢恒温器的状态




  • 阅读&

  • 对于
    恒温器温度控制和设置恒温器,我拥有正确配置的读写权限离开




我可以正确读取状态。有没有人有这个API的经验知道如何去设置这个状态?



FirebaseManager.h

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

//将结构放入字典
NSMutableDictionary * dict = snapshot.value;
NSLog(@\\\
\\\
\\\
1。Away Status =%@,[dict valueForKey:@away]);

NSLog(@Dict Contents%@,dict); //< ---读取恒温器状态。一个字符串,无论是在家或离开

dict [@away] = @away; //< ---更改状态字符串,但不是一个正确的解决方案,并且不会将stat设置为离开

//更改状态名称,但不会解析回firebase
NSLog (@new status =%@,[dict valueForKey:@away]);

}];


解决方案

更新子值


$ b

假设这个结构

 结构
structure_id_0
away:home

将离开的节点设置为一个字符串(这段代码相当详细,所以很容易遵循)

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

//建立一个引用到我们要写的地方structure / structure_id /
Firebase * thisStructureRef = [structuresRef childByAppendingPath:@structure_id_0];
Firebase * awayRef = [thisStructureRef childByAppendingPath:@away];

[awayRef setValue:@away];

现在,如果您想通过使用FEventTypeChildAdded观察节点来获取快照,节点的名称将是什么,而不是structure_id_0。

可以通过snapshot.key获得。



这是key:value对的关键。所以NSString * key = snapshot.key



在路径中替换for @structure_id_0中的键变量。

<请参阅 Firebase书写数据,然后查看updateChildValues为另一种选择。


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

    }];

解决方案

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.

这篇关于更改Nest恒温器(Nest API)的离开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆