Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvery accessory in this home, in every room and in none.getAccessoriesInRoom(String roomId) The accessories in one room.getAccessoriesSupporting(Trait trait) Every accessory in this home that exposes a trait.getAccessory(String accessoryId) One accessory by identifier.getId()The identifier this structure is addressed by.getName()The user-visible name, empty when the structure has none.One room by identifier.getRooms()The rooms in this home.The scenes in this home.getZones()The zones in this home.booleanisOwner()Whether the user owns this home rather than having been invited to it.booleanWhether this is the user's default home.booleanWhether scenes can be created and deleted in this home throughSmartHome.createScene(HomeStructure, java.lang.String, java.util.List)andSmartHome.deleteScene(Scene).toString()Returns a string representation of the object.
-
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) Creates a structure snapshot. Called by the ports and by the local home; application code receives these rather than building them.
Parameters
-
id: the structure identifier -
name: the user-visible name, ornullfor none -
primary: whether this is the user's default home -
owner: whether the user owns this home rather than being a guest -
sceneAuthoringSupported: whether scenes can be created and deleted here -
rooms: its rooms;nullbecomes empty -
zones: its zones;nullbecomes empty, which is what every backend but HomeKit produces -
accessories: its accessories;nullbecomes empty -
scenes: its scenes;nullbecomes empty
Throws
IllegalArgumentException: whenidisnullor empty
-
-
-
Method Details
-
getId
The identifier this structure is addressed by.
Returns
the identifier, never
null -
getName
The user-visible name, empty when the structure has none. The user's own text; treat it as untrusted beyond display.
Returns
the name, never
null -
isPrimary
public boolean isPrimary()Whether this is the user's default home.
Always
falseon iOS. Apple deprecatedHMHomeManager.primaryHomein 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 reportsfalsefor every home rather than guessing, andSmartHome.getPrimaryStructure()falls back to the first -- which is at least not a claim about what the user prefers.Returns
truefor the primary structure -
isOwner
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.UNAUTHORIZEDin a home they own; this is worth surfacing mainly so an app can explain why a control it offered did not work.Always
falseon 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 byisSceneAuthoringSupported()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
truewhen the user is the owner -
isSceneAuthoringSupported
public boolean isSceneAuthoringSupported()Whether scenes can be created and deleted in this home through
SmartHome.createScene(HomeStructure, java.lang.String, java.util.List)andSmartHome.deleteScene(Scene).falseon 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
truewhen scenes can be authored here -
getRooms
-
getZones
-
getAccessories
-
getScenes
-
getRoom
-
getAccessory
-
getAccessoriesInRoom
-
getAccessoriesSupporting
-
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())
-