Skip to content

Commit 080adda

Browse files
updates
1 parent 258eaec commit 080adda

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

src/viam/components/board/board.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ async def gpio_pin_by_name(self, name: str) -> GPIOPin:
366366

367367
@abc.abstractmethod
368368
async def set_power_mode(
369-
self, mode: PowerMode.ValueType, duration: Optional[timedelta] = None, *, timeout: Optional[float] = None, **kwargs
369+
self, mode: PowerMode.ValueType, duration: Optional[timedelta] = None, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
370370
):
371371
"""
372372
Set the board to the indicated power mode.

src/viam/components/board/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,15 @@ async def set_power_mode(
201201
mode: PowerMode.ValueType,
202202
duration: Optional[timedelta] = None,
203203
*,
204+
extra: Optional[Dict[str, Any]] = None,
204205
timeout: Optional[float] = None,
205206
**kwargs,
206207
):
207208
md = kwargs.get("metadata", self.Metadata()).proto
208209
duration_pb: Optional[Duration] = None
209210
if duration is not None:
210211
duration_pb = [(d, d.FromTimedelta(duration)) for d in [Duration()]][0][0]
211-
request = SetPowerModeRequest(name=self.name, power_mode=mode, duration=duration_pb)
212+
request = SetPowerModeRequest(name=self.name, power_mode=mode, duration=duration_pb, extra=dict_to_struct(extra))
212213
await self.client.SetPowerMode(request, timeout=timeout, metadata=md)
213214

214215
async def get_geometries(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs) -> List[Geometry]:

src/viam/components/board/service.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ async def SetPowerMode(self, stream: Stream[SetPowerModeRequest, SetPowerModeRes
164164
await board.set_power_mode(
165165
mode=request.power_mode,
166166
duration=request.duration.ToTimedelta(),
167+
extra=struct_to_dict(request.extra),
167168
timeout=timeout,
168169
metadata=stream.metadata,
169170
)

tests/mocks/components.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,9 @@ async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Option
436436
return {"command": command}
437437

438438
async def set_power_mode(
439-
self, mode: PowerMode.ValueType, duration: Optional[timedelta] = None, *, timeout: Optional[float] = None, **kwargs
439+
self, mode: PowerMode.ValueType, duration: Optional[timedelta] = None, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None, **kwargs
440440
):
441+
self.extra = extra
441442
self.timeout = timeout
442443
self.power_mode = mode
443444
self.power_mode_duration = duration

tests/test_board.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,14 @@ async def test_set_power_mode(self, board: MockBoard, service: BoardRPCService):
275275
pm_mode = PowerMode.POWER_MODE_OFFLINE_DEEP
276276
pm_duration = Duration()
277277
pm_duration.FromTimedelta(timedelta(minutes=1))
278-
request = SetPowerModeRequest(name=board.name, power_mode=pm_mode, duration=pm_duration)
278+
extra = {"foo": "bar", "baz": [1, 2, 3]}
279+
request = SetPowerModeRequest(name=board.name, power_mode=pm_mode, duration=pm_duration, extra=dict_to_struct(extra))
279280
response: SetPowerModeResponse = await client.SetPowerMode(request, timeout=6.66)
280281
assert response == SetPowerModeResponse()
281282
assert board.timeout == loose_approx(6.66)
282283
assert board.power_mode == PowerMode.POWER_MODE_OFFLINE_DEEP
283284
assert board.power_mode_duration == pm_duration.ToTimedelta()
285+
assert board.extra == extra
284286

285287
async def test_write_analog(self, board: MockBoard, service: BoardRPCService):
286288
async with ChannelFor([service]) as channel:

0 commit comments

Comments
 (0)