public final class TraitSubscription
- Object
- TraitSubscription
A live watch on a set of traits, returned by
SmartHome.subscribe(SubscriptionRequest, HomeChangeListener).
Hold on to it and stop() it. A subscription the caller has dropped
keeps its listener reachable and keeps the platform delivering, so a form
that subscribes on show and never unsubscribes leaks a listener per visit
and eventually delivers the same change a dozen times. Stopping on
Form.removeNotify or in the screen’s teardown is the habit to build.
Unlike a health subscription, this does not survive the process: it lives
entirely in memory and is gone when the app is. There is no cursor to
persist because there is nothing to catch up on – see isPushDelivery().
Methods
public String getId() | The identifier this subscription is known by, matching TraitChangeBatch.getSubscriptionId(). |
public boolean isActive() | Whether this subscription is still delivering. |
public boolean isPushDelivery() | Whether the platform pushes changes as they happen, or whether they only arrive when you ask. |
public void stop() | Stops delivering, detaches the listener and releases the platform registration. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Method details
getId
public String getId()TraitChangeBatch.getSubscriptionId().Returns
nullisActive
public boolean isActive()Returns
true until stop() is calledisPushDelivery
public boolean isPushDelivery()Whether the platform pushes changes as they happen, or whether they only arrive when you ask.
true only on HomeKit, and only while your app is in the
foreground. Everywhere else – Google Home, the local simulated home
– changes are gathered and handed over when you call
SmartHome.drainChanges(), and a subscription on its own will never
fire.
So an app that watches a sensor has to do one of two things: call
drainChanges() when it comes to the foreground and on whatever
cadence suits it, or check this and tell the user plainly that live
updates are not available here. Assuming push and getting none is the
mistake this method exists to prevent, and it looks exactly like a
sensor that never triggers.
Returns
true when changes arrive without being asked forstop
public void stop()Stops delivering, detaches the listener and releases the platform registration.
Idempotent; calling it on a stopped subscription does nothing.
toString
public String toString()