Invalid Capability

Hi! I develop app
when setCapabilityOptions with empty object and read it app throw a error
2024-09-16T16:00:00.401Z [err] [ManagerDrivers] [Driver:light] [Device:5b53fe8d-6b85-4d03-ab98-4ad17974cbff] Device.onInit Error: Error: Invalid Capability: dim

here is my code

if (!this.hasCapability(capability)) {
  await this.addCapability(capability);
   await this.setCapabilityOptions(capability, {});
}
const capabilityOptions = this.getCapabilityOptions(capability);

expect get empty object {} in capabilityOptions

So on which call does it fail exactly?

const capabilityOptions = this.getCapabilityOptions(capability);

It could be that adding a new capability in onInit requires that method to end before you can use the capability, or retrieve its options.

So something like this:

async onInit() {
  if (!this.hasCapability(capability)) {
    await this.addCapability(capability);
    await this.setCapabilityOptions(capability, {});
  }
  setTimeout(() => this.onInit2(), 0);
}

async onInit2() {
  const capabilityOptions = this.getCapabilityOptions(capability);
}