diff options
author | dennis <d@ennis.no> | 2023-01-31 21:41:21 +0100 |
---|---|---|
committer | dennis <d@ennis.no> | 2023-02-01 12:26:35 +0100 |
commit | 949d26079e2888db51097b0858fb04c00843ba11 (patch) | |
tree | fab2514e010b0d90b1147683bc8ea12641e9eb9a | |
parent | import correct module explicitly (diff) | |
download | energyscripts-949d26079e2888db51097b0858fb04c00843ba11.tar.gz |
neohub should use queue as well
-rwxr-xr-x | neohub2pgsql.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/neohub2pgsql.py b/neohub2pgsql.py index 646fa60..452f5a9 100755 --- a/neohub2pgsql.py +++ b/neohub2pgsql.py @@ -1,15 +1,19 @@ #!/usr/bin/python3 import os +import pickle import asyncio +from datetime import datetime +from litequeue import SQLQueue import neohubapi.neohub as neohub + from todb import todb neohub_ip = os.environ['el_neohub_ip'] neohub_port = os.environ['el_neohub_port'] -values = [] +q = SQLQueue("litequeue.db", maxsize=None) async def run(): # Legacy connection @@ -20,8 +24,9 @@ async def run(): hub_data, devices = await hub.get_live_data() for device in devices['thermostats']: print(f"Temperature in zone {device.name}: {device}") - values.append((device.time, device.device_id, device.away, device.heat_mode, device.heat_on, device.current_floor_temperature, device.target_temperature, device.temperature)) + sql = "INSERT INTO neohub (timestamp, time, device_id, away, heat_mode, heat_on, current_floor_temperature, target_temperature, temperature) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s)" + values = (datetime.utcnow(), device.time, device.device_id, device.away, device.heat_mode, device.heat_on, device.current_floor_temperature, device.target_temperature, device.temperature) + q.put(pickle.dumps([sql, values])) asyncio.run(run()) -todb("INSERT INTO neohub (time, device_id, away, heat_mode, heat_on, current_floor_temperature, target_temperature, temperature) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)", values) |