24 lines
708 B
Python
24 lines
708 B
Python
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))
|