Comments (7)
Suggestion for implementation:
- relative references start with a point (.)
- To reference a level higher, a point has to be added for every level
- relative parts of a path can be added to the point(s).
For instance, if you have an item subtree in the following form:
[level_1]
[[level_2]]
[[[item_1]]]
eval_trigger =
[[[[subitem_1]]]]
[[[item_2]]]
[[[[subitem_2]]]]
the eval_trigger
statement can reference
level_1.level_2.item_1
->.
level_1.level_2.item_1.subitem_1
->.subitem_1
level_1.level_2
->..
level_1.level_2.item_2
->..item_2
level_1.level_2.item_2.subitem_2
->..item_2.subitem_2
level_1
->...
from smarthome.
This is my current implementation:
############################################################# # Item Attributes ############################################################# for attr, value in config.items(): if not isinstance(value, dict): if attr in ['cycle', 'eval', 'name', 'type', 'value']: setattr(self, '_' + attr, value) elif attr in ['cache', 'enforce_updates']: # cast to bool try: setattr(self, '_' + attr, _cast_bool(value)) except: logger.warning("Item '{0}': problem parsing '{1}'.".format(self._path, attr)) continue elif attr in ['eval_trigger']: # cast to list ## extend here for two dots '..' which means parent ## this will result in a lot of writing work less when you have ## an item which is to be triggered by its parent if isinstance(value, str): if value == '..': logger.info("Parsing {0} we found eval_trigger = .. will be converted to its parent: {1}".format(self.id(), self.id())) value = self.return_parent().id() value = [value, ] setattr(self, '_' + attr, value) elif attr in ['crontab']: # cast to list if isinstance(value, str): value = [value, ] setattr(self, '_' + attr, value) elif attr == 'autotimer': time, __, value = value.partition('=') if value is not None: self._autotimer = time, value elif attr == 'threshold': low, __, high = value.rpartition(':') if not low: low = high self._threshold = True self.__th_crossed = False self.__th_low = float(low.strip()) self.__th_high = float(high.strip()) logger.debug("Item {}: set threshold => low: {} high: {}".format(self._path, self.__th_low, self.__th_high)) else: self.conf[attr] = value
And this is a typical application for it:
[[[[[Ausfall]]]]] # Ausfall = 1 name = Ausfall Stellgröße Heizkreis Windfang visu_acl = rw type = bool knx_dpt = 1 knx_init = 5/3/25 [[[[[[LastUpdate]]]]]] name = letztes Update von type = foo cache = yes eval = self.return_parent().last_update().strftime('%a %d.%m. %H:%M:%S') eval_trigger = ..
from smarthome.
I am thinking of isolating the conversion itself to a method, which can be used by plugins. The parse_item method of a plugin could call the conversion method to support relative references for the item attributed of the plugin.
from smarthome.
That would be a nice feature.. The autoblind plugin is using this method successfully.
from smarthome.
Feature implementation: PR #94
(German) documentation is here: https://github.com/smarthomeNG/smarthome/wiki/Items:-Relative-Item-Referenzen
from smarthome.
I guess we can close this issue, right?
from smarthome.
Right!
from smarthome.
Related Issues (20)
- HTTP Module: improve handling of page length and responsive design HOT 2
- CherryPy ValueError on restart HOT 2
- cache value not converted to current item type
- Issues with (re)loading logics from the editor page of the admin gui HOT 7
- structs not checked for wrong configurations? HOT 1
- Issue with smartdeviceplugin with UTF-8 response HOT 1
- Requirements von Logiken und Userfunctions installieren beim Start? HOT 7
- Websocket crashed HOT 4
- Vorschlag zum besseren Handling von Items mit Datentyp 'dict' oder 'list' HOT 25
- Websocket Exceptions HOT 4
- struct names are applied to items including the struct
- Visu subscription of a memory log activates sending of env.core.log HOT 5
- smarthome/doc/user/source/beispiele/eval.rst Beispiel "Enumeration über Liste" funktioniert nicht HOT 1
- Log configuration: allow placeholders for filename and rotate correctly HOT 1
- Delay in scenes HOT 4
- Problem when Item has the same name as a class Item method HOT 5
- Http module cannot bind on all interfaces
- Incompability to paho-mqtt-2.0.0 HOT 1
- Usage of logging.default.yaml HOT 7
- Problem bei max python Version zum Start? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smarthome.