Merge remote-tracking branch 'refs/remotes/origin/detached'
# Conflicts: # pulse.py
This commit is contained in:
commit
db522ae3c1
1 changed files with 30 additions and 8 deletions
38
pulse.py
38
pulse.py
|
@ -1,6 +1,7 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import tibber.const
|
import tibber.const
|
||||||
import asyncio
|
import asyncio
|
||||||
|
@ -29,7 +30,7 @@ logger.addHandler(ch)
|
||||||
|
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
__version__ = "v0.1.8"
|
__version__ = "v0.1.0"
|
||||||
logger.info(__version__)
|
logger.info(__version__)
|
||||||
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
|
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
|
||||||
|
|
||||||
|
@ -38,23 +39,44 @@ query_api = client.query_api()
|
||||||
|
|
||||||
|
|
||||||
def _incoming(pkg):
|
def _incoming(pkg):
|
||||||
data = pkg.get("data")
|
try:
|
||||||
p = Pulse(data).get_datapoint()
|
data = pkg.get("data")
|
||||||
write_api.write(record=p, bucket=BUCKET)
|
if data is None:
|
||||||
logger.info(p)
|
exit(1)
|
||||||
|
p = Pulse(data).get_datapoint()
|
||||||
|
write_api.write(record=p, bucket=BUCKET)
|
||||||
|
logger.info(p)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
conn = aiohttp.TCPConnector(limit_per_host=3)
|
conn = aiohttp.TCPConnector(limit_per_host=3)
|
||||||
async with aiohttp.ClientSession(trust_env=True, connector=conn) as session:
|
async with aiohttp.ClientSession(trust_env=True, connector=conn) as session:
|
||||||
tibber_connection = tibber.Tibber(TIBBERTOKEN, user_agent="python", websession=session)
|
|
||||||
|
logger.info("connecting to tibber...")
|
||||||
|
if session.closed:
|
||||||
|
logger.error("session closed")
|
||||||
|
exit(1)
|
||||||
|
try:
|
||||||
|
tibber_connection = tibber.Tibber(TIBBERTOKEN, user_agent="python", websession=session)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.info("error connecting to tibber...")
|
||||||
|
|
||||||
|
logger.info(e)
|
||||||
|
raise e
|
||||||
await tibber_connection.update_info()
|
await tibber_connection.update_info()
|
||||||
home = tibber_connection.get_homes()[0]
|
home = tibber_connection.get_homes()[0]
|
||||||
await home.rt_subscribe(_incoming)
|
await home.rt_subscribe(_incoming)
|
||||||
|
|
||||||
while True:
|
timeout = time.time() + 18000 # Set a timeout for 3600 seconds (1 hour)
|
||||||
await asyncio.sleep(2)
|
while time.time() < timeout:
|
||||||
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
|
asyncio.set_event_loop(loop)
|
||||||
loop.run_until_complete(run())
|
loop.run_until_complete(run())
|
||||||
|
exit(42)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue