use get to get value so it will return None if not in status

This commit is contained in:
2025-03-17 22:41:57 -05:00
parent fd7231700f
commit 42516b9d69

View File

@@ -35,13 +35,19 @@ def parse_status(status, last_status_time, table):
# preparing a cursor object
cursorObject = dataBase.cursor()
with open("status.json", "w") as file:
json.dump(status, file, indent=4)
# insert into table
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, \
current_activity, zone_conditioning, mode) \
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'],
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']]
cursorObject.execute(sql, val)
dataBase.commit()
@@ -80,7 +86,7 @@ def main():
for i in range(2):
print('')
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)
last_status_time_downstairs = parse_status(status_downstairs, last_status_time_downstairs, table)