executeAction is intermittently called

Hi all, I have a bit of a head scratcher here. I’ve created a plugin for a custom light interface using MQTT for control. I have everything working in principle however the executeAction function is only sometimes being called when I change the values from the app. I wrote this in Python and the code is below. I know this is happening by adding a logger.log() as the first line in the function and from the MQTT packets I receive.

import nymea
import paho.mqtt.client as mqtt

mqttc = None

def on_connect(client, userdata, flags, rc):
    client.subscribe("#")

def on_message(client, userdata, msg):
    thing.setStateValue(tube_lightPowerStateTypeId, True)
    
def on_disconnect(client, userdata, flags, rc):
    pass

def setupThing(info):

    # Init the MQTT
    global mqttc
    mqttc = mqtt.Client(client_id=info.thing.paramValue(tube_lightThingDevice_idParamTypeId))
    mqttc.connect("0.0.0.0", 1883, 60)
    mqttc.loop_start()

    # All done
    info.finish(nymea.ThingErrorNoError)

def executeAction(info):

    # Obtain the devices ID as given by the params
    device_id = info.thing.paramValue(tube_lightThingDevice_idParamTypeId)

    # Should the light be on or off
    if info.actionTypeId == tube_lightPowerActionTypeId:
        # Obtain the parameter of this action
        power = info.paramValue(tube_lightPowerActionPowerParamTypeId)
        # Make the payload
        payload = f'power={power}'

    # What should the brightness be?
    if info.actionTypeId == tube_lightBrightnessActionTypeId:
        # Obtain the parameter of this action
        brightness = info.paramValue(tube_lightBrightnessActionBrightnessParamTypeId)
        # Make the payload
        payload = f'brightness={brightness}'

    # Send some stuff
    if payload:
        global mqttc
        mqttc.publish(device_id, payload=payload, qos=2, retain=False)

def thingRemoved(thing):
    global mqttc
    mqttc.loop_stop()

You don’t seem to finish the action info on success/failure, which might be the issue.
Nymea prevents the action being executed while there is already one pending. If you never finish the action, the info will timeout (30 seconds if I remember correctly) and then you can re-execute it.

You could try:

    # Send some stuff
    if payload:
        global mqttc
        mqttc.publish(device_id, payload=payload, qos=2, retain=False)
        info.finish(nymea.ThingErrorNoError)
    else:
        # Some error handling or just finish success