use get to get value so it will return None if not in status
This commit is contained in:
@@ -35,13 +35,19 @@ def parse_status(status, last_status_time, table):
|
|||||||
# preparing a cursor object
|
# preparing a cursor object
|
||||||
cursorObject = dataBase.cursor()
|
cursorObject = dataBase.cursor()
|
||||||
|
|
||||||
|
with open("status.json", "w") as file:
|
||||||
|
json.dump(status, file, indent=4)
|
||||||
|
|
||||||
# insert into table
|
# insert into table
|
||||||
sql = (f"INSERT INTO {table} (timestamp, status_timestamp, outdoor_temp, idu_cfm, \
|
sql = (f"INSERT INTO {table} (timestamp, status_timestamp, outdoor_temp, idu_cfm, \
|
||||||
idu_opstat, odu_opmode, odu_opstat, room_temp, room_humidity, cool_setpoint, heat_setpoint, \
|
idu_opstat, odu_opmode, odu_opstat, room_temp, room_humidity, cool_setpoint, heat_setpoint, \
|
||||||
current_activity, zone_conditioning, mode) \
|
current_activity, zone_conditioning, mode) \
|
||||||
VALUES (CURRENT_TIMESTAMP, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
|
VALUES (CURRENT_TIMESTAMP, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)")
|
||||||
|
|
||||||
|
odu_opmode = status['odu'].get('opmode')
|
||||||
|
|
||||||
val = [status_time, status['oat'], status['idu']['cfm'], status['idu']['opstat'],
|
val = [status_time, status['oat'], status['idu']['cfm'], status['idu']['opstat'],
|
||||||
status['odu']['opmode'], status['odu']['opstat'], zone['rt'], zone['rh'], zone['clsp'], zone['htsp'],
|
odu_opmode, status['odu']['opstat'], zone['rt'], zone['rh'], zone['clsp'], zone['htsp'],
|
||||||
zone['currentActivity'], zone['zoneconditioning'], status['mode']]
|
zone['currentActivity'], zone['zoneconditioning'], status['mode']]
|
||||||
cursorObject.execute(sql, val)
|
cursorObject.execute(sql, val)
|
||||||
dataBase.commit()
|
dataBase.commit()
|
||||||
@@ -80,7 +86,7 @@ def main():
|
|||||||
for i in range(2):
|
for i in range(2):
|
||||||
print('')
|
print('')
|
||||||
table = serial_to_table[systems[i].serial]
|
table = serial_to_table[systems[i].serial]
|
||||||
print('Get Log Downstairs', systems[i].serial, table)
|
print('Get Log Downstairs', systems[i].serial, table)
|
||||||
status_downstairs = api_connection.get_status(systems[i].serial)
|
status_downstairs = api_connection.get_status(systems[i].serial)
|
||||||
last_status_time_downstairs = parse_status(status_downstairs, last_status_time_downstairs, table)
|
last_status_time_downstairs = parse_status(status_downstairs, last_status_time_downstairs, table)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user