Class 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.
-
Constructor Summary
ConstructorsConstructorDescriptionCommissioner(com.codename1.impl.home.CommissioningGateway gateway) Created bycom.codename1.home.SmartHome; not part of the public surface. -
Method Summary
Modifier and TypeMethodDescriptioncommission(CommissioningRequest request) Adds an accessory.getStyle()How this backend adds an accessory.booleanWhethercommission(CommissioningRequest)can do anything here.booleanOpens the platform's ecosystem app -- Apple Home, Google Home -- so the user can add an accessory there instead.
-
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, ornullfor an inert commissioner
-
-
Method Details
-
getStyle
How this backend adds an accessory.
Returns
the style, never
null -
isSupported
public boolean isSupported()Whether
commission(CommissioningRequest)can do anything here.falseon 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
truewhen this platform can commission -
commission
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()isfalse, and a reasonable fallback when commissioning fails for reasons your app cannot fix.Returns
truewhen the app was opened;falsewhen it is not installed, which is worth telling the user, since installing it is something they can do
-