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.

Flow<T>
<T : DeviceType> type(type: DeviceTypeFactory<T>)

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.

type

fun <T : DeviceType> type(type: DeviceTypeFactory<T>): 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.

Returns
Flow<T>

a flow that can be used to track changes to a specific type. If the type is not supported an empty flow will be 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.