Skip to content

Commit

Permalink
Merge pull request #972 from sisamiwe/dev-dbaddon2
Browse files Browse the repository at this point in the history
DB_ADDON:
  • Loading branch information
onkelandy authored Dec 10, 2024
2 parents 388cec8 + d1702da commit 062c56f
Show file tree
Hide file tree
Showing 6 changed files with 814 additions and 728 deletions.
1,045 changes: 606 additions & 439 deletions db_addon/__init__.py

Large diffs are not rendered by default.

75 changes: 0 additions & 75 deletions db_addon/item_attributes.py

This file was deleted.

375 changes: 185 additions & 190 deletions db_addon/item_attributes_master.py

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions db_addon/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ plugin:
# keywords: iot xyz
# documentation: https://github.com/smarthomeNG/smarthome/wiki/CLI-Plugin # url of documentation (wiki) page
support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1848494-support-thread-databaseaddon-plugin
version: 1.2.9 # Plugin version (must match the version specified in __init__.py)
version: 1.2.10 # Plugin version (must match the version specified in __init__.py)
sh_minversion: 1.9.3.5 # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
py_minversion: '3.8' # minimum Python version to use for this plugin
py_minversion: '3.9' # minimum Python version to use for this plugin
# py_maxversion: # maximum Python version to use for this plugin (leave empty if latest)
multi_instance: false # plugin supports multi instance
restartable: unknown
Expand Down Expand Up @@ -69,6 +69,13 @@ parameters:
de: Sperren der Datenbank während der Abfrage
en: Lock the database during queries

pause_item:
type: str
default: ''
description:
de: 'Item, um die Ausführung des Plugins zu steuern'
en: 'item for controlling plugin execution'

item_attributes:
db_addon_fct:
type: str
Expand Down
26 changes: 9 additions & 17 deletions db_addon/webif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def index(self, reload=None, action=None, item_path=None, active=None, option=No

return tmpl.render(p=self.plugin,
webif_pagelength=pagelength,
suspended='true' if self.plugin.suspended else 'false',
items=self.plugin.get_item_list('db_addon', 'function'),
item_count=len(self.plugin.get_item_list('db_addon', 'function')),
plugin_shortname=self.plugin.get_shortname(),
plugin_version=self.plugin.get_version(),
plugin_info=self.plugin.get_info(),
maintenance=True if self.plugin.log_level < 20 else False,
paused=not(self.plugin.alive)
)

@cherrypy.expose
Expand All @@ -116,7 +116,6 @@ def get_data_html(self, dataSet=None):
data['items'][item.property.path]['last_update'] = item.property.last_update.strftime('%d.%m.%Y %H:%M:%S')
data['items'][item.property.path]['last_change'] = item.property.last_change.strftime('%d.%m.%Y %H:%M:%S')

data['plugin_suspended'] = self.plugin.suspended
data['maintenance'] = True if self.plugin.log_level == 10 else False
data['queue_length'] = self.plugin.queue_backlog()
data['active_queue_item'] = self.plugin.active_queue_item
Expand Down Expand Up @@ -149,12 +148,15 @@ def submit(self, item=None):
self.logger.debug(f"Result for web interface: {result}")
return json.dumps(result).encode('utf-8')

elif cmd.startswith("suspend_plugin_calculation"):
self.logger.debug(f"set_plugin_calculation {cmd=}")
elif cmd.startswith("pause_plugin"):
self.logger.debug(f"pause_plugin {cmd=}")
cmd, value = cmd.split(',')
value = True if value == "True" else False
self.logger.info(f"Plugin will be set to suspended: {value} via WebIF.")
result = self.plugin.suspend(value)
if value == "True":
self.plugin.stop()
else:
self.plugin.run()
self.logger.warning(f"Plugin will be set to paused: {value} via WebIF.")
result = not(self.plugin.alive)
self.logger.debug(f"Result for web interface: {result}")
return json.dumps(result).encode('utf-8')

Expand Down Expand Up @@ -187,16 +189,6 @@ def clear_queue(self):
self.logger.debug(f"_clear_queue called")
self.plugin._clear_queue()

@cherrypy.expose
def activate(self):
self.logger.debug(f"active called")
self.plugin.suspend(False)

@cherrypy.expose
def suspend(self):
self.logger.debug(f"suspend called")
self.plugin.suspend(True)

@cherrypy.expose
def debug_log_option(self, log: str = None, state: bool = None):
self.logger.warning(f"debug_log_option called with {log=}, {state=}")
Expand Down
10 changes: 5 additions & 5 deletions db_addon/webif/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@
<!-- Additional script tag for plugin specific javascript code go into this block -->
{% block pluginscripts %}
<script>
function togglePlayPause(id, suspended) {
function togglePlayPause(id, paused) {
const escapedId = $.escapeSelector(id);
const buttonElement = $("#" + escapedId);
const icon = buttonElement.find('i');
recalcElement = $("#" + escapedId.replace(/_button_playpause$/, "_button_recalc"));

if (suspended == "true") {
if (paused == "true") {
// Change to pause icon
recalcElement.prop("disabled", true);
if (id.startsWith("plugin"))
buttonElement.val(id.replace(/_button_playpause$/, "") + ":suspend_plugin_calculation,False");
buttonElement.val(id.replace(/_button_playpause$/, "") + ":pause_plugin,False");
else
buttonElement.val(id.replace(/_button_playpause$/, "") + ":suspend_item_calculation,False");
icon.removeClass('fa-play').addClass('fa-pause');
Expand All @@ -87,7 +87,7 @@
} else {
// Change to play icon
if (id.startsWith("plugin"))
buttonElement.val(id.replace(/_button_playpause$/, "") + ":suspend_plugin_calculation,True");
buttonElement.val(id.replace(/_button_playpause$/, "") + ":pause_plugin,True");
else
buttonElement.val(id.replace(/_button_playpause$/, "") + ":suspend_item_calculation,True");
recalcElement.prop("disabled", false);
Expand Down Expand Up @@ -304,7 +304,7 @@
<td class="py-1" width="150px"><strong>{{ _('Treiber') }}</strong></td>
<td class="py-1">{{ p.db_driver }}</td>
<td class="py-1" width="150px"><strong>{{ _('Startup Delay') }}</strong></td>
<td class="py-1">{{ (p.startup_run_delay) }}s</td>
<td class="py-1">{{ (p.startup_run_delay) }}s {{paused}} </td>
</tr>
{% set first = True %}
{% if p._db %}
Expand Down

0 comments on commit 062c56f

Please sign in to comment.