Debugging event subscribe() failure

My code seemed to be working this morning. Now it isn't, and I can't think of what I might have changed.

The call is:

        subscribe(selectedDevices, selectedCapability, handler)

Where "selectedDevices" is the list from the multi-select input, selectedCapability is capability.temperatureMeasurement, and hander is the method of the form def handler(evt)

The App Instance is listed after subscribing, for each device in the "In Use By" section, so subscribe seems to be working. But while events from those devices go to other handlers, they don't go to mine, as determined from the Device Events "Triggered Apps" lists.

What might I be doing wrong, that my app is listed as using the device but never triggers on events?

Are you sure the subscribe code you showed is actually getting called? You could put a log.debug "oops if missing" right after that, so you'd know ...

Yes, it's getting called, since a log line right before it is getting called, but based on your advice I added another one after.
It's not returning from subscribe(). Not getting an error, nothing logged, just not getting to the next line.

        log.info("${thisChartName}: Subscribing to ${selectedDevices} for capability ${selectedCapability}.")
        subscribe(selectedDevices, selectedCapability, handler)
        log.info("${thisChartName}: Subscribe complete.")

Only returns the first log line:
Test1850: Subscribing to [Sensorama, Office, Bedroom, Main] for capability capability.temperatureMeasurement.

Any thoughts on how to find why it's not getting to the second?

You subscribe to events (attributes), not capabilities.

1 Like

Thank you. That was apparently it.
Is there a more intuitive way to get there than, essentially...

@Field static capabilityToAttribute = [
    "capability.temperatureMeasurement": "temperature",
    "capability.battery": "battery",
    "capability.contactSensor": "contact",
    "capability.motionSensor": "motion",
    ...
]
def attr = capabilityToAttribute[selectedCapability]

?

Not really. Only you know what you what you're looking for with whatever capability (e.g., a specific command or attribute), so that seems as good as any approach to me.