Parse_function is never called

If the agent output looks like this:

<<<ttn_gateway>>>
Markus TTIG (The Things Indoor Gateway 2.0.0):	64

Then I’d suggest the colon : as separator, i.e.

<<<ttn_gateway:sep(58)>>>
Markus TTIG (The Things Indoor Gateway 2.0.0):	64

The parse function can then be written as

def parse_ttn_gateway_info(info):
    parsed = {}
    for gateway, value in info:
        parsed[gateway.strip()] = saveint(value.strip())
    return parsed

This will result in

parsed = {
    'Markus TTIG (The Things Indoor Gateway 2.0.0)': 64
}

Note: the parse function will crash if the agent output does not contain exactly two fields separated by a : (as does your version, btw.). To circumvent this, use the following instead:

def parse_ttn_gateway_info(info):
    parsed = {}
    for line in info:
        if len(line)==2:
            (gateway, value) = line
            parsed[gateway.strip()] = saveint(value.strip())
    return parsed

Update: I’ve put the call to saveint into the parse function here, so you can drop that step from the check function. Or drop it here and keep it in the check function. Actually, it doesn’t matter and I have to confess I don’t do it consistently myself. :wink:

1 Like