HasDeviceTypes

interface HasDeviceTypes

Known direct subclasses
HomeDevice

A device supporting traits, commands, and subscriptions.


This interface allows for getting device types from a Device. Returns the API-generated class for the DeviceType with the Traits populated by a snapshot at the time of the call. Null if the type is not present or not accessible to the caller.

For example:

if(device.has(DimmableLightDevice)) {
println(device.type(DimmableLightDevice).first().onOff.on)
}

Summary

Public functions

Boolean
<T : DeviceType> has(type: DeviceTypeFactory<T>)

Checks if a device type is supported by this device.

open Flow<T>
@HomeExperimentalApi
<T : DeviceType> part(type: DeviceTypeFactory<T>, vararg tags: Tag)

Gets a flow on the DeviceType using the given DeviceTypeFactory and Tag.

open Flow<T?>
@HomeExperimentalApi
<T : DeviceType> partOrNull(type: DeviceTypeFactory<T>, vararg tags: Tag)

Gets a flow on the DeviceType using the given DeviceTypeFactory and Tag.

open Flow<Set<DeviceType>>

Gets a flow on the DeviceTypes that are parts of this HomeDevice.

Flow<T>
<T : DeviceType> type(type: DeviceTypeFactory<T>, vararg tags: Tag)

Gets a flow on the DeviceType using the given DeviceTypeFactory.

Flow<T?>
<T : DeviceType> typeOrNull(type: DeviceTypeFactory<T>, vararg tags: Tag)

Gets a flow on the DeviceType using the given DeviceTypeFactory.

Flow<Set<DeviceType>>

Gets a list of all available types on the HomeDevice.

Public functions

has

fun <T : DeviceType> has(type: DeviceTypeFactory<T>): Boolean

Checks if a device type is supported by this device. Uses a locally cached list of supported DeviceTypes.

Parameters
type: DeviceTypeFactory<T>

the factory for the DeviceType to check.

Returns
Boolean

true if the device type is supported, false otherwise.

part

@HomeExperimentalApi
open fun <T : DeviceType> part(type: DeviceTypeFactory<T>, vararg tags: Tag): Flow<T>

Gets a flow on the DeviceType using the given DeviceTypeFactory and Tag.

Parameters
type: DeviceTypeFactory<T>

the device type to get.

vararg tags: Tag

The tags to filter by.

Returns
Flow<T>

a flow that can be used to track changes to a specific type. If the type is not supported or has multiple instances requiring tags an empty flow will be returned.

partOrNull

@HomeExperimentalApi
open fun <T : DeviceType> partOrNull(type: DeviceTypeFactory<T>, vararg tags: Tag): Flow<T?>

Gets a flow on the DeviceType using the given DeviceTypeFactory and Tag.

Parameters
type: DeviceTypeFactory<T>

the device type to get.

vararg tags: Tag

The tag to filter by.

Returns
Flow<T?>

a flow that can be used to track changes to a specific type. If the type is not supported or has multiple instances requiring tags an empty flow will be returned.

parts

@HomeExperimentalApi
open fun parts(): Flow<Set<DeviceType>>

Gets a flow on the DeviceTypes that are parts of this HomeDevice.

Returns
Flow<Set<DeviceType>>

a flow that can be used to track changes to a specific type. If the type is not supported or has multiple instances requiring tags an empty flow will be returned.

type

fun <T : DeviceType> type(type: DeviceTypeFactory<T>, vararg tags: Tag): Flow<T>

Gets a flow on the DeviceType using the given DeviceTypeFactory.

For example:

device.type(DimmableLightDevice).collect { println(it.onOff.on) }
Parameters
type: DeviceTypeFactory<T>

the device type to get.

vararg tags: Tag

The tags to filter by. Required if the device has multiple instances of this device type.

Returns
Flow<T>

a flow that can be used to track changes to a specific type. If the type is not supported or has multiple instances requiring tags an empty flow will be returned.

typeOrNull

fun <T : DeviceType> typeOrNull(type: DeviceTypeFactory<T>, vararg tags: Tag): Flow<T?>

Gets a flow on the DeviceType using the given DeviceTypeFactory. Unlike the type() API, this will never return a flow that terminates and will remain active indefinitely while being collected upon. This effectively combines Device.has() and type() into a single linear flow.

null is returned if the type is not present/supported at any time.

Parameters
type: DeviceTypeFactory<T>

the device type to get.

vararg tags: Tag

The tags to filter by. Required if the device has multiple instances of this device type.

Returns
Flow<T?>

a flow that can be used to track changes to a specific type. If the type is not supported, null is returned.

types

fun types(): Flow<Set<DeviceType>>

Gets a list of all available types on the HomeDevice. It relies on the FactoryRegistry.typeRegistry for finding the types to parse.