Skip to content

Commit 6984e42

Browse files
authored
Add MachineStatus to Robot API (#704)
1 parent 8355e84 commit 6984e42

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/viam/robot/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
GetCloudMetadataResponse,
2828
GetOperationsRequest,
2929
GetOperationsResponse,
30+
GetMachineStatusRequest,
31+
GetMachineStatusResponse,
3032
GetStatusRequest,
3133
GetStatusResponse,
3234
GetVersionRequest,
@@ -894,3 +896,25 @@ async def get_version(self) -> GetVersionResponse:
894896

895897
request = GetVersionRequest()
896898
return await self._client.GetVersion(request)
899+
900+
######################
901+
# Get Machine Status #
902+
######################
903+
904+
async def get_machine_status(self) -> GetMachineStatusResponse:
905+
"""
906+
Get status information about the robot.
907+
908+
::
909+
910+
machine_status = await machine.get_machine_status()
911+
resource_statuses = machine_status.resources
912+
913+
Returns:
914+
viam.proto.robot.GetMachineStatusResponse: current status of the resources (List[ResourceStatus]) of the robot.
915+
916+
For more information, see `Machine Management API <https://docs.viam.com/appendix/apis/robot/>`_.
917+
"""
918+
919+
request = GetMachineStatusRequest()
920+
return await self._client.GetMachineStatus(request)

tests/test_robot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
GetOperationsResponse,
3737
GetStatusRequest,
3838
GetStatusResponse,
39+
GetMachineStatusRequest,
40+
GetMachineStatusResponse,
41+
ResourceStatus,
3942
GetVersionRequest,
4043
GetVersionResponse,
4144
Operation,
@@ -161,6 +164,15 @@
161164
api_version="0.3.0",
162165
)
163166

167+
GET_MACHINE_STATUS_RESPONSE = GetMachineStatusResponse(
168+
resources=[
169+
ResourceStatus(
170+
name=ResourceName(namespace=RESOURCE_NAMESPACE_RDK, type=RESOURCE_TYPE_COMPONENT, subtype="arm", name="arm1"),
171+
state=ResourceStatus.State.STATE_READY,
172+
)
173+
]
174+
)
175+
164176

165177
@pytest.fixture(scope="function")
166178
def service() -> RobotService:
@@ -225,6 +237,11 @@ async def GetVersion(stream: Stream[GetVersionRequest, GetVersionResponse]) -> N
225237
assert request is not None
226238
await stream.send_message(GET_VERVSION_RESPONSE)
227239

240+
async def GetMachineStatus(stream: Stream[GetMachineStatusRequest, GetMachineStatusResponse]) -> None:
241+
request = await stream.recv_message()
242+
assert request is not None
243+
await stream.send_message(GET_MACHINE_STATUS_RESPONSE)
244+
228245
async def Shutdown(stream: Stream[ShutdownRequest, ShutdownResponse]) -> None:
229246
request = await stream.recv_message()
230247
assert request is not None
@@ -240,6 +257,7 @@ async def Shutdown(stream: Stream[ShutdownRequest, ShutdownResponse]) -> None:
240257
service.GetCloudMetadata = GetCloudMetadata
241258
service.Shutdown = Shutdown
242259
service.GetVersion = GetVersion
260+
service.GetMachineStatus = GetMachineStatus
243261

244262
return service
245263

@@ -462,6 +480,14 @@ async def test_get_version(self, service: RobotService):
462480
assert md == GET_VERVSION_RESPONSE
463481
await client.close()
464482

483+
@pytest.mark.asyncio
484+
async def test_get_machine_status(self, service: RobotService):
485+
async with ChannelFor([service]) as channel:
486+
client = await RobotClient.with_channel(channel, RobotClient.Options())
487+
statuses = await client.get_machine_status()
488+
assert statuses == GET_MACHINE_STATUS_RESPONSE
489+
await client.close()
490+
465491
@pytest.mark.asyncio
466492
async def test_get_operations(self, service: RobotService):
467493
async with ChannelFor([service]) as channel:

0 commit comments

Comments
 (0)