我正在使用 Hufman 的 Honeywell Python 代码从 MyTotalConnectComfort 网站提取数据。代码在这里。我已经修改了 2.7 的代码。我也在使用 Flask。
当我调用 client.locations() 时,我得到一个包含 6 个键的 json 文件。我削减了 json 中的数据,只获取我想要的单个键后面的数据,即“设备”。我使用以下代码来执行此操作:
Honeywelldata = client.locations()
newlist2 = []
dada = {}
for keyl, value in Honeywelldata[0].items():
if keyl == "Devices":
dada[keyl] = value
print "dadakey", dada[keyl]
newlist2.append(dada)
print "newlist2 keys", newlist2[0].keys()
print "newlist2", json.dumps(newlist2, sort_keys=True,indent=4,separators=(',', ': '))
我在这个线程的底部取回了数据和格式化列表。我试图能够将此 json 传递给 html,然后使用以下 html 代码从该列表中发布值。我已经尝试了很多事情,但我无法获得“设备”的子值。
{{ honeywell.Devices.ThermostatData.Outdoorhumidity | safe }}
我不断收到此错误UndefinedError: 'list object' has no attribute 'Devices'
我是否需要重新键入此列表,或者除了作为新手之外,我做错了什么。谢谢。
这是 newlist2 键和数据(jsonlint.com 将其显示为有效的 json)
newlist2 keys [u'Devices']
[{
"Devices": [{
"AlertSettings": null,
"DehumidifierData": null,
"DemandResponseData": null,
"DeviceID": 1111111,
"DeviceType": 48,
"FanData": null,
"HasAlertSettings": false,
"HasDehumidifier": false,
"HasFan": false,
"HasHumidifier": false,
"HasUIData": true,
"HoldUntilCapable": true,
"HumidifierData": null,
"IsAlive": true,
"IsUpgrading": false,
"LocationID": 1111111,
"MacID": "000000000000",
"Name": "THERMOSTAT",
"Schedule": null,
"ScheduleCapable": true,
"ThermostatData": {
"AllowedModes": [
3,
1,
2
],
"CoolRate": null,
"CoolSetpoint": null,
"Deadband": 0.0,
"DisplayUnits": 1,
"EquipmentOutputStatus": null,
"HeatRate": null,
"HeatSetpoint": null,
"IndoorHumidity": 39.0,
"IndoorHumidityStatus": 0,
"IndoorTemperature": 74.0,
"IndoorTemperatureStatus": 0,
"IsCommercial": false,
"IsInVacationHoldMode": false,
"MaxCoolSetpoint": 99.0,
"MaxHeatSetpoint": 90.0,
"MinCoolSetpoint": 50.0,
"MinHeatSetpoint": 40.0,
"Mode": null,
"NextTime": null,
"OutdoorHumidity": 13.0,
"OutdoorHumidityAvailable": true,
"OutdoorHumidityStatus": 0,
"OutdoorTemperature": 103.0,
"OutdoorTemperatureAvailable": true,
"OutdoorTemperatureStatus": 0,
"ScheduleCoolSp": 75.0,
"ScheduleHeatSp": 62.0,
"Status": null,
"VacationHold": null,
"VacationHoldCancelable": true
}
}]
}]