Class TraitWrite
One change to make: set one Trait on one AccessoryService to one value.
TraitWrite w = new TraitWrite(lamp, lamp.getPrimaryService(),
Trait.BRIGHTNESS, TraitValue.of(40, TraitUnit.PERCENT));
SmartHome.getInstance().write(w).onResult((results, err) -> { ... });
Writes name a service, not just an accessory, because an accessory can
have several -- the two halves of a two-gang switch both expose
Trait.ON_OFF and writing to "the switch" would be ambiguous.
-
Constructor Summary
ConstructorsConstructorDescriptionTraitWrite(Accessory accessory, AccessoryService service, Trait trait, TraitValue value) Creates a write against a snapshot.TraitWrite(String accessoryId, String serviceId, Trait trait, TraitValue value) Creates a write against identifiers, for code working from persisted ids that has not re-fetched the graph. -
Method Summary
Modifier and TypeMethodDescriptionThe accessory this write changes.The credential set bysetAuthorizationData(java.lang.String).The service on that accessory.getTrait()The trait this write sets.getValue()The value it sets the trait to.setAuthorizationData(String authorizationData) A credential the accessory needs before it will obey.This write as a scene action, for building aSceneout of the changes a user just made.toString()Returns a string representation of the object.
-
Constructor Details
-
TraitWrite
Creates a write against a snapshot.
Parameters
-
accessory: the accessory to change -
service: the service on it -
trait: the trait to set -
value: the value to set it to
Throws
IllegalArgumentException: when any argument isnull, when the value's kind does not match the trait's, or when the trait can never be written
-
-
TraitWrite
Creates a write against identifiers, for code working from persisted ids that has not re-fetched the graph.
Parameters
-
accessoryId: the accessory to change -
serviceId: the service on it -
trait: the trait to set -
value: the value to set it to
Throws
IllegalArgumentException: when any argument isnullor empty, when the value's kind does not match the trait's, or when the trait can never be written
-
-
-
Method Details
-
setAuthorizationData
A credential the accessory needs before it will obey.
The only thing that uses this today is a Matter door lock configured with
RequirePINforRemoteOperation, which refusesTrait.TARGET_LOCK_STATEwithout a user PIN and fails the write withHomeError.PIN_REQUIRED. HomeKit never takes a PIN and ignores this.Treat the value the way you would any credential: do not log it, do not persist it in the clear, and prefer prompting for it over storing it. It is passed straight to the platform and is not retained here beyond the life of this object.
Parameters
authorizationData: the credential, ornullto clear it
Returns
this write, for chaining
-
getAuthorizationData
-
getAccessoryId
The accessory this write changes.
Returns
the accessory identifier, never
null -
getServiceId
The service on that accessory.
Returns
the service identifier, never
null -
getTrait
The trait this write sets.
Returns
the trait, never
null -
getValue
The value it sets the trait to.
Returns
the value, never
null -
toSceneAction
This write as a scene action, for building a
Sceneout of the changes a user just made.Drops any credential: a scene is replayed by the platform later, when this app is not running, and there is nowhere to put one.
Returns
an equivalent scene action
-
toString
Description copied from class:ObjectReturns 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())
-