diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-10-07 17:38:50 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-10-07 17:38:50 +0100 |
commit | 8d804ec551d8866325a56643adae34d399280327 (patch) | |
tree | 4372af0c62802b0863e2e1c28778a592d4ffaf6c /devices.py | |
parent | 88647d26fe0c38a09cfa39fcb3d09125f9f9e955 (diff) | |
download | power.eda.gay-8d804ec551d8866325a56643adae34d399280327.tar.gz power.eda.gay-8d804ec551d8866325a56643adae34d399280327.zip |
Fixed retrying if it couldn't connect
Diffstat (limited to 'devices.py')
-rw-r--r-- | devices.py | 39 |
1 files changed, 25 insertions, 14 deletions
@@ -39,26 +39,37 @@ def poll_watt_all(): asyncio.set_event_loop(loop) with database.PowerDatabase(host = HOST) as db: for host, username, password in db.get_tasmota_devices(): - try: - asyncio.run(poll_watt_for(db, host, username, password)) - except: - print("Retrying %s..." % host) - asyncio.run(poll_watt_for(db, host, username, password)) + while True: + try: + asyncio.run(poll_watt_for(db, host, username, password)) + except: + print("Retrying %s..." % host) + continue + break + def poll_kwh_all(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) with database.PowerDatabase(host = HOST) as db: for host, username, password in db.get_tasmota_devices(): - try: - asyncio.run(poll_yesterday_kwh_for(db, host, username, password)) - except: - print("Retrying %s..." % host) - asyncio.run(poll_yesterday_kwh_for(db, host, username, password)) + while True: + try: + asyncio.run(poll_yesterday_kwh_for(db, host, username, password)) + except ConnectionError: + print("Retrying %s..." % host) + continue + break if __name__ == "__main__": - if sys.argv[1] == "daily": - poll_kwh_all() - else: - poll_watt_all() + while True: + try: + if sys.argv[1] == "daily": + poll_kwh_all() + else: + poll_watt_all() + except ConnectionError as e: + print("Couldn't connect: ", e, " retrying...") + continue + break |