Git Product home page Git Product logo

Comments (7)

msinn avatar msinn commented on May 26, 2024

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.

bmxp avatar bmxp commented on May 26, 2024

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.

msinn avatar msinn commented on May 26, 2024

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.

onkelandy avatar onkelandy commented on May 26, 2024

That would be a nice feature.. The autoblind plugin is using this method successfully.

from smarthome.

msinn avatar msinn commented on May 26, 2024

Feature implementation: PR #94

(German) documentation is here: https://github.com/smarthomeNG/smarthome/wiki/Items:-Relative-Item-Referenzen

from smarthome.

ohinckel avatar ohinckel commented on May 26, 2024

I guess we can close this issue, right?

from smarthome.

msinn avatar msinn commented on May 26, 2024

Right!

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.