Skip to content

Commit 2a221b4

Browse files
authored
RSDK-6664 Get metadata client (#545)
1 parent e6b63ec commit 2a221b4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/viam/robot/client.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
FrameSystemConfig,
2424
FrameSystemConfigRequest,
2525
FrameSystemConfigResponse,
26+
GetCloudMetadataRequest,
27+
GetCloudMetadataResponse,
2628
GetOperationsRequest,
2729
GetOperationsResponse,
2830
GetStatusRequest,
@@ -623,3 +625,15 @@ async def stop_all(self, extra: Dict[ResourceName, Dict[str, Any]] = {}):
623625
ep.append(StopExtraParameters(name=name, params=dict_to_struct(params)))
624626
request = StopAllRequest(extra=ep)
625627
await self._client.StopAll(request)
628+
629+
######################
630+
# Get Cloud Metadata #
631+
######################
632+
633+
async def get_cloud_metadata(self) -> GetCloudMetadataResponse:
634+
"""
635+
Returns app-related information about the robot.
636+
"""
637+
638+
request = GetCloudMetadataRequest()
639+
return await self._client.GetCloudMetadata(request)

src/viam/services/motion/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, Final, List, Mapping, Optional, Sequence, Iterable
1+
from typing import Any, Final, Iterable, List, Mapping, Optional, Sequence
22

33
from grpclib.client import Channel
44

tests/test_robot.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
FrameSystemConfig,
3030
FrameSystemConfigRequest,
3131
FrameSystemConfigResponse,
32+
GetCloudMetadataRequest,
33+
GetCloudMetadataResponse,
3234
GetOperationsRequest,
3335
GetOperationsResponse,
3436
GetStatusRequest,
@@ -140,6 +142,12 @@
140142

141143
OPERATIONS_RESPONSE = [Operation(id=OPERATION_ID)]
142144

145+
GET_CLOUD_METADATA_RESPONSE = GetCloudMetadataResponse(
146+
robot_part_id="the-robot-part",
147+
primary_org_id="the-primary-org",
148+
location_id="the-location",
149+
)
150+
143151

144152
@pytest.fixture(scope="function")
145153
def service() -> RobotService:
@@ -194,12 +202,18 @@ async def GetOperations(stream: Stream[GetOperationsRequest, GetOperationsRespon
194202
response = GetOperationsResponse(operations=OPERATIONS_RESPONSE)
195203
await stream.send_message(response)
196204

205+
async def GetCloudMetadata(stream: Stream[GetCloudMetadataRequest, GetCloudMetadataResponse]) -> None:
206+
request = await stream.recv_message()
207+
assert request is not None
208+
await stream.send_message(GET_CLOUD_METADATA_RESPONSE)
209+
197210
manager = ResourceManager(resources)
198211
service = RobotService(manager)
199212
service.FrameSystemConfig = Config
200213
service.TransformPose = TransformPose
201214
service.DiscoverComponents = DiscoverComponents
202215
service.GetOperations = GetOperations
216+
service.GetCloudMetadata = GetCloudMetadata
203217

204218
return service
205219

@@ -407,6 +421,14 @@ async def test_discover_components(self, service: RobotService):
407421
assert discoveries == DISCOVERY_RESPONSE
408422
await client.close()
409423

424+
@pytest.mark.asyncio
425+
async def test_get_cloud_metadata(self, service: RobotService):
426+
async with ChannelFor([service]) as channel:
427+
client = await RobotClient.with_channel(channel, RobotClient.Options())
428+
md = await client.get_cloud_metadata()
429+
assert md == GET_CLOUD_METADATA_RESPONSE
430+
await client.close()
431+
410432
@pytest.mark.asyncio
411433
async def test_get_operations(self, service: RobotService):
412434
async with ChannelFor([service]) as channel:

0 commit comments

Comments
 (0)