-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
virtual-device-app: Add cluster stub and initialize code (#28914)
Signed-off-by: Jaehoon You <[email protected]> Signed-off-by: Charles Kim <[email protected]>
- Loading branch information
1 parent
d8fbe4e
commit 1551340
Showing
3 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...er/src/main/java/com/matter/virtual/device/app/core/matter/manager/DoorLockManagerStub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.matter.virtual.device.app.core.matter.manager | ||
|
||
import com.matter.virtual.device.app.DeviceApp | ||
import com.matter.virtual.device.app.DoorLockManager | ||
import com.matter.virtual.device.app.core.common.MatterConstants | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import timber.log.Timber | ||
|
||
@Singleton | ||
class DoorLockManagerStub @Inject constructor(private val deviceApp: DeviceApp) : DoorLockManager { | ||
|
||
private val _lockState = MutableStateFlow(false) | ||
val lockState: StateFlow<Boolean> | ||
get() = _lockState | ||
|
||
override fun initAttributeValue() { | ||
Timber.d("initAttributeValue()") | ||
deviceApp.setLockType(MatterConstants.DEFAULT_ENDPOINT, DoorLockManager.DlLockType_kMagnetic) | ||
deviceApp.setLockState(MatterConstants.DEFAULT_ENDPOINT, lockState.value.asLockState()) | ||
deviceApp.setActuatorEnabled(MatterConstants.DEFAULT_ENDPOINT, true) | ||
deviceApp.setOperatingMode( | ||
MatterConstants.DEFAULT_ENDPOINT, | ||
DoorLockManager.OperatingModeEnum_kNormal | ||
) | ||
deviceApp.setSupportedOperatingModes( | ||
MatterConstants.DEFAULT_ENDPOINT, | ||
DoorLockManager.DlSupportedOperatingModes_kNormal | ||
) | ||
} | ||
|
||
override fun handleLockStateChanged(value: Int) { | ||
Timber.d("handleLockStateChanged():$value") | ||
_lockState.value = value.asBooleanLockState() | ||
} | ||
|
||
fun setLockState(value: Boolean) { | ||
Timber.d("setLockState():$value") | ||
deviceApp.setLockState(MatterConstants.DEFAULT_ENDPOINT, value.asLockState()) | ||
} | ||
|
||
fun sendLockAlarmEvent() { | ||
Timber.d("sendLockAlarmEvent()") | ||
deviceApp.sendLockAlarmEvent(MatterConstants.DEFAULT_ENDPOINT) | ||
} | ||
|
||
private fun Boolean.asLockState() = | ||
when (this) { | ||
true -> DoorLockManager.DlLockState_kUnlocked | ||
false -> DoorLockManager.DlLockState_kLocked | ||
} | ||
|
||
private fun Int.asBooleanLockState() = | ||
when (this) { | ||
DoorLockManager.DlLockState_kUnlocked -> true | ||
DoorLockManager.DlLockState_kLocked -> false | ||
else -> false | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...src/main/java/com/matter/virtual/device/app/core/matter/manager/PowerSourceManagerStub.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.matter.virtual.device.app.core.matter.manager | ||
|
||
import com.matter.virtual.device.app.DeviceApp | ||
import com.matter.virtual.device.app.PowerSourceManager | ||
import com.matter.virtual.device.app.core.common.MatterConstants | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import timber.log.Timber | ||
|
||
@Singleton | ||
class PowerSourceManagerStub @Inject constructor(private val deviceApp: DeviceApp) : | ||
PowerSourceManager { | ||
|
||
private val _batPercent = MutableStateFlow(DEFAULT_BATTERY_STATUS) | ||
val batPercent: StateFlow<Int> | ||
get() = _batPercent | ||
|
||
override fun initAttributeValue() { | ||
Timber.d("initAttributeValue()") | ||
deviceApp.setBatPercentRemaining(MatterConstants.DEFAULT_ENDPOINT, DEFAULT_BATTERY_STATUS) | ||
} | ||
|
||
fun setBatPercentRemaining(batteryPercentRemaining: Int) { | ||
Timber.d("setBatPercentRemaining():$batteryPercentRemaining") | ||
_batPercent.value = batteryPercentRemaining | ||
deviceApp.setBatPercentRemaining(MatterConstants.DEFAULT_ENDPOINT, batteryPercentRemaining) | ||
} | ||
|
||
companion object { | ||
private const val DEFAULT_BATTERY_STATUS = 70 | ||
} | ||
} |