public final class Commissioner
- Object
- Commissioner
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.
Constructors
public Commissioner(CommissioningGateway gateway) | Created by com.codename1.home.SmartHome; not part of the public surface. |
Methods
public CommissioningStyle getStyle() | How this backend adds an accessory. |
public boolean isSupported() | Whether commission(CommissioningRequest) can do anything here. |
public AsyncResource<CommissioningResult> commission(CommissioningRequest request) | Adds an accessory. |
public boolean openEcosystemApp() | Opens the platform’s ecosystem app – Apple Home, Google Home – so the user can add an accessory there instead. |
Inherited methods
Constructor details
Commissioner
public Commissioner(CommissioningGateway gateway)com.codename1.home.SmartHome; not part of the public
surface.Parameters
gatewayCommissioningGateway- the machinery to delegate to, or
nullfor an inert commissioner
Method details
getStyle
public CommissioningStyle getStyle()Returns
nullisSupported
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 commissioncommission
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
requestCommissioningRequest- what to add and where; an empty request means “open the platform UI and let the user do everything there”
Returns
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