Skip to content

Commit

Permalink
virtual-device-app: Add Doorlock/PowerSource repository
Browse files Browse the repository at this point in the history
Signed-off-by: Jaehoon You <jaehoon.you@samsung.com>
Signed-off-by: Charles Kim <chulspro.kim@samsung.com>
  • Loading branch information
Jaehoon-You committed Sep 8, 2023
1 parent ce66c4d commit 1a0e334
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.matter.virtual.device.app.core.data.repository.cluster

import kotlinx.coroutines.flow.StateFlow

interface DoorLockManagerRepository {
fun getLockStateFlow(): StateFlow<Boolean>

suspend fun setLockState(value: Boolean)

suspend fun sendLockAlarmEvent()
}
Original file line number Diff line number Diff line change
@@ -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<Boolean> {
return doorLockManagerStub.lockState
}

override suspend fun setLockState(value: Boolean) {
Timber.d("setLockState():$value")
doorLockManagerStub.setLockState(value)
}

override suspend fun sendLockAlarmEvent() {
doorLockManagerStub.sendLockAlarmEvent()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.matter.virtual.device.app.core.data.repository.cluster

import kotlinx.coroutines.flow.StateFlow

interface PowerSourceManagerRepository {
fun getBatPercent(): StateFlow<Int>

suspend fun setBatPercentRemaining(batteryPercentRemaining: Int)
}
Original file line number Diff line number Diff line change
@@ -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<Int> {
return powerSourceManagerStub.batPercent
}

override suspend fun setBatPercentRemaining(batteryPercentRemaining: Int) {
powerSourceManagerStub.setBatPercentRemaining(batteryPercentRemaining)
}
}

0 comments on commit 1a0e334

Please sign in to comment.