Skip to content

Commit

Permalink
Fix dependencies of Mijia LYWSD03MMC, run widget HTML regeneration in…
Browse files Browse the repository at this point in the history
… thread
  • Loading branch information
kizniche committed Jul 28, 2024
1 parent 857d7b1 commit c098cb7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This release changes the install directory from ~/Mycodo to /opt/Mycodo. This ne
- Fix display of values <=0 in PID Widget ([#1372](https://github.com/kizniche/Mycodo/issues/1372))
- Fix MCP23017 Pump Output KeyError
- Fix displaying Tags on Highcharts Widget
- Fix dependencies of Mijia LYWSD03MMC

### Features

Expand All @@ -37,6 +38,7 @@ This release changes the install directory from ~/Mycodo to /opt/Mycodo. This ne
- Change Dashboard grid width from 20 to 24
- Add endpoint option to RAM Input for when Mycodo is using a non-standard IP/port
- Add self.control to the Python 3 Code Action
- Run widget HTML regeneration in thread
- Update adafruit-circuitpython-ads1x15 to 2.2.25
- Update Gridstack to 10.0.1
- Update alembic to 1.13.1
Expand Down
1 change: 1 addition & 0 deletions mycodo/inputs/xiaomi_mijia_lywsd03mmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'options_disabled': ['interface'],

'dependencies_module': [
('apt', 'libglib2.0', 'libglib2.0'),
('apt', 'bluez', 'bluez'),
('apt', 'bluetooth', 'bluetooth'),
('apt', 'libbluetooth-dev', 'libbluetooth-dev'),
Expand Down
8 changes: 6 additions & 2 deletions mycodo/mycodo_flask/routes_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""collection of Page endpoints."""
import logging
import os

import flask_login
import threading
from io import BytesIO
from flask import flash, jsonify, send_file, redirect, render_template, request, url_for
from flask.blueprints import Blueprint
Expand Down Expand Up @@ -636,7 +636,11 @@ def settings_diagnostic():
elif form_settings_diagnostic.install_dependencies.data:
utils_settings.settings_diagnostic_install_dependencies()
elif form_settings_diagnostic.regenerate_widget_html.data:
utils_settings.settings_regenerate_widget_html()
regen_widget_html = threading.Thread(target=utils_settings.settings_regenerate_widget_html)
regen_widget_html.start()
flash("Widget HTML Regeneration started in the background. "
"It may take a few seconds to complete. "
"Any errors will appear in the Web Log.", "success")
elif form_settings_diagnostic.upgrade_master.data:
utils_settings.settings_diagnostic_upgrade_master()

Expand Down
36 changes: 17 additions & 19 deletions mycodo/mycodo_flask/utils/utils_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1993,25 +1993,23 @@ def install_dependencies():


def settings_regenerate_widget_html():
action = gettext("Regenerate Widget HTML")
error = []

if not error:
try:
command = f'/bin/bash {INSTALL_DIRECTORY}/mycodo/scripts/upgrade_commands.sh generate-widget-html'
p = subprocess.Popen(command, shell=True)
p.communicate()

cmd = f"{INSTALL_DIRECTORY}/mycodo/scripts/mycodo_wrapper frontend_reload" \
f" | ts '[%Y-%m-%d %H:%M:%S]' >> {DEPENDENCY_LOG_FILE} 2>&1"
p = subprocess.Popen(cmd, shell=True)
p.communicate()
except Exception as except_msg:
error.append(except_msg)

flash("Widget HTML Regeneration complete.", "success")
flash_success_errors(
error, action, url_for('routes_settings.settings_diagnostic'))
try:
time.sleep(2)

cmd = f'/bin/bash {INSTALL_DIRECTORY}/mycodo/scripts/upgrade_commands.sh generate-widget-html'
out, err, status = cmd_output(cmd, stdout_pipe=False, user='root')
logger.info(
"Regenerate Widget HTML: "
f"cmd: {cmd}; out: {out}; error: {err}; status: {status}")

cmd = f"{INSTALL_DIRECTORY}/mycodo/scripts/mycodo_wrapper frontend_reload" \
f" | ts '[%Y-%m-%d %H:%M:%S]' >> {DEPENDENCY_LOG_FILE} 2>&1"
out, err, status = cmd_output(cmd, stdout_pipe=False, user='root')
logger.info(
"Frontend reload: "
f"cmd: {cmd}; out: {out}; error: {err}; status: {status}")
except Exception:
logger.exception("Regenerating widget HTML")


def settings_diagnostic_upgrade_master():
Expand Down

0 comments on commit c098cb7

Please sign in to comment.