Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

smartvisu: Improve web interface #826

Merged
merged 6 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion smartvisu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

class SmartVisu(SmartPlugin):

PLUGIN_VERSION="1.8.13"
PLUGIN_VERSION="1.8.14"
ALLOW_MULTIINSTANCE = True

visu_definition = None
Expand Down Expand Up @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wozu ist das gut? Das sollte die SmartPlugin Klasse doch eigentlich von selbst tun.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das expand_relativepathes..? Keine Ahnung - war schon drin. Soll ich die 3 Zeilen raus kicken? Hast du das getestet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nein ich meinte

  if ('visu_acl' in item.conf):
    ...

Copy link
Member Author

@onkelandy onkelandy Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, ich hab's reverted.

self.add_item(item)


def parse_logic(self, logic):
Expand Down
8 changes: 7 additions & 1 deletion smartvisu/locale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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': '='}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zumindest die Übersetzung für Item ist doppelt gemoppelt. Die gibt es doch bereits in den globalen Übersetzungen in bin/locale.yaml. Dort sogar mit französischer Übersetzung, was durch den Eintrag hier jedoch ausgeblendet wird.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guter Hinweis, an das File hab ich nie gedacht.. da könnte man dann wohl noch einige andere Plugins säubern. Hab mal ein paar unnötige Übersetzungen rausgenommen.

'Typ': {'de': '=', 'en': 'Type'}
'Wert': {'de': '=', 'en': 'Value'}
5 changes: 2 additions & 3 deletions smartvisu/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."

44 changes: 22 additions & 22 deletions smartvisu/webif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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 = []
Expand All @@ -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)
Expand All @@ -187,4 +188,3 @@ def get_data_html(self, dataSet=None):
self.logger.error(f"get_data_html exception: {e}")

return {}

Loading