91 lines
3.3 KiB
Python
91 lines
3.3 KiB
Python
from flask import Flask, request
|
|
|
|
|
|
##---------------------------------------------------------------------------------------##
|
|
class Webserver(object):
|
|
##---------------------------------------------------------------------------------------##
|
|
##-----------------------------------------------------------------------------------##
|
|
def __init__(self, config):
|
|
##-----------------------------------------------------------------------------------##
|
|
print("Webserver initialisiert")
|
|
self.settings = config.read("settings")
|
|
self.devices = config.read("devices")
|
|
|
|
##-----------------------------------------------------------------------------------##
|
|
def run(self):
|
|
##-----------------------------------------------------------------------------------##
|
|
app = Flask(__name__)
|
|
|
|
if(self.devices['yeelight'] != None):
|
|
print("Enabled Yeelight")
|
|
from app.devices import yeelight
|
|
self.yeelight = yeelight.Yeelight(self.devices['yeelight'])
|
|
|
|
@app.route('/yeelight', methods=['POST'])
|
|
def yeelight():
|
|
app.logger.debug("JSON received...")
|
|
app.logger.debug(request.json)
|
|
if request.json:
|
|
data = request.get_json(force=True)
|
|
self.yeelight.command(data)
|
|
return '200'
|
|
else:
|
|
return '500'
|
|
else:
|
|
print("Disabled Yeelight")
|
|
|
|
if(self.devices['ssh'] != None):
|
|
print("Enabled SSH")
|
|
from app.devices import ssh
|
|
self.ssh = ssh.SSH(self.devices['ssh'])
|
|
|
|
@app.route('/ssh', methods=['POST'])
|
|
def ssh():
|
|
app.logger.debug("JSON received...")
|
|
app.logger.debug(request.json)
|
|
if request.json:
|
|
data = request.get_json(force=True)
|
|
self.ssh.command(data)
|
|
return '200'
|
|
else:
|
|
return '500'
|
|
else:
|
|
print("Disabled SSH")
|
|
|
|
if(self.devices['wol'] != None):
|
|
print("Enabled WOL")
|
|
from app.devices import wol
|
|
self.wol = wol.WOL(self.devices['wol'])
|
|
|
|
@app.route('/wol', methods=['POST'])
|
|
def wol():
|
|
app.logger.debug("JSON received...")
|
|
app.logger.debug(request.json)
|
|
if request.json:
|
|
data = request.get_json(force=True)
|
|
self.wol.command(data)
|
|
return '200'
|
|
else:
|
|
return '500'
|
|
else:
|
|
print("Disabled SSH")
|
|
|
|
if(self.devices['denon'] != None):
|
|
print("Enabled Denon")
|
|
from app.devices import denon
|
|
self.denon = wol.WOL(self.devices['denon'])
|
|
|
|
@app.route('/denon', methods=['POST'])
|
|
def denon():
|
|
app.logger.debug("JSON received...")
|
|
app.logger.debug(request.json)
|
|
if request.json:
|
|
data = request.get_json(force=True)
|
|
self.denon.command(data)
|
|
return '200'
|
|
else:
|
|
return '500'
|
|
else:
|
|
print("Disabled Denon")
|
|
|
|
app.run(debug=False, host='0.0.0.0') |