Git Product home page Git Product logo

Comments (5)

msinn avatar msinn commented on June 21, 2024

a) replace all method calls in core, e.g. in smartplugin by the property. For example instead of item.path() -> item.property.path

Nope, that would only fix the issue, if the class methods in question would be removed and that would be a massive breaking change.

b) extend the item check functionality that tests for item names that might clash with python to also log a warning if an item is called the same as an item method

Could be done, but I haven't seen any problem reports concerning this in the forum or issues up to now.

Furthermore, I think in https://smarthomeng.github.io/dev_doc/lib/item_class_item.html the "Available only in SmartHomeNG v1.6, not in versions above" for path() is wrong?

Yup

from smarthome.

onkelandy avatar onkelandy commented on June 21, 2024

Ad a) Ja, stimmt schon, andererseits würde ein Anpassen des Core Codes zumindest die Gefahr drastisch verringern, dass da was Unerwartetes passiert.
ad b) Kann dir gerne einen Forumbeitrag erstellen ;) Bin selbst erst grad bei der Kombination von smartvisu Plugin WebIF und lms Plugin auf den Fehler gestoßen..

Jan 30 21:37:48 ERROR    cherrypy.error.546951669792 [30/Jan/2024:21:37:48] HTTP 
Traceback (most recent call last):
  File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 638, in respond
    self._do_respond(path_info)
  File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cprequest.py", line 697, in _do_respond
    response.body = self.handler()
  File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/lib/encoding.py", line 223, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/home/smarthome/.local/lib/python3.9/site-packages/cherrypy/_cpdispatch.py", line 54, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/usr/local/smarthome/plugins/smartvisu/webif/__init__.py", line 144, in get_data_html
    item_config = self.plugin.get_item_config(item)
  File "/usr/local/smarthome/lib/model/smartplugin.py", line 280, in get_item_config
    return self._plg_item_dict[item_path].get('config_data')
KeyError: 'file:///music/Discographies/Therapy/Therapy%20-%201994%20-%20Troublegum/01.%20Therapy%20-%20Knives.mp3'

Es wurde hier also der Wert des Unteritems namens path ausgewertet anstatt dass der Itempfad zurückgegeben wurde. Werde jetzt mal das Pluginstruct anpassen oder wie sollen wir hier vorgehen? Ist halt auch ein breaking change, aber das Plugin ist noch recht frisch und vermutlich nicht sonderlich weit verbreitet...

from smarthome.

Morg42 avatar Morg42 commented on June 21, 2024

Das Problem rührt natürlich im Kern daher, dass Unteritems als Objektvariablen im Item angelegt werden (was nicht selbstverständlich und nicht streng notwendig ist). Während das tatsächlich Probleme machen kann, halte ich das nicht für sinnvoll verzichtbar; als Architekturfeature müsste der gesamte Core und ein Großteil der Plugins neu geschrieben werden.

Variante b) würde das Problem lösen zu Lasten der User, die ihre Items umbenennen müssten. Lösen allerdings nur vorläufig; wenn lib.item.item irgendwann neue Methoden bekommt (siehe add_item/remove_item/..., auch wenn das schlechte Beispiele sind ;) ), passierte das wieder von Neuem.

Also entweder
a) damit leben und Plugins (Core?) so anpassen, dass statt item.id() -> item.path() -> item.property.path verwendet wird und das gelegentliche Problem hinnehmen,
b) beim Lesen der Items prüfen, ob der Name des Sub-Items als Methode/Eigenschaft des Items vorhanden ist und
ba) das Unteritem nicht anlegen
bb) das Unteritem nicht als Objekteigenschaft einbinden (schlecht, weil inkonsistent)

Ich sehe das nicht als kurzfristig dringendes Problem und tendiere daher zu b) bzw. bb)

from smarthome.

msinn avatar msinn commented on June 21, 2024

Ich hätte noch eine Option, eine Variante zu ba): Eine Warning loggen.

Bisher gibt es in lib/config.py die Methoden remove_reserved() (verhindert Itemnamen, die einem shng Keyword entsprechen) und remove_keyword (verhindert Item Namen, die einem Python keyword entsprechen).

Als shng Keywords sind dort bisher nur ['set', 'get', 'property'] definiert.

Man könnte eine Methode warn_reserved() ergänzen, die zwar die Anlage des Items zulässt, aber einen Log Eintrag erstellt. Die offene Frage dabei ist, wie man die Liste der entsprechenden Keywords am einfachsten erstellt. Ein Ansatz könnte sein, die Liste z.B. mit dir(Item) zu erstellen. Damit würde sie immer aktuell sein.

Als Nachteil ergäbe sich, dass sich die Startzeit von shng erhöht.

from smarthome.

Morg42 avatar Morg42 commented on June 21, 2024

Fixed by #628

from smarthome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.