Disable/Enable Things

Thing owners and app admin can disable the thing. If the thing is disabled, the thing is "locked" and it will not be able to access its data resources (i.e. buckets and objects in the thing scope). The data resources themselves are kept in the backend and the thing owners and the app admin can still access them. The feature is useful, for example, when the thing is lost or stolen.

The thing owners and app admin can of course re-enable the thing. Once the thing is enabled, it is "unlocked" and it will regain the access to its data resources.

The following sample code shows how to disable a thing.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Disable the thing if it is enabled.
      if (!thing.disabled()) {
        thing.disable();
      }
    } catch (AppException e) {
      // Handle the error.
    } catch (IOException e) {
      // Handle the error.
    }
  • // Instantiate a thing by vendor thing ID.
    KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() {
      @Override
      public void onComplete(KiiThing result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Disable the thing if it is enabled.
        if (!result.disabled()) {
          result.disable(new KiiCallback<KiiThing>() {
            @Override
            public void onComplete(KiiThing result, Exception e) {
              if (e != null) {
                // Handle the error.
                return;
              }
            }
          });
        }
      }
    });

iOS

Swift 3:

  • let thing : KiiThing
    
    do{
      // Instantiate a thing by vendor thing ID.
      thing = try KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS")
    }catch(let error as NSError){
      // Handle the error.
      return
    }
    
    // Disable the thing if it is enabled.
    if !thing.disabled {
      do{
        try thing.disableSynchronous()
      } catch let error as NSError {
        // Handle the error.
        return
      }
    }
  • // Instantiate a thing by vendor thing ID.
    KiiThing.load(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Disable the thing if it is enabled.
      if !thing!.disabled {
        thing!.disable({ (thing , error) -> Void in
          if error != nil {
            // Handle the error.
            return
          }
        })
      }
    }

Objective-C:

  • NSError* error = nil;
    
    // Instantiate a thing by vendor thing ID.
    KiiThing* thing = [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                                                           error:&error];
    if (error != nil) {
      // Handle the error.
      return;
    }
    
    // Disable the thing if it is enabled.
    if (!thing.disabled) {
      [thing disableSynchronous:&error];
      if (error != nil) {
        // Handle the error.
        return;
      }
    }
  • // Instantiate a thing by vendor thing ID.
    [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                              block:^(KiiThing *thing, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Disable the thing if it is enabled.
      if (!thing.disabled) {
        [thing disable:^(KiiThing *thing, NSError *error) {
          if (error != nil) {
            // Handle the error.
            return;
          }
        }];
      }
    }];

JavaScript

// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
  success: function(thing) {
    // Disable the thing if it is enabled.
    if(!thing.getDisabled()) {
      thing.disable({
        success: function(theThing) {
          // Do something.
        },
        failure: function(theThing, error) {
          // Handle the error.
        }
      });
    }
  },
  failure: function(error) {
    // Handle the error.
  }
});

The next sample code shows how to enable a thing.

Android

  • try {
      // Instantiate a thing by vendor thing ID.
      KiiThing thing = KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS");
    
      // Enable the thing if it is disabled.
      if (thing.disabled()) {
        thing.enable();
      }
    } catch (AppException e) {
      // Handle the error.
    } catch (IOException e) {
      // Handle the error.
    }
  • // Instantiate a thing by vendor thing ID.
    KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", new KiiCallback<KiiThing>() {
      @Override
      public void onComplete(KiiThing result, Exception e) {
        if (e != null) {
          // Handle the error.
          return;
        }
    
        // Enable the thing if it is disabled.
        if (result.disabled()) {
          result.enable(new KiiCallback<KiiThing>() {
            @Override
            public void onComplete(KiiThing result, Exception e) {
              if (e != null) {
                // Handle the error.
                return;
              }
            }
          });
        }
      }
    });

iOS

Swift 3:

  • let thing : KiiThing
    
    do{
      // Instantiate a thing by vendor thing ID.
      thing = try KiiThing.loadSynchronous(withVendorThingID: "rBnvSPOXBDF9r29GJeGS")
    }catch(let error as NSError){
      // Handle the error.
      return
    }
    
    // Enable the thing if it is disabled.
    if thing.disabled {
      do{
        try thing.enableSynchronous()
      } catch let error as NSError {
        // Handle the error.
        return
      }
    }
  • // Instantiate a thing by vendor thing ID.
    KiiThing.load(withVendorThingID: "rBnvSPOXBDF9r29GJeGS") { (thing , error) -> Void in
      if error != nil {
        // Handle the error.
        return
      }
    
      // Enable the thing if it is disabled.
      if thing!.disabled {
        thing!.enable({ (thing , error) -> Void in
          if error != nil {
            // Handle the error.
            return
          }
        })
      }
    }

Objective-C:

  • NSError* error = nil;
    
    // Instantiate a thing by vendor thing ID.
    KiiThing* thing = [KiiThing loadSynchronousWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                                                           error:&error];
    
    // Enable the thing if it is disabled.
    if (thing.disabled) {
      [thing enableSynchronous:&error];
      if (error != nil) {
        // Handle the error.
        return;
      }
    }
  • // Instantiate a thing by vendor thing ID.
    [KiiThing loadWithVendorThingID:@"rBnvSPOXBDF9r29GJeGS"
                              block:^(KiiThing *thing, NSError *error) {
      if (error != nil) {
        // Handle the error.
        return;
      }
    
      // Enable the thing if it is disabled.
      if (thing.disabled) {
        [thing enable:^(KiiThing *thing, NSError *error) {
          if (error != nil) {
            // Handle the error.
            return;
          }
        }];
      }
    }];

JavaScript

// Instantiate a thing by vendor thing ID.
KiiThing.loadWithVendorThingID("rBnvSPOXBDF9r29GJeGS", {
  success: function(thing) {
    // Enable the thing if it is disabled.
    if(thing.getDisabled()) {
      thing.enable({
        success: function(theThing) {
          // Do something.
        },
        failure: function(theThing, error) {
          // Handle the error.
        }
      });
    }
  },
  failure: function(error) {
    // Handle the error.
  }
});