Home

@ShowFirstParty
@RequiresApi(value = 27)
class Home : HomeClient, TokenRefresh


Entry point for the Home API.

Summary

Constants

const String

Public companion functions

HomeClient
getClient(activity: Activity, homeConfig: HomeConfig)

Creates an instance of the Home API.

HomeClient
getClient(context: Context, homeConfig: HomeConfig)

Creates an instance of the Home API.

Public functions

open HomeObjectsFlow<HomeDevice>

Gets an observable flow of HomeDevices visible to the logged-in user, dependent on the context of the implementation (HomeManager, Structure, Room).

open Flow<PermissionsState>

Checks if the client has permissions to home data.

open suspend String

Refreshes OAuth tokens for the currentAccount.

open Unit

Registers an ActivityResultCaller that can be used to launch permissions-related UIs.

open suspend PermissionsResult

Triggers the permission-granting flow, getting OAuth consent from the user and completing initialization if needed.

open HomeObjectsFlow<Room>

Gets an observable flow of Rooms visible to the logged-in user.

open suspend T

Entry point for sending a batch of commands.

open HomeObjectsFlow<Structure>

Gets an observable flow of Structures visible to the logged-in user.

Constants

TAG

const val TAGString

Public companion functions

getClient

fun getClient(activity: Activity, homeConfig: HomeConfig = HomeConfig()): HomeClient

Creates an instance of the Home API.

Note: This is not the preferred Home.getClient method for 3P apps. Instead, use Home.getClient with a Context. The provided Activity here will be used to obtain the application context, which will be used to create the HomeClient. Provding the application context directly is preferred.

Parameters
activity: Activity

the app activity to use for the instance.

homeConfig: HomeConfig = HomeConfig()

configuration parameters for SDK behavior.

Returns
HomeClient

an instance of the Home API.

getClient

fun getClient(context: Context, homeConfig: HomeConfig = HomeConfig()): HomeClient

Creates an instance of the Home API.

Note: This is the preferred Home.getClient method for 3P apps.

Parameters
context: Context

the app context to use for the instance.

homeConfig: HomeConfig = HomeConfig()

configuration parameters for SDK behavior.

Returns
HomeClient

an instance of the Home API.

Public functions

devices

open fun devices(): HomeObjectsFlow<HomeDevice>

Gets an observable flow of HomeDevices visible to the logged-in user, dependent on the context of the implementation (HomeManager, Structure, Room).

Returns
HomeObjectsFlow<HomeDevice>

a flow of HomeDevices.

hasPermissions

open fun hasPermissions(): Flow<PermissionsState>

Checks if the client has permissions to home data.

Returns
Flow<PermissionsState>

a flow of client permissions.

refreshToken

open suspend fun refreshToken(): String

Refreshes OAuth tokens for the currentAccount. If sdk is unable to fetch a new OAuth token, empty string is returned.

registerActivityResultCallerForPermissions

open fun registerActivityResultCallerForPermissions(
    permissionsLauncher: ActivityResultCaller
): Unit

Registers an ActivityResultCaller that can be used to launch permissions-related UIs.

Parameters
permissionsLauncher: ActivityResultCaller

the ActivityResultCaller to register.

requestPermissions

open suspend fun requestPermissions(forceLaunch: Boolean): PermissionsResult

Triggers the permission-granting flow, getting OAuth consent from the user and completing initialization if needed.

Parameters
forceLaunch: Boolean

When false, only launch UIs in the absence of a valid account and/or OAuth token for the account. When true, always launch the UIs in order to grant additional permissions (accounts and/or structures).

Returns
PermissionsResult

the result of the permission-granting flow.

rooms

open fun rooms(): HomeObjectsFlow<Room>

Gets an observable flow of Rooms visible to the logged-in user.

Returns
HomeObjectsFlow<Room>

a flow of Rooms.

sendBatchedCommands

@HomeExperimentalApi
open suspend fun <T : Any?> sendBatchedCommands(block: BatchScope.() -> T): T

Entry point for sending a batch of commands. This method does not return until all commands in the batch have been sent and all command responses have been populated. This method will not throw if an individual command fails.

Parameters
block: BatchScope.() -> T

the block to execute.

Returns
T

the result of the block.

structures

open fun structures(): HomeObjectsFlow<Structure>

Gets an observable flow of Structures visible to the logged-in user.

Returns
HomeObjectsFlow<Structure>

a flow of Structures.