remove state capabilities
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
22
src/app.py
22
src/app.py
@@ -1,21 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
import logging
|
||||
from flask import Flask
|
||||
from flask_mqtt import logger
|
||||
from flask_restful import Api
|
||||
import sentry_sdk
|
||||
from sentry_sdk.integrations.flask import FlaskIntegration
|
||||
from sentry_sdk.integrations.logging import LoggingIntegration
|
||||
from sentry_sdk.integrations.sqlalchemy import SqlalchemyIntegration
|
||||
from healthcheck import HealthCheck
|
||||
|
||||
from resources import *
|
||||
from config import *
|
||||
from db import db
|
||||
from marshm import ma
|
||||
from mqtt_flask_instance import mqtt
|
||||
|
||||
from mqtt_methods import handle_status_message
|
||||
from healthchecks import health_database_status
|
||||
|
||||
"""
|
||||
Main Flask RESTful API
|
||||
@@ -33,7 +29,7 @@ if SENTRY_DSN:
|
||||
)
|
||||
sentry_sdk.init(
|
||||
dsn=SENTRY_DSN,
|
||||
integrations=[FlaskIntegration(), sentry_logging, SqlalchemyIntegration()],
|
||||
integrations=[FlaskIntegration(), sentry_logging],
|
||||
traces_sample_rate=1.0,
|
||||
send_default_pii=True,
|
||||
release=RELEASE_ID,
|
||||
@@ -48,18 +44,10 @@ app.config['MQTT_BROKER_PORT'] = MQTT_PORT
|
||||
app.config['MQTT_USERNAME'] = MQTT_USERNAME
|
||||
app.config['MQTT_PASSWORD'] = MQTT_PASSWORD
|
||||
app.config['MQTT_REFRESH_TIME'] = 1.0 # refresh time in seconds
|
||||
app.config['SQLALCHEMY_DATABASE_URI'] = \
|
||||
f"postgresql://{POSTGRES_USERNAME}:{POSTGRES_PASSWORD}@{POSTGRES_HOSTNAME}:5432/{POSTGRES_DB}?sslmode=require"
|
||||
|
||||
api = Api(app)
|
||||
db.init_app(app)
|
||||
ma.init_app(app)
|
||||
mqtt.init_app(app)
|
||||
health = HealthCheck()
|
||||
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
|
||||
|
||||
@mqtt.on_log()
|
||||
def handle_logging(client, userdata, level, buf):
|
||||
@@ -80,15 +68,9 @@ def handle_status_message_proxy(*args, **kwargs):
|
||||
handle_status_message(*args, **kwargs)
|
||||
|
||||
|
||||
api.add_resource(AllDevicesResource, "/devices")
|
||||
api.add_resource(AllDevicesOfflineResource, "/devices/offline")
|
||||
api.add_resource(AllDevicesOnlineResource, "/devices/online")
|
||||
api.add_resource(DeviceResource, "/devices/{deviceid}")
|
||||
api.add_resource(DeviceOfflineResrouce, "/devices/{deviceid}/offline")
|
||||
api.add_resource(DeviceOnlineResrouce, "/devices/{deviceid}/online")
|
||||
api.add_resource(SensorResource, "/devices/{deviceid}/{sensorid}")
|
||||
api.add_resource(SensorOfflineResource, "/devices/{deviceid}/{sensorid}/offline")
|
||||
api.add_resource(SensorOnlineResource, "/devices/{deviceid}/{sensorid}/online")
|
||||
|
||||
health.add_check(health_database_status)
|
||||
app.add_url_rule("/healthz", "healthcheck", view_func=lambda: health.run())
|
||||
|
||||
Reference in New Issue
Block a user