Class TraitWriteResult

java.lang.Object
com.codename1.home.TraitWriteResult

public final class TraitWriteResult extends Object

What happened to one TraitWrite.

A batch write partly succeeding is normal, not exceptional

"Turn off every light" against a home with a dead bulb in it is a request that mostly worked. Failing the whole operation would be wrong -- the other eight lights are off, and telling the caller nothing happened would have them retry and flicker the house. So SmartHome.write(java.util.List) resolves successfully with one of these per write, and the caller decides what a partial result means for them.

The operation's own AsyncResource fails only when the request never reached the platform at all -- unauthorized, not configured, malformed.

  • Method Details

    • applied

      public static TraitWriteResult applied(TraitWrite write)

      A write the accessory accepted.

      Parameters
      • write: the write that succeeded
      Returns

      the result

      Throws
      • IllegalArgumentException: when write is null
    • failed

      public static TraitWriteResult failed(TraitWrite write, HomeError error, String message)

      A write the accessory did not accept.

      Parameters
      • write: the write that failed

      • error: why; null becomes HomeError.UNKNOWN

      • message: the platform's own text, or null

      Returns

      the result

      Throws
      • IllegalArgumentException: when write is null
    • getWrite

      public TraitWrite getWrite()

      The write this describes.

      Returns

      the write, never null

    • isApplied

      public boolean isApplied()

      Whether the accessory accepted the write.

      Note what this does not claim: that the accessory has finished doing it. A covering that accepted "go to 40 percent" will be moving for some seconds afterwards, and a fan ramps. Watch Trait.COVERING_MOTION or subscribe to the trait if you need to know when it settles.

      Returns

      true when the write was accepted

    • getError

      public HomeError getError()

      Why the write failed.

      Returns

      the error, or null when it succeeded

    • getErrorMessage

      public String getErrorMessage()

      The platform's own text for a failure.

      Returns

      the message, or null

    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object