Class 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.
-
Constructor Summary
ConstructorsConstructorDescriptionAccessoryService(String id, String name, ServiceType type, boolean primary, List<TraitConstraint> constraints) Creates a service snapshot. -
Method Summary
Modifier and TypeMethodDescriptiongetConstraint(Trait trait) What this service will accept for one trait.Every trait this service exposes, with what each will accept.getId()The identifier this service is addressed by, unique within its accessory.getName()The user-visible name, empty when the accessory gave none.Every trait this service exposes.getType()What this service is.booleanWhether this is the accessory's main service -- the one a UI showing a single control for the whole device should use.booleanWhether this service exposes a trait at all.toString()Returns a string representation of the object.
-
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
-
id: the service identifier, unique within its accessory -
name: the user-visible name, ornullfor none -
type: what the service is;nullbecomesServiceType.OTHER -
primary: whether this is the accessory's main service -
constraints: what each trait on this service will accept;nullbecomes empty
Throws
IllegalArgumentException: whenidisnullor empty
-
-
-
Method Details
-
getId
The identifier this service is addressed by, unique within its accessory.
Returns
the identifier, never
null -
getName
The user-visible name, empty when the accessory gave none.
Returns
the name, never
null -
getType
What this service is.
Returns
the type, never
null -
isPrimary
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
truefor the primary service -
getConstraints
Every trait this service exposes, with what each will accept.
Returns
an immutable list, possibly empty
-
getConstraint
What this service will accept for one trait.
Parameters
trait: the trait to look up, ornull
Returns
the constraint, or
nullwhen this service does not expose the trait -
supports
Whether this service exposes a trait at all.
This is the question to ask instead of switching on
getType()or onSmartHome.getBackend(). A service exposes what it exposes, and two accessories of the same type routinely differ.Parameters
trait: the trait to test, ornull
Returns
truewhen the trait is present here -
getTraits
-
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())
-