public final class Accessory
- Object
- Accessory
One physical device in the home: HomeKit’s HMAccessory, a Google Home
device, one Matter node.
An immutable snapshot, not a live handle
Every getter here reads a field. Nothing calls into the platform, so nothing here can block, fail, or care which thread you are on.
The alternative – a proxy over the platform’s own live object – was
rejected: HMAccessory is a mutable Objective-C object whose properties
are only safe to touch on the main queue, so every getter would have been a
cross-boundary call with a threading rule attached, and under ParparVM an
expensive one. Reading six properties to lay out a row would be six hops.
The cost is that a snapshot goes stale. When the topology moves – an
accessory added, removed, renamed, moved between rooms, or its reachability
flipping – a HomeStructureListener fires and you fetch again. Trait
values are not part of the snapshot at all; read them with
SmartHome.read(TraitReadRequest) or watch them with a
TraitSubscription.
Constructors
Methods
Inherited methods
Constructor details
Accessory
public Accessory(String id, String name, String roomId, AccessoryCategory category, String manufacturer, String model, String firmwareVersion, boolean reachable, String bridgeAccessoryId, List<AccessoryService> services)Parameters
idString- the accessory identifier, unique within the backend
nameString- the user-visible name, or
nullfor none roomIdString- the room it is in, or
nullwhen it is in none categoryAccessoryCategory- roughly what it is;
nullbecomesAccessoryCategory.OTHER manufacturerString- the maker, or
null modelString- the model name, or
null firmwareVersionString- the firmware version, or
null reachableboolean- whether the platform could talk to it when the snapshot was taken
bridgeAccessoryIdString- the bridge it sits behind, or
nullwhen it talks to the platform directly servicesList<AccessoryService>- its functional endpoints;
nullbecomes empty
Throws
IllegalArgumentException- when
idisnullor empty
Method details
getId
public String getId()The identifier this accessory is addressed by.
Unique across the whole backend, not merely within its structure, so a read or a write needs only this and a service id.
Stable for the life of the process on every backend, and stable across
launches wherever the platform provides a stable identifier – which
both do today. SmartHome.areIdsPersistent() is the honest answer for
a given backend, and is what to check before persisting one as a user’s
favourite.
Returns
nullgetName
public String getName()The user-visible name, empty when the accessory has none.
This is the user’s own text, from their ecosystem app. Treat it as untrusted for anything beyond display.
Returns
nullgetRoomId
public String getRoomId()Returns
null when it is not assigned to onegetCategory
public AccessoryCategory getCategory()Returns
nullgetManufacturer
public String getManufacturer()Returns
nullgetModel
public String getModel()Returns
nullgetFirmwareVersion
public String getFirmwareVersion()Returns
nullisReachable
public boolean isReachable()Whether the platform could talk to this accessory when the snapshot was taken.
A snapshot’s answer, so it can be out of date; the current answer
arrives through StructureChangeKind.REACHABILITY_CHANGED. An
operation on an unreachable accessory fails with
HomeError.ACCESSORY_UNREACHABLE, which is worth handling even when
this said true.
Returns
true when the accessory was reachableisBridged
public boolean isBridged()Whether this accessory sits behind a bridge rather than talking to the platform directly.
Worth surfacing because a bridge going offline takes every accessory behind it with it, and “twelve lights stopped responding” is much easier to explain when you can name the one device that actually failed.
Returns
true when getBridgeAccessoryId() names a bridgegetBridgeAccessoryId
public String getBridgeAccessoryId()Returns
null when it is not bridgedgetServices
public List<AccessoryService> getServices()Returns
getService
public AccessoryService getService(String serviceId)Parameters
serviceIdString- the identifier to look up, or
null
Returns
null when this accessory has no such servicegetPrimaryService
public AccessoryService getPrimaryService()The accessory’s main service – what a UI showing one control for the whole device should drive.
Falls back to the first service when none is flagged primary, and to
null only when there are no services at all.
Returns
nullgetServicesSupporting
public List<AccessoryService> getServicesSupporting(Trait trait)Every service on this accessory that exposes a trait.
More than one for a device with repeated endpoints – the two halves of
a two-gang switch both expose Trait.ON_OFF – which is exactly why a
write names a service rather than an accessory.
Parameters
traitTrait- the trait to look for, or
null
Returns
supports
public boolean supports(Trait trait)Parameters
traitTrait- the trait to test, or
null
Returns
true when at least one service has ittoString
public String toString()