getUnitsLiveData

abstract fun getUnitsLiveData(availability: Availability, sorting: Sorting, type: IotUnit.Type? = null): LiveData<SimpleResponse<List<IotUnit>>?>

Support function to get a list with IotUnit returning LiveData.

Note: The purpose of this function is to support clients that can not use Coroutines or the Kotlin programming language!

Get a LiveData for all the IotUnit the given the parameters. This data should be observed for as long as needed as calls to SmartSpacesSdk.refresh will be update it.

Availability determines whether return all units the logged user has access to or only the ones available now. Availability.AvailableNow will filter out units booked by other users, units with restricted access times and blue-id units not yet synchronized with blue-id servers.

Sorting determines the order units will be returned. Sorting.None will simply return them on the order returned by backend. Calls using Sorting.Distance will actively scan for units and will be ordered by their distance, closest first and out-of-range at the end of the list.

To check if the unit is in range use IotUnit.isNearby. To get a list with only the ones in range applications can call:

After logout LiveData.getValue is set to null. You need to re-observe this LiveData once the user is logged out!

getUnitController()
.getUnits(Availability.All, Sorting.Distance)
.map { iotUnitList -> iotUnitList?.filter { iotUnit -> iotUnit.isNearby() } }