craftbeerpi4-pione/cbpi/controller/system_controller.py

33 lines
1,018 B
Python
Raw Normal View History

2019-08-05 20:51:20 +02:00
import logging
2019-01-28 22:21:31 +01:00
2018-11-01 19:50:04 +01:00
2019-08-05 20:51:20 +02:00
import aiohttp
2019-01-04 09:29:09 +01:00
2018-11-01 19:50:04 +01:00
2019-08-05 20:51:20 +02:00
class SystemController:
2018-11-01 19:50:04 +01:00
2018-11-01 21:25:42 +01:00
def __init__(self, cbpi):
self.cbpi = cbpi
self.service = cbpi.actor
2019-08-05 20:51:20 +02:00
self.logger = logging.getLogger(__name__)
2019-07-31 07:58:54 +02:00
self.cbpi.app.on_startup.append(self.check_for_update)
async def check_for_update(self, app):
2019-08-05 20:51:20 +02:00
try:
timeout = aiohttp.ClientTimeout(total=1)
async with aiohttp.ClientSession(timeout=timeout) as session:
async with session.post('http://localhost:2202/check', json=dict(version=app["cbpi"].version)) as resp:
if (resp.status == 200):
data = await resp.json()
if data.get("version") != self.cbpi.version:
self.logger.info("Version Check: Newer Version exists")
else:
self.logger.info("Version Check: You are up to date")
except:
self.logger.warning("Version Check: Can't check for update")
2019-01-28 22:21:31 +01:00