# HasDeviceTypes


```
@OptIn(markerClass = [HomeExperimentalApi])
interface HasDeviceTypes : PartsProvider
```

<br />

Known direct subclasses [HomeDevice](https://developers.home.google.com/reference/kotlin/com/google/home/HomeDevice)

|---|---|
| `https://developers.home.google.com/reference/kotlin/com/google/home/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 `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` with the `https://developers.home.google.com/reference/kotlin/com/google/home/Trait`s 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:

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

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `<T : https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType> https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#has(com.google.home.DeviceTypeFactory)(type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>)` Checks if a device type is supported by this device. |
| `open https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>` | `@https://developers.home.google.com/reference/kotlin/com/google/home/annotation/HomeExperimentalApi <T : https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType> https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#part(com.google.home.DeviceTypeFactory,kotlin.Array)(type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>, vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag)` Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory` and `https://developers.home.google.com/reference/kotlin/com/google/home/Tag`. |
| `open https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T?>` | `@https://developers.home.google.com/reference/kotlin/com/google/home/annotation/HomeExperimentalApi <T : https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType> https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#partOrNull(com.google.home.DeviceTypeFactory,kotlin.Array)(type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>, vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag)` Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory` and `https://developers.home.google.com/reference/kotlin/com/google/home/Tag`. |
| `open https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/index.html<https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType>>` | `@https://developers.home.google.com/reference/kotlin/com/google/home/annotation/HomeExperimentalApi https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#parts()()` Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType`s that are parts of this `https://developers.home.google.com/reference/kotlin/com/google/home/HomeDevice`. |
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T>` | `<T : https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType> https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#type(com.google.home.DeviceTypeFactory,kotlin.Array)(type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>, vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag)` Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory`. |
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T?>` | `<T : https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType> https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#typeOrNull(com.google.home.DeviceTypeFactory,kotlin.Array)(type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>, vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag)` Gets a flow on the `DeviceType` using the given `DeviceTypeFactory`. |
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/index.html<https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType>>` | `https://developers.home.google.com/reference/kotlin/com/google/home/HasDeviceTypes#types()()` Gets a list of all available types on the `https://developers.home.google.com/reference/kotlin/com/google/home/HomeDevice`. |

### Inherited properties

From [com.google.home.HasConnectivityState](https://developers.home.google.com/reference/kotlin/com/google/home/HasConnectivityState) `https://developers.home.google.com/reference/kotlin/com/google/home/SourceConnectivity` `https://developers.home.google.com/reference/kotlin/com/google/home/HasConnectivityState#sourceConnectivity()`

Source Connectivity for the device.

## 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 `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType`s.

| Parameters |
|---|---|
| `type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>` | the factory for the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` to check. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | 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 `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory` and `https://developers.home.google.com/reference/kotlin/com/google/home/Tag`.

| Parameters |
|---|---|
| `type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>` | the device type to get. |
| `vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag` | The tags to filter by. |

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<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 `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory` and `https://developers.home.google.com/reference/kotlin/com/google/home/Tag`.

| Parameters |
|---|---|
| `type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>` | the device type to get. |
| `vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag` | The tags to filter by. |

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<T?>` | a flow that can be used to track changes to a specific type. If the type is not supported, `null` is emitted. If multiple instances match, the first match is emitted. |

### parts

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

Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType`s that are parts of this `https://developers.home.google.com/reference/kotlin/com/google/home/HomeDevice`.

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-set/index.html<https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType>>` | a flow that can be used to track changes to the parts of this device. |

### type

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

Gets a flow on the `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceType` using the given `https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory`.

For example:

```kotlin
device.type(DimmableLightDevice).collect { println(it.onOff.on) }
```

| Parameters |
|---|---|
| `type: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>` | the device type to get. |
| `vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag` | The tags to filter by. Required if the device has multiple instances of this device type. |

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<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: https://developers.home.google.com/reference/kotlin/com/google/home/DeviceTypeFactory<T>` | the device type to get. |
| `vararg tags: https://developers.home.google.com/reference/kotlin/com/google/home/Tag` | The tags to filter by. Required if the device has multiple instances of this device type. |

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<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 `https://developers.home.google.com/reference/kotlin/com/google/home/HomeDevice`. It relies on the `https://developers.home.google.com/reference/kotlin/com/google/home/FactoryRegistry#typeRegistry()` for finding the types to parse.