Issue with mediaPreset capability

There is a bug in the ‘proposed’ mediaPreset capability on Edge. The table you pass into the presets event is modified and the items are removed locally in the Lua code. Running something like this will cause myPresets to be empty after emitting it. I am assuming this is not expected behavior.

local myPresets = {
    { name = 'John', id = 'A' },
    { name = 'Jane', id = 'B' },
    { name = 'Mike', id = 'C' }
}

print(json.encode(myPresets))

device:emit_event(capabilities.mediaPresets.presets(myPresets))

print(json.encode(myPresets))

Hi!
Are you using the Hub’s firmware version 43?

No. This is seen on 42.

Ah, this is similar to an issue reported here:

The team mentioned this is solved in the v43, the current solution is using deep_copy(), for example:

device.profile.components["componentID"]:emit_event(capabilities.button.supportedButtonValues(utils.deep_copy(supportedMode)))

Perfect. This sounds like the exact same issue :+1:

The solution for me was also a deep copy. Thanks

1 Like