public final class TraitWrite
- Object
- 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.
Constructors
public TraitWrite(Accessory accessory, AccessoryService service, Trait trait, TraitValue value) | Creates a write against a snapshot. |
public 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. |
Methods
public TraitWrite setAuthorizationData(String authorizationData) | A credential the accessory needs before it will obey. |
public String getAuthorizationData() | The credential set by setAuthorizationData(java.lang.String). |
public String getAccessoryId() | The accessory this write changes. |
public String getServiceId() | The service on that accessory. |
public Trait getTrait() | The trait this write sets. |
public TraitValue getValue() | The value it sets the trait to. |
public SceneAction toSceneAction() | This write as a scene action, for building a Scene out of the changes a user just made. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
TraitWrite
public TraitWrite(Accessory accessory, AccessoryService service, Trait trait, TraitValue value)Parameters
accessoryAccessory- the accessory to change
serviceAccessoryService- the service on it
traitTrait- the trait to set
valueTraitValue- the value to set it to
Throws
IllegalArgumentException- when any argument is
null, when the value’s kind does not match the trait’s, or when the trait can never be written
TraitWrite
public TraitWrite(String accessoryId, String serviceId, Trait trait, TraitValue value)Parameters
accessoryIdString- the accessory to change
serviceIdString- the service on it
traitTrait- the trait to set
valueTraitValue- the value to set it to
Throws
IllegalArgumentException- when any argument is
nullor empty, when the value’s kind does not match the trait’s, or when the trait can never be written
Method details
setAuthorizationData
public TraitWrite setAuthorizationData(String authorizationData)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 refuses
Trait.TARGET_LOCK_STATE without a user PIN and fails the write with
HomeError.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
authorizationDataString- the credential, or
nullto clear it
Returns
getAuthorizationData
public String getAuthorizationData()setAuthorizationData(java.lang.String).Returns
nullgetAccessoryId
public String getAccessoryId()Returns
nullgetServiceId
public String getServiceId()Returns
nullgetTrait
public Trait getTrait()Returns
nullgetValue
public TraitValue getValue()Returns
nulltoSceneAction
public SceneAction toSceneAction()This write as a scene action, for building a Scene out 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
toString
public String toString()