OK... It's been an interesting journey but I think I have a better understanding now.
In the original code tgalarneau had the "write MQTT" statements are inside the Delegate code block, so when the device responds and triggers the delegate it figures out which response it is getting and then parses it and writes the MQTT message.
When I refactored his code I did not take that into account, and was doing my MQTT message writing as if it was procedural code. Sometimes it worked, sometimes not, based on whether or not the delegate had received both of the result messages. I think that explains the randomness issue. I'll do some rework and see if I can take that delegate processing into account...
In the original code tgalarneau had the "write MQTT" statements are inside the Delegate code block, so when the device responds and triggers the delegate it figures out which response it is getting and then parses it and writes the MQTT message.
When I refactored his code I did not take that into account, and was doing my MQTT message writing as if it was procedural code. Sometimes it worked, sometimes not, based on whether or not the delegate had received both of the result messages. I think that explains the randomness issue. I'll do some rework and see if I can take that delegate processing into account...