public final class AccessoryService
- Object
- AccessoryService
One functional endpoint of an Accessory: HomeKit’s HMService, one
Matter endpoint.
The distinction matters more than it looks. A two-gang wall switch is
one accessory with two services, and writing Trait.ON_OFF to the
accessory without saying which service is ambiguous. Everything in this API
that reads or writes a trait names a service.
An immutable snapshot. Nothing here calls into the platform.
Constructors
public AccessoryService(String id, String name, ServiceType type, boolean primary, List<TraitConstraint> constraints) | Creates a service snapshot. |
Methods
public String getId() | The identifier this service is addressed by, unique within its accessory. |
public String getName() | The user-visible name, empty when the accessory gave none. |
public ServiceType getType() | What this service is. |
public boolean isPrimary() | Whether this is the accessory’s main service – the one a UI showing a single control for the whole device should use. |
public List<TraitConstraint> getConstraints() | Every trait this service exposes, with what each will accept. |
public TraitConstraint getConstraint(Trait trait) | What this service will accept for one trait. |
public boolean supports(Trait trait) | Whether this service exposes a trait at all. |
public List<Trait> getTraits() | Every trait this service exposes. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
AccessoryService
public AccessoryService(String id, String name, ServiceType type, boolean primary, List<TraitConstraint> constraints)Creates a service snapshot. Called by the ports and by the local home;
application code receives these rather than building them.
Parameters
idString- the service identifier, unique within its accessory
nameString- the user-visible name, or
nullfor none typeServiceType- what the service is;
nullbecomesServiceType.OTHER primaryboolean- whether this is the accessory’s main service
constraintsList<TraitConstraint>- what each trait on this service will accept;
nullbecomes empty
Throws
IllegalArgumentException- when
idisnullor empty
Method details
getId
public String getId()The identifier this service is addressed by, unique within its
accessory.
Returns
the identifier, never
nullgetName
public String getName()The user-visible name, empty when the accessory gave none.
Returns
the name, never
nullgetType
public ServiceType getType()What this service is.
Returns
the type, never
nullisPrimary
public boolean isPrimary()Whether this is the accessory’s main service – the one a UI showing a
single control for the whole device should use.
Returns
true for the primary servicegetConstraints
public List<TraitConstraint> getConstraints()Every trait this service exposes, with what each will accept.
Returns
an immutable list, possibly empty
getConstraint
public TraitConstraint getConstraint(Trait trait)What this service will accept for one trait.
Parameters
traitTrait- the trait to look up, or
null
Returns
the constraint, or
null when this service does not expose the traitsupports
public boolean supports(Trait trait)Whether this service exposes a trait at all.
This is the question to ask instead of switching on getType() or on
SmartHome.getBackend(). A service exposes what it exposes, and two
accessories of the same type routinely differ.
Parameters
traitTrait- the trait to test, or
null
Returns
true when the trait is present heregetTraits
public List<Trait> getTraits()Every trait this service exposes.
Returns
an immutable list, possibly empty
toString
public String toString()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())