public final class HomeStructure
- Object
- HomeStructure
One home: HomeKit’s HMHome, a Google Home structure.
A user can have several – a house and a holiday flat – so
SmartHome.getStructures() returns a list and isPrimary() marks the one
their ecosystem app opens by default. An app that only ever wants one
should use the primary rather than the first.
An immutable snapshot; see Accessory for why.
Constructors
Methods
Inherited methods
Constructor details
HomeStructure
public HomeStructure(String id, String name, boolean primary, boolean owner, boolean sceneAuthoringSupported, List<HomeRoom> rooms, List<HomeZone> zones, List<Accessory> accessories, List<Scene> scenes)Parameters
idString- the structure identifier
nameString- the user-visible name, or
nullfor none primaryboolean- whether this is the user’s default home
ownerboolean- whether the user owns this home rather than being a guest
sceneAuthoringSupportedboolean- whether scenes can be created and deleted here
roomsList<HomeRoom>- its rooms;
nullbecomes empty zonesList<HomeZone>- its zones;
nullbecomes empty, which is what every backend but HomeKit produces accessoriesList<Accessory>- its accessories;
nullbecomes empty scenesList<Scene>- its scenes;
nullbecomes empty
Throws
IllegalArgumentException- when
idisnullor empty
Method details
getId
public String getId()Returns
nullgetName
public String getName()Returns
nullisPrimary
public boolean isPrimary()Whether this is the user’s default home.
Always false on iOS. Apple deprecated
HMHomeManager.primaryHome in iOS 16.1 as “no longer supported” and
shipped nothing to replace it, so the platform genuinely cannot say
which home the user thinks of as theirs. The iOS port reports false
for every home rather than guessing, and
SmartHome.getPrimaryStructure() falls back to the first – which is
at least not a claim about what the user prefers.
Returns
true for the primary structureisOwner
public boolean isOwner()Whether the user owns this home rather than having been invited to it.
A guest’s permissions vary by home and by accessory, so a write can
still fail with HomeError.UNAUTHORIZED in a home they own; this is
worth surfacing mainly so an app can explain why a control it offered
did not work.
Always false on iOS. HomeKit has no notion of ownership – it
reports whether the user is an administrator of the home, which an
invited resident can also be – so there is nothing to answer this
with. That capability is reported by
isSceneAuthoringSupported() instead, which is what it actually
governs. Do not use this to decide whether to offer a control; use it
only to phrase an explanation after one has failed.
Returns
true when the user is the ownerisSceneAuthoringSupported
public boolean isSceneAuthoringSupported()Whether scenes can be created and deleted in this home through
SmartHome.createScene(HomeStructure, java.lang.String, java.util.List)
and SmartHome.deleteScene(Scene).
false on backends that will run a scene but not author one, and for a
guest without permission. Check it before offering a “save this as a
scene” button.
Returns
true when scenes can be authored heregetRooms
public List<HomeRoom> getRooms()Returns
getZones
public List<HomeZone> getZones()The zones in this home.
Empty on every backend but HomeKit, which is the only one with the
concept; see HomeZone.
Returns
getAccessories
public List<Accessory> getAccessories()Returns
getScenes
public List<Scene> getScenes()Returns
getRoom
public HomeRoom getRoom(String roomId)Parameters
roomIdString- the identifier to look up, or
null
Returns
null when this home has no such roomgetAccessory
public Accessory getAccessory(String accessoryId)Parameters
accessoryIdString- the identifier to look up, or
null
Returns
null when this home has no such accessorygetAccessoriesInRoom
public List<Accessory> getAccessoriesInRoom(String roomId)Parameters
roomIdString- the room to filter by;
nullselects the accessories that are in no room at all, which is a real state on both backends and easy to lose a device in
Returns
getAccessoriesSupporting
public List<Accessory> getAccessoriesSupporting(Trait trait)Parameters
traitTrait- the trait to look for, or
null
Returns
toString
public String toString()