Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] virtual-device-app: Add Doorlock/PowerSource repository #29127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}