HABApp - getting started with parameters

Hi All,

I’m trying to move my OH config to GitHub and want to isolate passwords and API keys into one file, as well as some JSON settings that I use to store time of day settings (volumes, brightness, etc) but I’m having trouble understanding how to parse subkeys from a parameter file, and would love an example of how to get a rule re-load a parameter when changed.

My novice attempt at loading a subkey looks like this, but errors out:

import HABApp
import logging

class MyRuleWithParameters(HABApp.Rule):
    def __init__(self):
        super().__init__()

        # construct parameter once, default_value can be anything
        self.min_value = HABApp.Parameter('secrets', 'min_value', default_value=10)

        # deeper structuring is possible through specifying multiple keys
        self.min_value_nested = HABApp.Parameter(
            'secrets',
            'Rule A', 'subkey1', 'subkey2',
            default_value=['a', 'b', 'c'] # defaults can also be dicts or lists
        )
        log.warning(self.min_value_nested['Rule A']['subkey1'])


log = logging.getLogger('MyRules')
MyRuleWithParameters()
 TypeError: 'Parameter' object is not subscriptable

I’m sure it is something simple I’m missing, but I can’t turn it up through searches, and it seems like I shouldn’t need to load a yml parser…

not being impatient, but forgot to tag @Spaceman_Spiff above! Outside working in the yard…

You can just tag your thread with HABApp and I’ll get a notification.

Your second usage should be DictParameter instead of Parameter

Thanks… changing that line to DictParameter still returns an error. The way it is shown is in the rule example in the docs…

ValueError: Value "['a', 'b', 'c']" for DictParameter is not a dict! (<class 'ruamel.yaml.comments.CommentedSeq'>)

I’ll submit doc changes on GitHub once I figure this out.

default_value of the DictParameter has to be a dict. In the example it’s a list.