# Class Commissioner

java.lang.Object
com.codename1.home.commissioning.Commissioner

public final class Commissioner extends Object

Adds a new Matter accessory to the user's home.

Obtain it from `com.codename1.home.SmartHome#getCommissioner()`, which never returns `null`.

    Commissioner c = SmartHome.getInstance().getCommissioner();
    if (!c.isSupported()) {
        c.openEcosystemApp();
        return;
    }
    c.commission(new CommissioningRequest().setSetupPayload(scanned))
     .onResult((result, err) -> {
         if (err != null) {
             return;
         }
         if (result.wasCommissionedToThisApp()) {
             SmartHome.getInstance().refresh();
         }
     });

##### The flow is not yours

Both mobile backends hand the whole interaction to an operating-system sheet: iOS presents `MatterSupport`'s add-device UI and Android presents Play services' commissioning activity. There is no progress reporting, and the user may be several minutes -- they have to power the accessory on, hold a button, sometimes join it to Wi-Fi. Do not put a short timeout or a determinate progress bar behind this.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Commissioner(com.codename1.impl.home.CommissioningGateway gateway)`
  Created by `com.codename1.home.SmartHome`; not part of the public surface.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `AsyncResource<CommissioningResult>`
  `commission(CommissioningRequest request)`
  Adds an accessory.
  `CommissioningStyle`
  `getStyle()`
  How this backend adds an accessory.
  `boolean`
  `isSupported()`
  Whether `commission(CommissioningRequest)` can do anything here.
  `boolean`
  `openEcosystemApp()`
  Opens the platform's ecosystem app -- Apple Home, Google Home -- so the user can add an accessory there instead.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Commissioner

    public Commissioner(com.codename1.impl.home.CommissioningGateway gateway)

    Created by `com.codename1.home.SmartHome`; not part of the public surface.

    ###### Parameters

    - `gateway`: the machinery to delegate to, or `null` for an inert commissioner

- ## Method Details

  - ### getStyle

    public CommissioningStyle getStyle()

    How this backend adds an accessory.

    ###### Returns

    the style, never `null`

  - ### isSupported

    public boolean isSupported()

    Whether `commission(CommissioningRequest)` can do anything here.

    `false` on watchOS, tvOS and macOS, and on an Android device with no Play services. Check it before offering an "add a device" button; `openEcosystemApp()` is usually the honest alternative.

    ###### Returns

    `true` when this platform can commission

  - ### commission

    public AsyncResource<CommissioningResult> commission(CommissioningRequest request)

    Adds an accessory.

    The result resolves when the platform's flow finishes, however it finished. A user who backed out produces a failure carrying `HomeError.USER_CANCELED`, which is a normal outcome rather than something to report as an error.

    Read `CommissioningResult.wasCommissionedToThisApp()` before doing anything with the returned accessory id.

    ###### Parameters

    - `request`: what to add and where; an empty request means "open the platform UI and let the user do everything there"

    ###### Returns

    the outcome, delivered on the EDT

  - ### openEcosystemApp

    public boolean openEcosystemApp()

    Opens the platform's ecosystem app -- Apple Home, Google Home -- so the user can add an accessory there instead.

    The answer on every platform where `isSupported()` is `false`, and a reasonable fallback when commissioning fails for reasons your app cannot fix.

    ###### Returns

    `true` when the app was opened; `false` when it is not installed, which is worth telling the user, since installing it is something they can do