Skip to content

Commit b251763

Browse files
authored
Board (#45)
1 parent ef77c7a commit b251763

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

core/sdk/src/main/kotlin/com/viam/sdk/core/component/board/Board.kt

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import com.viam.sdk.core.robot.RobotClient
1111
import java.util.*
1212
import java.util.stream.Stream
1313
import kotlin.time.Duration
14+
import kotlin.time.toJavaDuration
15+
import java.time.Duration as JDuration
1416

1517
typealias Tick = StreamTicksResponse
1618

@@ -226,14 +228,23 @@ abstract class Board(name: String) : Component(SUBTYPE, named(name)) {
226228
* @param powerMode the power mode to set
227229
* @param duration if provided, the board will exit the given power mode after this duration
228230
*/
229-
abstract fun setPowerMode(powerMode: PowerMode, duration: Duration, extra: Struct)
231+
abstract fun setPowerMode(powerMode: PowerMode, duration: JDuration, extra: Struct)
230232

231233
/**
232234
* Set the board to the indicated power mode.
233235
* @param powerMode the power mode to set
234236
* @param duration if provided, the board will exit the given power mode after this duration
235237
*/
236-
fun setPowerMode(powerMode: PowerMode, duration: Duration) {
238+
fun setPowerMode(powerMode: PowerMode, duration: JDuration) {
237239
return setPowerMode(powerMode, duration, Struct.getDefaultInstance())
238240
}
241+
242+
/**
243+
* Set the board to the indicated power mode.
244+
* @param powerMode the power mode to set
245+
* @param duration if provided, the board will exit the given power mode after this duration
246+
*/
247+
fun setPowerMode(powerMode: PowerMode, duration: Duration, extra: Struct = Struct.getDefaultInstance()) {
248+
return setPowerMode(powerMode, duration.toJavaDuration(), extra)
249+
}
239250
}

core/sdk/src/main/kotlin/com/viam/sdk/core/component/board/BoardRPCClient.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import com.viam.component.board.v1.BoardServiceGrpc.BoardServiceBlockingStub
1010
import com.viam.sdk.core.exception.MethodNotImplementedException
1111
import com.viam.sdk.core.rpc.Channel
1212
import com.viam.sdk.core.util.Durations
13+
import java.time.Duration
1314
import java.util.*
1415
import kotlin.jvm.optionals.getOrDefault
15-
import kotlin.time.Duration
16+
import kotlin.time.toKotlinDuration
1617

1718
/**
1819
* gRPC Client for a Board component
@@ -99,7 +100,7 @@ class BoardRPCClient(name: String, channel: Channel) : Board(name) {
99100
powerMode: PowerMode, duration: Duration, extra: Struct
100101
) {
101102
val request = SetPowerModeRequest.newBuilder().setName(this.name.name).setPowerMode(powerMode)
102-
.setDuration(Durations.fromNanos(duration.inWholeNanoseconds)).setExtra(extra).build()
103+
.setDuration(Durations.fromNanos(duration.toKotlinDuration().inWholeNanoseconds)).setExtra(extra).build()
103104
this.client.setPowerMode(request)
104105
}
105106

@@ -116,4 +117,5 @@ class BoardRPCClient(name: String, channel: Channel) : Board(name) {
116117
val response = this.client.getGeometries(request)
117118
return response.geometriesList
118119
}
120+
119121
}

core/sdk/src/test/kotlin/com/viam/sdk/core/component/board/BoardTest.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import java.util.*
1414
import kotlin.random.Random
1515
import kotlin.time.DurationUnit
1616
import kotlin.time.toDuration
17+
import kotlin.time.toJavaDuration
1718

1819
class BoardTest {
1920
private lateinit var board: Board
@@ -163,6 +164,6 @@ class BoardTest {
163164
val powerMode = PowerMode.POWER_MODE_OFFLINE_DEEP
164165
val powerModeDuration = Random.nextInt().toDuration(DurationUnit.NANOSECONDS)
165166
board.setPowerMode(powerMode, powerModeDuration)
166-
verify(board).setPowerMode(powerMode, powerModeDuration)
167+
verify(board).setPowerMode(powerMode, powerModeDuration.toJavaDuration(), Struct.getDefaultInstance())
167168
}
168169
}

0 commit comments

Comments
 (0)