Class TraitChangeBatch
A coalesced set of trait changes, delivered to a HomeChangeListener on
the EDT.
One entry per trait, not one per change
Within the subscription's window -- see
SubscriptionRequest.setMinIntervalMillis(int) -- changes are collapsed
per accessory, service and trait, keeping only the newest value. Dragging a
dimmer produces one reading showing where it ended up, not forty showing
the journey.
That means a batch is a state update, not an event log: you cannot count changes from it and you cannot see intermediate values. If you need every step, set the window to zero and accept the cost.
-
Constructor Summary
ConstructorsConstructorDescriptionTraitChangeBatch(String subscriptionId, List<TraitReading> readings, boolean initialDelivery, boolean resyncRequired) Creates a batch. -
Method Summary
Modifier and TypeMethodDescriptionThe changed values, one per trait that moved.Which subscription produced this batch.booleanisEmpty()Whether this batch carries no readings.booleanWhether this is the up-front delivery of current values rather than a report of something that just changed.booleanWhether changes were missed and the values you hold cannot be trusted.toString()Returns a string representation of the object.
-
Constructor Details
-
TraitChangeBatch
public TraitChangeBatch(String subscriptionId, List<TraitReading> readings, boolean initialDelivery, boolean resyncRequired) Creates a batch. Called by the ports and by the local home.
Parameters
-
subscriptionId: which subscription produced this -
readings: the coalesced changes;nullbecomes empty -
initialDelivery: whether this is the up-front delivery of current values requested bySubscriptionRequest.setDeliverInitialValues(boolean) -
resyncRequired: whether changes were missed
-
-
-
Method Details
-
getSubscriptionId
Which subscription produced this batch.
Matches
TraitSubscription.getId(). Worth checking when one listener serves several subscriptions.Returns
the subscription identifier, or
null -
getReadings
The changed values, one per trait that moved.
A reading here can have no value or carry an error, exactly as one from a read can -- an accessory going unreachable is a change worth delivering. See
TraitReading.Returns
an immutable list, possibly empty
-
isInitialDelivery
public boolean isInitialDelivery()Whether this is the up-front delivery of current values rather than a report of something that just changed.
Returns
truefor the initial delivery -
isResyncRequired
public boolean isResyncRequired()Whether changes were missed and the values you hold cannot be trusted.
The platform dropped its notification stream -- the app was backgrounded long enough, the connection to a hub was rebuilt, the accessory rejoined. The readings in this batch are still good; everything else you were tracking through this subscription is stale.
Re-read the traits you care about with
SmartHome.read(TraitReadRequest). Ignoring this leaves a UI showing values from before the gap, indefinitely, with nothing to indicate it.Returns
truewhen a full re-read is needed -
isEmpty
public boolean isEmpty()Whether this batch carries no readings.
An empty batch is delivered only when
isResyncRequired()istrue-- a resync is worth telling you about even with nothing to show.Returns
truewhen there are no readings -
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())
-