有没有一种简单的方法来发现和区分恒温器设备 ID?我本来希望能够在设备接口的某处或使用 Firebase 库中找到 deviceId,但我没有发现任何一种情况。
我的 Firebase 对象是这样创建的(网址以恒温器结尾):
Firebase fb = new Firebase("https://developer-api.nest.com/devices/thermostats/");
要更改恒温器上的属性,我的代码如下所示...
/*此方法执行 http get(不是 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
}``