From b38ced2ad2c4fa2de1752d53a59eb9284db863ba Mon Sep 17 00:00:00 2001 From: Morg42 <43153739+Morg42@users.noreply.github.com> Date: Tue, 12 Dec 2023 16:06:48 +0100 Subject: [PATCH] z2m: update webif --- zigbee2mqtt/__init__.py | 37 ++++---------------------- zigbee2mqtt/webif/__init__.py | 26 +++++++++--------- zigbee2mqtt/webif/templates/index.html | 18 ++++++------- 3 files changed, 27 insertions(+), 54 deletions(-) diff --git a/zigbee2mqtt/__init__.py b/zigbee2mqtt/__init__.py index ddae14e60..6006a2cf9 100755 --- a/zigbee2mqtt/__init__.py +++ b/zigbee2mqtt/__init__.py @@ -29,7 +29,7 @@ from lib.model.mqttplugin import MqttPlugin from .rgbxy import Converter -# from .webif import WebInterface +from .webif import WebInterface Z2M_TOPIC = 'z2m_topic' Z2M_ATTR = 'z2m_attr' @@ -62,6 +62,7 @@ def __init__(self, sh, **kwargs): self.cycle = self.get_parameter_value('poll_period') self.read_at_init = self.get_parameter_value('read_at_init') self.bool_values = self.get_parameter_value('bool_values') + self._z2m_gui = self.get_parameter_value('z2m_gui') self._items_read = [] self._items_write = [] @@ -102,6 +103,9 @@ def __init__(self, sh, **kwargs): # Add subscription to get device announces self.add_z2m_subscription('+', '', '', '', 'dict', callback=self.on_mqtt_msg) + # try to load webif + self.init_webinterface(WebInterface) + def run(self): """ Run method for the plugin """ @@ -383,37 +387,6 @@ def on_mqtt_msg(self, topic: str, payload, qos=None, retain=None): except Exception as e: self.logger.debug(f"Error {e} occurred during decoding of last_seen using format '%Y-%m-%dT%H:%M:%SZ'.") - # # Korrektur der Brightness von 0-254 auf 0-100% - # if 'brightness' in payload: - # try: - # payload.update({'brightness': int(round(payload['brightness'] * 100 / 254, 0))}) - # except Exception as e: - # self.logger.debug(f"Error {e} occurred during decoding of brightness.") - - # # Korrektur der Farbtemperatur von "mired scale" (Reziproke Megakelvin) auf Kelvin - # if 'color_temp' in payload: - # try: - # # keep mired and "true" kelvin - # payload.update({'color_temp_mired': payload['color_temp']}) - # payload.update({'color_temp_k': int(round(1000000 / int(payload['color_temp']), 0))}) - # - # payload.update({'color_temp': int(round(10000 / int(payload['color_temp']), 0)) * 100}) - # except Exception as e: - # self.logger.debug(f"Error {e} occurred during decoding of color_temp.") - - # # Verarbeitung von Farbdaten - # if 'color_mode' in payload and 'color' in payload: - # color_mode = payload['color_mode'] - # color = payload.pop('color') - # - # if color_mode == 'hs': - # payload['hue'] = color['hue'] - # payload['saturation'] = color['saturation'] - # - # if color_mode == 'xy': - # payload['color_x'] = color['x'] - # payload['color_y'] = color['y'] - if 'data' not in self._devices[device]: self._devices[device]['data'] = {} self._devices[device]['data'].update(payload) diff --git a/zigbee2mqtt/webif/__init__.py b/zigbee2mqtt/webif/__init__.py index 03f4f45f8..47a0e4122 100755 --- a/zigbee2mqtt/webif/__init__.py +++ b/zigbee2mqtt/webif/__init__.py @@ -29,7 +29,6 @@ import cherrypy from lib.item import Items from lib.model.smartplugin import SmartPluginWebIf -from jinja2 import Environment, FileSystemLoader class WebInterface(SmartPluginWebIf): @@ -72,8 +71,8 @@ def index(self, reload=None, action=None): return tmpl.render(plugin_shortname=self.plugin.get_shortname(), plugin_version=self.plugin.get_version(), plugin_info=self.plugin.get_info(), - items=sorted(self.plugin.zigbee2mqtt_items, key=lambda k: str.lower(k['_path'])), - item_count=len(self.plugin.zigbee2mqtt_items), + items=sorted([i for i in self.plugin.get_item_list()], key=lambda x: x.path().lower()), + item_count=len(self.plugin.get_item_list()), p=self.plugin, webif_pagelength=pagelength, ) @@ -96,23 +95,24 @@ def get_data_html(self, dataSet=None): data['broker_uptime'] = self.plugin.broker_uptime() data['item_values'] = {} - for item in self.plugin.zigbee2mqtt_items: + for item in self.plugin.get_item_list(): data['item_values'][item.id()] = {} data['item_values'][item.id()]['value'] = item.property.value data['item_values'][item.id()]['last_update'] = item.property.last_update.strftime('%d.%m.%Y %H:%M:%S') data['item_values'][item.id()]['last_change'] = item.property.last_change.strftime('%d.%m.%Y %H:%M:%S') data['device_values'] = {} - for device in self.plugin.zigbee2mqtt_devices: - data['device_values'][device] = {} - if 'data' in self.plugin.zigbee2mqtt_devices[device]: - data['device_values'][device]['lqi'] = str(self.plugin.zigbee2mqtt_devices[device]['data'].get('linkquality', '-')) - data['device_values'][device]['data'] = ", ".join(list(self.plugin.zigbee2mqtt_devices[device]['data'].keys())) + for device in self.plugin._devices: + if 'data' in self.plugin._devices[device]: + data['device_values'][device] = { + 'lqi': str(self.plugin._devices[device]['data'].get('linkquality', '-')), + 'data': ", ".join(list(self.plugin._devices[device]['data'].keys())) + } else: - data['device_values'][device]['lqi'] = '-' - data['device_values'][device]['data'] = '-' - if 'meta' in self.plugin.zigbee2mqtt_devices[device]: - last_seen = self.plugin.zigbee2mqtt_devices[device]['meta'].get('lastSeen', None) + data['device_values'][device] = {'lqi': '-', 'data': '-'} + + if 'meta' in self.plugin._devices[device]: + last_seen = self.plugin._devices[device]['meta'].get('lastSeen', None) if last_seen: data['device_values'][device]['last_seen'] = last_seen.strftime('%d.%m.%Y %H:%M:%S') else: diff --git a/zigbee2mqtt/webif/templates/index.html b/zigbee2mqtt/webif/templates/index.html index f819f7e1f..2eb3966ea 100755 --- a/zigbee2mqtt/webif/templates/index.html +++ b/zigbee2mqtt/webif/templates/index.html @@ -168,7 +168,7 @@ {{ p.broker_config.qos }} {{ webif_pagelength }} {{_('Zigbee2Mqtt')}} - {{ 'GUI' }} + {{ 'GUI' }} @@ -205,7 +205,7 @@ {% for item in items %} {% set item_id = item.id() %} - {{ item_id }} + {{ item.property.path }} {{ item.property.type }} {{ item()}} {{ p.get_iattr_value(item.conf, 'zigbee2mqtt_topic') }} @@ -238,16 +238,16 @@ - {% for device in p.zigbee2mqtt_devices %} - {% if p.zigbee2mqtt_devices[device]['meta'] %} + {% for device in p._devices %} + {% if p._devices[device]['meta'] %} {{ loop.index }} {{ device }} - {{ p.zigbee2mqtt_devices[device]['meta']['ieeeAddr'] }} - {{ p.zigbee2mqtt_devices[device]['meta']['vendor'] }} - {{ p.zigbee2mqtt_devices[device]['meta']['model'] }} - {{ p.zigbee2mqtt_devices[device]['meta']['description'] }} - {{ p.zigbee2mqtt_devices[device]['meta']['modelID'] }} + {{ p._devices[device]['meta']['ieee_address'] }} + {{ p._devices[device]['meta']['manufacturer'] }} + {{ p._devices[device]['meta']['model'] }} + {{ p._devices[device]['meta']['description'] }} + {{ p._devices[device]['meta']['model_id'] }} {{ _('Init...') }} {{ _('Init...') }} {{ _('Init...') }}