From 5f11b91c1a1794ab76404210e9e5de705a5989ec Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 19 Sep 2023 00:06:25 +0200 Subject: [PATCH 1/6] smartvisu plugin: update web interface to make automatic updates of logics and items work --- smartvisu/webif/__init__.py | 44 +++---- smartvisu/webif/templates/index.html | 165 +++++++++++++-------------- 2 files changed, 99 insertions(+), 110 deletions(-) diff --git a/smartvisu/webif/__init__.py b/smartvisu/webif/__init__.py index 980a70df6..41be0be2a 100755 --- a/smartvisu/webif/__init__.py +++ b/smartvisu/webif/__init__.py @@ -115,12 +115,13 @@ def index(self, reload=None): plgitems.append(item) plglogics = [] - for logic in self.logics.return_logics(): - plglogics.append(self.logics.get_logic_info(logic)) - + if self.logics: + for logic in self.logics.return_logics(): + plglogics.append(self.logics.get_logic_info(logic)) + pagelength = self.plugin.get_parameter_value('webif_pagelength') tmpl = self.tplenv.get_template('index.html') return tmpl.render(p=self.plugin, - webif_pagelength=self.plugin.get_parameter_value('webif_pagelength'), + webif_pagelength=pagelength, items=sorted(plgitems, key=lambda k: str.lower(k['_path'])), logics=sorted(plglogics, key=lambda k: str.lower(k['name'])), clients=clients_sorted, client_count=len(clients_sorted)) @@ -137,23 +138,18 @@ def get_data_html(self, dataSet=None): :return: dict with the data needed to update the web page. """ if dataSet is None: - result_array = [] - # callect data for 'items' tab - item_list = [] - # for item in self.plugin.get_item_list(): - # item_config = self.plugin.get_item_config(item) - # value_dict = {} - # value_dict['path'] = item.id() - # value_dict['type'] = item.type() - # value_dict['not_discovered'] = (item_config['bus'] == '') - # value_dict['sensor_addr'] = item_config['sensor_addr'] - # value_dict['deviceclass'] = item_config['deviceclass'] - # value_dict['value'] = item() - # value_dict['value_unit'] = item_config['unit'] - # value_dict['last_update'] = item.property.last_update.strftime('%d.%m.%Y %H:%M:%S') - # value_dict['last_change'] = item.property.last_change.strftime('%d.%m.%Y %H:%M:%S') - # item_list.append(value_dict) + item_dict = {} + for item in self.plugin.get_item_list(): + item_config = self.plugin.get_item_config(item) + value_dict = {} + value_dict['type'] = item.property.type + if ('visu_acl' in item.conf): + value_dict['acl'] = item.conf.get('visu_acl') + value_dict['value'] = item.property.value + value_dict['last_update'] = item.property.last_update.strftime('%d.%m.%Y %H:%M:%S') + value_dict['last_change'] = item.property.last_change.strftime('%d.%m.%Y %H:%M:%S') + item_dict[item.property.path] = value_dict # callect data for 'clients' tab client_list = [] @@ -174,8 +170,13 @@ def get_data_html(self, dataSet=None): value_dict['browserversion'] = clientinfo.get('browserversion', '') client_list.append(value_dict) - result = {'items': item_list, 'clients': client_list} + plglogics = [] + if self.logics: + for logic in self.logics.return_logics(): + plglogics.append(self.logics.get_logic_info(logic)) + result = {'items': item_dict, 'clients': client_list, 'logics': plglogics} + self.logger.error(result) # send result to wen interface try: data = json.dumps(result) @@ -187,4 +188,3 @@ def get_data_html(self, dataSet=None): self.logger.error(f"get_data_html exception: {e}") return {} - diff --git a/smartvisu/webif/templates/index.html b/smartvisu/webif/templates/index.html index 4fb8c9413..330993ef6 100755 --- a/smartvisu/webif/templates/index.html +++ b/smartvisu/webif/templates/index.html @@ -32,6 +32,16 @@ .access { width: 100px; } + .last_update { + width: 150px; + } + .last_change { + width: 150px; + } + .value { + width: 200px; + max-width: 400px; + } {% endblock pluginstyles %} -{% block buttons %} -{% endblock %} - - - {% set tabcount = 3 %} - - {% if item_count==0 %} {% set start_tab = 2 %} {% endif %} @@ -284,17 +273,19 @@ -{% set tab2title = "" ~ p.get_shortname() ~ " " ~ _('Items') ~ " (" ~ items|length ~ ")" %} +{% set tab2title = "" ~ p.get_shortname() ~ " " ~ _('Items') ~ " (" ~ items|length ~ ")" %} {% block bodytab2 %} {% for item in items %} - - - - + + + + + + {% endfor %} @@ -302,19 +293,17 @@ {% endblock bodytab2 %} -{% set tab3title = "" ~ p.get_shortname() ~ " " ~ _('Logiken') ~ " (" ~ logics|length ~ ")" %} +{% set tab3title = "" ~ p.get_shortname() ~ " " ~ _('Logiken') ~ " (" ~ logics|length ~ ")" %} {% block bodytab3 %}
{{ item._path }}{{ item._type }}{{ item() }}{{ item.conf['visu_acl'] }}{{ item._path }}     
{% for logic in logics %} - - - + + + {% endfor %}
{{ logic.name }}{% if logic.enabled %}{{ _('aktiv') }}{% else %}{{ _('nicht aktiv') }}{% endif %}{% if logic.visu_access %}{{ _('erlaubt') }}{% else %}{{ _('nicht erlaubt') }}{% endif %}{{ logic.name }}  
- - {% endblock bodytab3 %} From ed3de415ddedf82b67f7446b1a2b53c574edd0bd Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 19 Sep 2023 00:06:39 +0200 Subject: [PATCH 2/6] smartvisu plugin: extend locale.yaml --- smartvisu/locale.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smartvisu/locale.yaml b/smartvisu/locale.yaml index 26944c2f4..7fa6bf62c 100755 --- a/smartvisu/locale.yaml +++ b/smartvisu/locale.yaml @@ -21,4 +21,10 @@ plugin_translations: 'nicht aktiv': {'de': '=', 'en': 'disabled'} 'erlaubt': {'de': '=', 'en': 'enabled'} 'nicht erlaubt': {'de': '=', 'en': 'disabled'} - + 'Letzte Änderung': {'de': '=', 'en': 'Last Change'} + 'Letzte Aktualisierung': {'de': '=', 'en': 'Last Update'} + 'Logik': {'de': '=', 'en': 'Logic'} + 'Status': {'de': '=', 'en': '='} + 'Item': {'de': '=', 'en': '='} + 'Typ': {'de': '=', 'en': 'Type'} + 'Wert': {'de': '=', 'en': 'Value'} From 5c00346115200a7e6bed0deef56672a3349c9596 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 19 Sep 2023 00:06:57 +0200 Subject: [PATCH 3/6] smartvisu plugin: bump version to 1.8.14 --- smartvisu/__init__.py | 4 +++- smartvisu/plugin.yaml | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/smartvisu/__init__.py b/smartvisu/__init__.py index 89ce2a164..c4e108e30 100755 --- a/smartvisu/__init__.py +++ b/smartvisu/__init__.py @@ -46,7 +46,7 @@ class SmartVisu(SmartPlugin): - PLUGIN_VERSION="1.8.13" + PLUGIN_VERSION="1.8.14" ALLOW_MULTIINSTANCE = True visu_definition = None @@ -184,6 +184,8 @@ def parse_item(self, item): item.expand_relativepathes('sv_widget2', "'", "'") item.expand_relativepathes('sv_nav_aside', "'", "'") item.expand_relativepathes('sv_nav_aside2', "'", "'") + if ('visu_acl' in item.conf): + self.add_item(item) def parse_logic(self, logic): diff --git a/smartvisu/plugin.yaml b/smartvisu/plugin.yaml index aec938fd0..5d73c7f08 100755 --- a/smartvisu/plugin.yaml +++ b/smartvisu/plugin.yaml @@ -6,13 +6,13 @@ plugin: de: 'smartVISU Unterstützung: Autogenerierung von Seiten; Widget Handling' en: 'Support for smartVISU: Automatic generation of pages; widget handling' maintainer: msinn - tester: wvhn + tester: wvhn, onkelandy state: ready #keywords: iot xyz #documentation: '' support: https://knx-user-forum.de/forum/supportforen/smarthome-py/1586800-support-thread-für-das-smartvisu-plugin - version: 1.8.13 # Plugin version + version: 1.8.14 # Plugin version 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.6 # minimum Python version to use for this plugin @@ -233,4 +233,3 @@ plugin_functions: description: de: "Falls angegeben, werden nur Clients (Browser) die auf dem Host mit der angegebenen IP Adresse laufen angewiesen die Seite zu wechseln. " en: "If specified, only clients (browsers) running on the host with the specified ip address are instructed to change the page." - From 53164cd6f1f863842ad92f38bacad865e187fd34 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 19 Sep 2023 00:22:23 +0200 Subject: [PATCH 4/6] smartvisu plugin: add datatableAdditional class to tables --- smartvisu/webif/templates/index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/smartvisu/webif/templates/index.html b/smartvisu/webif/templates/index.html index 330993ef6..6dec300d8 100755 --- a/smartvisu/webif/templates/index.html +++ b/smartvisu/webif/templates/index.html @@ -266,7 +266,7 @@ --> {% set tab1title = "" ~ p.get_shortname() ~ " " ~ _('Clients') ~ " (" ~ clients|length ~ ")" %} {% block bodytab1 %} -
+
{% endblock %} @@ -276,7 +276,7 @@ {% set tab2title = "" ~ p.get_shortname() ~ " " ~ _('Items') ~ " (" ~ items|length ~ ")" %} {% block bodytab2 %} - +
{% for item in items %} @@ -295,7 +295,7 @@ {% set tab3title = "" ~ p.get_shortname() ~ " " ~ _('Logiken') ~ " (" ~ logics|length ~ ")" %} {% block bodytab3 %} -
+
{% for logic in logics %} From 365239fcef41010130f3ef00e3ed085c79d7a4f0 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Tue, 31 Oct 2023 11:50:45 +0100 Subject: [PATCH 5/6] smartvisu plugin; locale cleanup --- smartvisu/locale.yaml | 14 ++------------ smartvisu/webif/templates/index.html | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/smartvisu/locale.yaml b/smartvisu/locale.yaml index 7fa6bf62c..6d0edf398 100755 --- a/smartvisu/locale.yaml +++ b/smartvisu/locale.yaml @@ -2,29 +2,19 @@ plugin_translations: # Translations for the plugin specially for the web interface 'Websocket Protokoll': {'de': '=', 'en': 'Websocket protocol'} 'Standard Zugriff': {'de': '=', 'en': 'Default Access'} + 'Standard Zugriff (acl)': {'de': '=', 'en': 'Default Access (acl)'} 'Definitions-Abfrage': {'de': '=', 'en': 'Query definitions'} 'Erlaubt': {'de': '=', 'en': 'Allowed'} 'Verboten': {'de': '=', 'en': 'Forbidden'} 'Anzahl Clients': {'de': '=', 'en': 'Number of clients'} 'Visu Client': {'de': '=', 'en': '='} - 'IP': {'de': '=', 'en': '='} 'Port': {'de': '=', 'en': '='} - 'Protokoll': {'de': '=', 'en': 'Protocol'} + 'Port (ws / wss)': {'de': '=', 'en': '='} 'Client Software': {'de': '=', 'en': '='} - 'Browser': {'de': '=', 'en': '='} 'Keine aktiven Clients': {'de': '=', 'en': 'No active clients'} 'Visu Zugriff': {'de': '=', 'en': 'Visu Access'} - 'aktiv': {'de': '=', 'en': 'enabled'} - 'nicht aktiv': {'de': '=', 'en': 'disabled'} 'erlaubt': {'de': '=', 'en': 'enabled'} 'nicht erlaubt': {'de': '=', 'en': 'disabled'} - 'Letzte Änderung': {'de': '=', 'en': 'Last Change'} - 'Letzte Aktualisierung': {'de': '=', 'en': 'Last Update'} - 'Logik': {'de': '=', 'en': 'Logic'} - 'Status': {'de': '=', 'en': '='} - 'Item': {'de': '=', 'en': '='} - 'Typ': {'de': '=', 'en': 'Type'} - 'Wert': {'de': '=', 'en': 'Value'} diff --git a/smartvisu/webif/templates/index.html b/smartvisu/webif/templates/index.html index 6dec300d8..ba957b0df 100755 --- a/smartvisu/webif/templates/index.html +++ b/smartvisu/webif/templates/index.html @@ -115,7 +115,7 @@ targets: [4], "className": "access" }, { - title: "{{ _('Letzte Aktualisierung') }}", + title: "{{ _('Letztes Update') }}", targets: [5], "className": "last_update" }, { From c05374102a445814c93021c31c1a182cc6ae0c22 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Wed, 1 Nov 2023 20:37:27 +0100 Subject: [PATCH 6/6] smartvisu plugin: revert add_item if clause --- smartvisu/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/smartvisu/__init__.py b/smartvisu/__init__.py index c4e108e30..11bb1b303 100755 --- a/smartvisu/__init__.py +++ b/smartvisu/__init__.py @@ -184,8 +184,7 @@ def parse_item(self, item): item.expand_relativepathes('sv_widget2', "'", "'") item.expand_relativepathes('sv_nav_aside', "'", "'") item.expand_relativepathes('sv_nav_aside2', "'", "'") - if ('visu_acl' in item.conf): - self.add_item(item) + self.add_item(item) def parse_logic(self, logic):