Skip to content

Commit

Permalink
Functionality to edit driver from WUI
Browse files Browse the repository at this point in the history
Add functionality to edit *.xmq drivers from WUI
  • Loading branch information
BIBOLV committed Oct 6, 2024
1 parent 82a0795 commit b5859d8
Show file tree
Hide file tree
Showing 215 changed files with 1,891 additions and 5 deletions.
51 changes: 50 additions & 1 deletion wmbusmeters-ha-addon-edge/rootfs/flask/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json, requests, os, re, base64, zipfile, xmltodict
from flask import Flask, jsonify, render_template, request
from flask import Flask, jsonify, render_template, request, redirect, url_for
from waitress import serve
from threading import Thread
from xml.dom import minidom
Expand All @@ -10,6 +10,7 @@
app = Flask(__name__, static_url_path='')

cfgfile = '/data/options_custom.json'
DRIVER_DIRECTORY = '/data/drivers'
RESTART_URL = "http://supervisor/addons/self/restart"
URL_HEADER = { "Authorization": "Bearer " + os.environ.get('SUPERVISOR_TOKEN'), "content-type": "application/json" }

Expand Down Expand Up @@ -106,6 +107,54 @@ def decrypt():
return jsonify({'OK': {'id': meterid, 'key': meterkey}})
else:
return jsonify({'ERROR': 'Unable to extract details from file'})

@app.route('/drivers')
def drivers():
files = os.listdir(DRIVER_DIRECTORY)
return render_template('drivers.html', files=files)

@app.route('/edit_driver/<filename>', methods=['GET', 'POST'])
def edit_driver(filename):
filepath = os.path.join(DRIVER_DIRECTORY, filename)
if request.method == 'POST':
content = request.form['content']
with open(filepath, 'w') as f:
f.write(content)
return redirect(url_for('drivers'))

with open(filepath, 'r') as f:
content = f.read()
return render_template('edit_driver.html', filename=filename, content=content)

@app.route('/add_driver', methods=['GET', 'POST'])
def add_driver():
if request.method == 'POST':
filename = request.form['filename']
content = request.form['content']
filepath = os.path.join(DRIVER_DIRECTORY, filename)
with open(filepath, 'w') as f:
f.write(content)
return redirect(url_for('drivers'))
return render_template('add_driver.html', filename='', content='')

@app.route('/delete_driver/<filename>', methods=['POST'])
def delete_driver(filename):
filepath = os.path.join(DRIVER_DIRECTORY, filename)
if os.path.exists(filepath):
os.remove(filepath)
return redirect(url_for('drivers'))

@app.route('/check_filename', methods=['POST'])
def check_filename():
data = request.json
filename = data.get('filename')
if not filename:
return jsonify({'error': 'No filename provided'}), 400
file_path = os.path.join(DRIVER_DIRECTORY, filename)
if os.path.exists(file_path):
return jsonify({'exists': True})
else:
return jsonify({'exists': False})

if __name__ == '__main__':
serve(app, host="127.0.0.1", port=5000)
17 changes: 17 additions & 0 deletions wmbusmeters-ha-addon-edge/rootfs/flask/static/ace-min/ace.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
; (function() {
window.require(["ace/ext/error_marker"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b5859d8

Please sign in to comment.