Class AccessoryService

java.lang.Object
com.codename1.home.AccessoryService

public final class AccessoryService extends Object

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 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, or null for none

      • type: what the service is; null becomes ServiceType.OTHER

      • primary: whether this is the accessory's main service

      • constraints: what each trait on this service will accept; null becomes empty

      Throws
      • IllegalArgumentException: when id is null or empty
  • Method Details

    • getId

      public String getId()

      The identifier this service is addressed by, unique within its accessory.

      Returns

      the identifier, never null

    • getName

      public String getName()

      The user-visible name, empty when the accessory gave none.

      Returns

      the name, never null

    • getType

      public ServiceType 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

      true for the primary service

    • getConstraints

      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
      • trait: the trait to look up, or null
      Returns

      the constraint, or null when this service does not expose the trait

    • supports

      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
      • trait: the trait to test, or null
      Returns

      true when the trait is present here

    • getTraits

      public List<Trait> getTraits()

      Every trait this service exposes.

      Returns

      an immutable list, possibly empty

    • toString

      public String toString()
      Description copied from class: Object
      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())
      Overrides:
      toString in class Object