Move MQTT and HSL startup scripts around
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
from . import mqtt
|
||||
import logging
|
||||
|
||||
mqtt.client.loop_start()
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from coffee_scale import mqtt
|
||||
|
||||
|
||||
class CoffeeScaleConfig(AppConfig):
|
||||
name = 'coffee_scale'
|
||||
|
||||
def ready(self):
|
||||
if ('makemigrations' in sys.argv or 'migrate' in sys.argv):
|
||||
return
|
||||
|
||||
try:
|
||||
logging.info('Connecting to MQTT (coffee scale) at {}...'.format(mqtt.HOST))
|
||||
logging.info('If there is no confirmation, the MQTT connection has probably failed.')
|
||||
mqtt.client.connect_async(mqtt.HOST, mqtt.PORT, 60)
|
||||
mqtt.client.loop_start()
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
logging.error('Failed to connect to MQTT at {}'.format(mqtt.HOST))
|
||||
|
||||
@@ -56,12 +56,3 @@ client = mqtt.Client()
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.on_disconnect = on_disconnect
|
||||
|
||||
|
||||
try:
|
||||
logging.info('Connecting to MQTT at {}...'.format(HOST))
|
||||
logging.info('If there is no confirmation, the MQTT connection has probably failed.')
|
||||
client.connect_async(HOST, PORT, 60)
|
||||
except Exception as ex:
|
||||
logging.error(ex)
|
||||
logging.error('Failed to connect to MQTT at {}'.format(HOST))
|
||||
|
||||
@@ -16,8 +16,8 @@ class HSLFetcher:
|
||||
|
||||
last_fetched = datetime.fromtimestamp(86400) # epoch
|
||||
INTERVAL = 1 # minutes
|
||||
logging.info(
|
||||
"Set up scheduled HSL API fetch every {} minutes".format(INTERVAL))
|
||||
# logging.info(
|
||||
# "Set up scheduled HSL API fetch every {} minutes".format(INTERVAL))
|
||||
|
||||
def fetch_if_needed(self):
|
||||
"""Check if new fetch from HSL API is needed."""
|
||||
|
||||
+1
-1
@@ -78,7 +78,7 @@ INSTALLED_APPS = [
|
||||
'webapp',
|
||||
'members',
|
||||
'infoscreen',
|
||||
'coffee_scale',
|
||||
'coffee_scale.apps.CoffeeScaleConfig',
|
||||
'rest_framework',
|
||||
'django_nose',
|
||||
'bootstrap3',
|
||||
|
||||
Reference in New Issue
Block a user