有没有一种发现和区分恒温器设备Is的简单方法?我本来希望能够在设备接口的某个地方或通过使用Firebase库找到deviceId,但我还没有发现这两种情况。
My对象是这样创建的(url以恒温器结尾):
Firebase fb = new Firebase("https://developer-api.nest.com/devices/thermostats/");
要更改恒温器上的属性,我的代码如下.
/*This方法使用http (而不是firebase)作为JSON对象获取整个恒温器数据结构。然后迭代每个恒温器deviceId结构,寻找一个匹配的房间名称。当它找到匹配时,它会以字符串的形式中断并返回deviceID。需要设备id来使用firebase更改与该恒温器设备相关的所有数据。*/
deviceId = getDeviceIdFromRoomName(roomName);
//然后执行类似的操作,将"target_temperature_f“更改为新值。
fb.child(deviceId).child(NestConstants.TARGET_TEMP_F).setValue(newValue);
似乎应该有一种更简单、更可靠的方法来使用Firebase库来实现这一点,但我一直未能找到它。有什么建议吗?
为了帮助可视化,这是我正在解析的数据结构,我正在寻找更好的方法来获取"CRfcK-QwEZLAr4qxHshPmZyFayBdIYv5“(如果存在的话)。
{
"thermostats": {
"CRfcK-QwEZLAr4qxHshPmZyFayBdIYv5": {
"locale": "en-US",
"temperature_scale": "F",
"is_using_emergency_heat": false,
"has_fan": true,
"software_version": "4.1",
"has_leaf": true,
"device_id": "CRfcK-QwEZLAr4qxHshPmZyFayBdIYv5",
"name": "Master Bedroom",
"can_heat": true,
"can_cool": false,
"hvac_mode": "heat",
"target_temperature_c": 18.5,
"target_temperature_f": 66,
"target_temperature_high_c": 24,
"target_temperature_high_f": 75,
"target_temperature_low_c": 20,
"target_temperature_low_f": 68,
"ambient_temperature_c": 12,
"ambient_temperature_f": 54,
"away_temperature_high_c": 24,
"away_temperature_high_f": 76,
"away_temperature_low_c": 12.5,
"away_temperature_low_f": 55,
"structure_id": "xF7P6wyrR7-8VHerOAcHYDMBc_odGpO2CIpQO_g5EpM13LINO9Oxdg",
"fan_timer_active": false,
"name_long": "Master Bedroom Thermostat",
"is_online": true
}``
发布于 2014-07-07 18:44:03
免责声明:我没有使用NEST API。下面我的答案是基于使用常规Firebase的经验。
从外观上看,thermostats
是一个[消]火源表。在这种情况下,您可以轻松地使用这样的方法来处理所有的孩子:
var thermostats = new Firebase("https://developer-api.nest.com/devices/thermostats/");
thermostats .on('child_added', function(snapshot) {
var thermostat = snapshot.val();
alert(thermostat.device_id+' is '+thermostat.name);
});
我假设您在这里使用的是JavaScript API。
发布于 2014-07-07 16:56:40
我不确定我在这里是否正确地理解了您的意思,但是您是否尝试过调用结构ID?当我这样做的时候,它列出了所有与这个结构相关的恒温器。一旦你拥有了所有的恒温器,你能打电话给他们并存储相关的名字吗?如果我离得很远,请告诉我,我会再看一遍。
发布于 2014-07-07 16:07:51
格雷格,
该结构包含关联设备ids的列表。如果发现是你的意图,我建议你开始听结构。您只需要这样做一次,因为设备ids不会更改。一旦遍历了结构并获得了所需的设备ids,您可能再也不需要执行该步骤了。
列夫。
https://stackoverflow.com/questions/24611966
复制相似问题