-
Notifications
You must be signed in to change notification settings - Fork 92
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
Problem when Item has the same name as a class Item method #624
Comments
Nope, that would only fix the issue, if the class methods in question would be removed and that would be a massive breaking change.
Could be done, but I haven't seen any problem reports concerning this in the forum or issues up to now.
Yup |
Ad a) Ja, stimmt schon, andererseits würde ein Anpassen des Core Codes zumindest die Gefahr drastisch verringern, dass da was Unerwartetes passiert.
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... |
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 Ich sehe das nicht als kurzfristig dringendes Problem und tendiere daher zu b) bzw. bb) |
Ich hätte noch eine Option, eine Variante zu ba): Eine Warning loggen. Bisher gibt es in lib/config.py die Methoden Als shng Keywords sind dort bisher nur Man könnte eine Methode Als Nachteil ergäbe sich, dass sich die Startzeit von shng erhöht. |
Fixed by #628 |
Quite some problems might occur if an item is named the same as a method in the item class, such as path, id, age, etc.
I suggest two approaches:
a) replace all method calls in core, e.g. in smartplugin by the property. For example instead of item.path() -> item.property.path
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
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?
The text was updated successfully, but these errors were encountered: