From 1285484a3c4611778fa91ef1c6dc98d9dd6ae03a Mon Sep 17 00:00:00 2001 From: Jaehoon-You <55170115+Jaehoon-You@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:09:04 +0900 Subject: [PATCH] virtual-device-app: Add Doorlock/PowerSource repository (#29127) Signed-off-by: Jaehoon You Signed-off-by: Charles Kim --- .../device/app/core/data/di/DataModule.kt | 13 ++++++++++ .../cluster/DoorLockManagerRepository.kt | 11 +++++++++ .../cluster/DoorLockManagerRepositoryImpl.kt | 24 +++++++++++++++++++ .../cluster/PowerSourceManagerRepository.kt | 9 +++++++ .../PowerSourceManagerRepositoryImpl.kt | 19 +++++++++++++++ 5 files changed, 76 insertions(+) create mode 100644 examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepository.kt create mode 100644 examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepositoryImpl.kt create mode 100644 examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepository.kt create mode 100644 examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepositoryImpl.kt diff --git a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/di/DataModule.kt b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/di/DataModule.kt index 8168f632c10275..d6dadd00f2cb87 100644 --- a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/di/DataModule.kt +++ b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/di/DataModule.kt @@ -1,8 +1,12 @@ package com.matter.virtual.device.app.core.data.di import com.matter.virtual.device.app.core.data.repository.* +import com.matter.virtual.device.app.core.data.repository.cluster.DoorLockManagerRepository +import com.matter.virtual.device.app.core.data.repository.cluster.DoorLockManagerRepositoryImpl import com.matter.virtual.device.app.core.data.repository.cluster.OnOffManagerRepository import com.matter.virtual.device.app.core.data.repository.cluster.OnOffManagerRepositoryImpl +import com.matter.virtual.device.app.core.data.repository.cluster.PowerSourceManagerRepository +import com.matter.virtual.device.app.core.data.repository.cluster.PowerSourceManagerRepositoryImpl import dagger.Binds import dagger.Module import dagger.hilt.InstallIn @@ -11,12 +15,21 @@ import dagger.hilt.components.SingletonComponent @InstallIn(SingletonComponent::class) @Module internal abstract class DataModule { + @Binds + abstract fun bindDoorLockManagerRepository( + repository: DoorLockManagerRepositoryImpl + ): DoorLockManagerRepository @Binds abstract fun bindOnOffManagerRepository( repository: OnOffManagerRepositoryImpl ): OnOffManagerRepository + @Binds + abstract fun bindPowerSourceManagerRepository( + repository: PowerSourceManagerRepositoryImpl + ): PowerSourceManagerRepository + @Binds abstract fun bindMatterRepository(repository: MatterRepositoryImpl): MatterRepository @Binds abstract fun bindNetworkRepository(repository: NetworkRepositoryImpl): NetworkRepository diff --git a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepository.kt b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepository.kt new file mode 100644 index 00000000000000..cdc7e380a94699 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepository.kt @@ -0,0 +1,11 @@ +package com.matter.virtual.device.app.core.data.repository.cluster + +import kotlinx.coroutines.flow.StateFlow + +interface DoorLockManagerRepository { + fun getLockStateFlow(): StateFlow + + suspend fun setLockState(value: Boolean) + + suspend fun sendLockAlarmEvent() +} diff --git a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepositoryImpl.kt b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepositoryImpl.kt new file mode 100644 index 00000000000000..4dfa15a01717e3 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/DoorLockManagerRepositoryImpl.kt @@ -0,0 +1,24 @@ +package com.matter.virtual.device.app.core.data.repository.cluster + +import com.matter.virtual.device.app.core.matter.manager.DoorLockManagerStub +import javax.inject.Inject +import kotlinx.coroutines.flow.StateFlow +import timber.log.Timber + +internal class DoorLockManagerRepositoryImpl +@Inject +constructor(private val doorLockManagerStub: DoorLockManagerStub) : DoorLockManagerRepository { + + override fun getLockStateFlow(): StateFlow { + return doorLockManagerStub.lockState + } + + override suspend fun setLockState(value: Boolean) { + Timber.d("setLockState():$value") + doorLockManagerStub.setLockState(value) + } + + override suspend fun sendLockAlarmEvent() { + doorLockManagerStub.sendLockAlarmEvent() + } +} diff --git a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepository.kt b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepository.kt new file mode 100644 index 00000000000000..3948f797e622a5 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepository.kt @@ -0,0 +1,9 @@ +package com.matter.virtual.device.app.core.data.repository.cluster + +import kotlinx.coroutines.flow.StateFlow + +interface PowerSourceManagerRepository { + fun getBatPercent(): StateFlow + + suspend fun setBatPercentRemaining(batteryPercentRemaining: Int) +} diff --git a/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepositoryImpl.kt b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepositoryImpl.kt new file mode 100644 index 00000000000000..d180e182b89853 --- /dev/null +++ b/examples/virtual-device-app/android/App/core/data/src/main/java/com/matter/virtual/device/app/core/data/repository/cluster/PowerSourceManagerRepositoryImpl.kt @@ -0,0 +1,19 @@ +package com.matter.virtual.device.app.core.data.repository.cluster + +import com.matter.virtual.device.app.core.matter.manager.PowerSourceManagerStub +import javax.inject.Inject +import kotlinx.coroutines.flow.StateFlow + +internal class PowerSourceManagerRepositoryImpl +@Inject +constructor(private val powerSourceManagerStub: PowerSourceManagerStub) : + PowerSourceManagerRepository { + + override fun getBatPercent(): StateFlow { + return powerSourceManagerStub.batPercent + } + + override suspend fun setBatPercentRemaining(batteryPercentRemaining: Int) { + powerSourceManagerStub.setBatPercentRemaining(batteryPercentRemaining) + } +}