Skip to content

Commit

Permalink
Update Protos + Make Methods unimplemented (#450)
Browse files Browse the repository at this point in the history
Co-authored-by: cheukt <[email protected]>
  • Loading branch information
cheukt and cheukt authored Oct 2, 2023
1 parent eaec616 commit 4e1bdef
Show file tree
Hide file tree
Showing 33 changed files with 1,965 additions and 529 deletions.
303 changes: 168 additions & 135 deletions docs/examples/_server.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,152 @@
import asyncio
from datetime import datetime

from grpclib.utils import graceful_exit
from grpclib.server import Server, Stream
from google.protobuf.struct_pb2 import Struct, Value
from google.protobuf.timestamp_pb2 import Timestamp
from grpclib.server import Server, Stream
from grpclib.utils import graceful_exit

from viam.app.data_client import DataClient
from viam.utils import datetime_to_timestamp, dict_to_struct, value_to_primitive
from viam.proto.app import (
AddRoleRequest,
AddRoleResponse,
AppServiceBase,
ChangeRoleRequest,
ChangeRoleResponse,
CheckPermissionsRequest,
CheckPermissionsResponse,
CreateFragmentRequest,
CreateFragmentResponse,
CreateKeyFromExistingKeyAuthorizationsRequest,
CreateKeyFromExistingKeyAuthorizationsResponse,
CreateKeyRequest,
CreateKeyResponse,
CreateLocationRequest,
CreateLocationResponse,
CreateLocationSecretRequest,
CreateLocationSecretResponse,
CreateModuleRequest,
CreateModuleResponse,
CreateOrganizationInviteRequest,
CreateOrganizationInviteResponse,
CreateOrganizationRequest,
CreateOrganizationResponse,
CreateRobotPartSecretRequest,
CreateRobotPartSecretResponse,
DeleteFragmentRequest,
DeleteFragmentResponse,
DeleteKeyRequest,
DeleteKeyResponse,
DeleteLocationRequest,
DeleteLocationResponse,
DeleteLocationSecretRequest,
DeleteLocationSecretResponse,
DeleteOrganizationInviteRequest,
DeleteOrganizationInviteResponse,
DeleteOrganizationMemberRequest,
DeleteOrganizationMemberResponse,
DeleteOrganizationRequest,
DeleteOrganizationResponse,
DeleteRobotPartRequest,
DeleteRobotPartResponse,
DeleteRobotPartSecretRequest,
DeleteRobotPartSecretResponse,
DeleteRobotRequest,
DeleteRobotResponse,
GetFragmentRequest,
GetFragmentResponse,
GetLocationRequest,
GetLocationResponse,
GetModuleRequest,
GetModuleResponse,
GetOrganizationNamespaceAvailabilityRequest,
GetOrganizationNamespaceAvailabilityResponse,
GetOrganizationRequest,
GetOrganizationResponse,
GetRobotAPIKeysRequest,
GetRobotAPIKeysResponse,
GetRobotPartHistoryRequest,
GetRobotPartHistoryResponse,
GetRobotPartLogsRequest,
GetRobotPartLogsResponse,
GetRobotPartRequest,
GetRobotPartResponse,
GetRobotPartsRequest,
GetRobotPartsResponse,
GetRobotRequest,
GetRobotResponse,
GetRoverRentalRobotsRequest,
GetRoverRentalRobotsResponse,
GetUserIDByEmailRequest,
GetUserIDByEmailResponse,
ListAuthorizationsRequest,
ListAuthorizationsResponse,
ListFragmentsRequest,
ListFragmentsResponse,
ListKeysRequest,
ListKeysResponse,
ListLocationsRequest,
ListLocationsResponse,
ListModulesRequest,
ListModulesResponse,
ListOrganizationMembersRequest,
ListOrganizationMembersResponse,
ListOrganizationsByUserRequest,
ListOrganizationsByUserResponse,
ListOrganizationsRequest,
ListOrganizationsResponse,
ListRobotsRequest,
ListRobotsResponse,
Location,
LocationAuthRequest,
LocationAuthResponse,
)
from viam.proto.app import LogEntry as LogEntryPB
from viam.proto.app import (
MarkPartAsMainRequest,
MarkPartAsMainResponse,
MarkPartForRestartRequest,
MarkPartForRestartResponse,
NewRobotPartRequest,
NewRobotPartResponse,
NewRobotRequest,
NewRobotResponse,
Organization,
RemoveRoleRequest,
RemoveRoleResponse,
ResendOrganizationInviteRequest,
ResendOrganizationInviteResponse,
Robot,
RotateKeyRequest,
RotateKeyResponse,
ShareLocationRequest,
ShareLocationResponse,
TailRobotPartLogsRequest,
TailRobotPartLogsResponse,
UnshareLocationRequest,
UnshareLocationResponse,
UpdateFragmentRequest,
UpdateFragmentResponse,
UpdateLocationRequest,
UpdateLocationResponse,
UpdateModuleRequest,
UpdateModuleResponse,
UpdateOrganizationInviteAuthorizationsRequest,
UpdateOrganizationInviteAuthorizationsResponse,
UpdateOrganizationRequest,
UpdateOrganizationResponse,
UpdateRobotPartRequest,
UpdateRobotPartResponse,
UpdateRobotRequest,
UpdateRobotResponse,
UploadModuleFileRequest,
UploadModuleFileResponse,
)
from viam.proto.app.data import (
AddBoundingBoxToImageByIDResponse,
AddBinaryDataToDatasetByIDsRequest,
AddBinaryDataToDatasetByIDsResponse,
AddBoundingBoxToImageByIDRequest,
AddBoundingBoxToImageByIDResponse,
AddTagsToBinaryDataByFilterRequest,
AddTagsToBinaryDataByFilterResponse,
AddTagsToBinaryDataByIDsRequest,
Expand All @@ -31,12 +167,12 @@
DeleteBinaryDataByIDsResponse,
DeleteTabularDataRequest,
DeleteTabularDataResponse,
DeleteTabularDataByFilterRequest,
DeleteTabularDataByFilterResponse,
GetDatabaseConnectionRequest,
GetDatabaseConnectionResponse,
RemoveBoundingBoxFromImageByIDResponse,
RemoveBinaryDataFromDatasetByIDsRequest,
RemoveBinaryDataFromDatasetByIDsResponse,
RemoveBoundingBoxFromImageByIDRequest,
RemoveBoundingBoxFromImageByIDResponse,
RemoveTagsFromBinaryDataByFilterRequest,
RemoveTagsFromBinaryDataByFilterResponse,
RemoveTagsFromBinaryDataByIDsRequest,
Expand All @@ -56,131 +192,7 @@
StreamingDataCaptureUploadRequest,
StreamingDataCaptureUploadResponse,
)
from viam.proto.app import (
AppServiceBase,
GetUserIDByEmailRequest,
GetUserIDByEmailResponse,
CreateKeyRequest,
CreateKeyResponse,
CreateOrganizationRequest,
CreateOrganizationResponse,
ListOrganizationsRequest,
ListOrganizationsResponse,
ListOrganizationsByUserRequest,
ListOrganizationsByUserResponse,
GetOrganizationRequest,
GetOrganizationResponse,
GetOrganizationNamespaceAvailabilityRequest,
GetOrganizationNamespaceAvailabilityResponse,
GetRobotAPIKeysRequest,
GetRobotAPIKeysResponse,
UpdateOrganizationRequest,
UpdateOrganizationResponse,
DeleteOrganizationRequest,
DeleteOrganizationResponse,
ListOrganizationMembersRequest,
ListOrganizationMembersResponse,
CreateOrganizationInviteRequest,
CreateOrganizationInviteResponse,
UpdateOrganizationInviteAuthorizationsRequest,
UpdateOrganizationInviteAuthorizationsResponse,
DeleteOrganizationMemberRequest,
DeleteOrganizationMemberResponse,
DeleteOrganizationInviteRequest,
DeleteOrganizationInviteResponse,
ResendOrganizationInviteRequest,
ResendOrganizationInviteResponse,
CreateLocationRequest,
CreateLocationResponse,
GetLocationRequest,
GetLocationResponse,
UpdateLocationRequest,
UpdateLocationResponse,
Organization,
Location,
LogEntry as LogEntryPB,
Robot,
DeleteLocationRequest,
DeleteLocationResponse,
ListLocationsRequest,
ListLocationsResponse,
ShareLocationRequest,
ShareLocationResponse,
UnshareLocationRequest,
UnshareLocationResponse,
LocationAuthRequest,
LocationAuthResponse,
CreateLocationSecretRequest,
CreateLocationSecretResponse,
DeleteLocationSecretRequest,
DeleteLocationSecretResponse,
GetRobotRequest,
GetRobotResponse,
GetRoverRentalRobotsRequest,
GetRoverRentalRobotsResponse,
GetRobotPartsRequest,
GetRobotPartsResponse,
GetRobotPartRequest,
GetRobotPartResponse,
GetRobotPartLogsRequest,
GetRobotPartLogsResponse,
TailRobotPartLogsRequest,
TailRobotPartLogsResponse,
GetRobotPartHistoryRequest,
GetRobotPartHistoryResponse,
UpdateRobotPartRequest,
UpdateRobotPartResponse,
NewRobotPartRequest,
NewRobotPartResponse,
DeleteRobotPartRequest,
DeleteRobotPartResponse,
MarkPartAsMainRequest,
MarkPartAsMainResponse,
MarkPartForRestartRequest,
MarkPartForRestartResponse,
CreateRobotPartSecretRequest,
CreateRobotPartSecretResponse,
DeleteRobotPartSecretRequest,
DeleteRobotPartSecretResponse,
ListRobotsRequest,
ListRobotsResponse,
NewRobotRequest,
NewRobotResponse,
UpdateRobotRequest,
UpdateRobotResponse,
DeleteRobotRequest,
DeleteRobotResponse,
ListFragmentsRequest,
ListFragmentsResponse,
GetFragmentRequest,
GetFragmentResponse,
CreateFragmentRequest,
CreateFragmentResponse,
UpdateFragmentRequest,
UpdateFragmentResponse,
DeleteFragmentRequest,
DeleteFragmentResponse,
AddRoleRequest,
AddRoleResponse,
RemoveRoleRequest,
RemoveRoleResponse,
ChangeRoleRequest,
ChangeRoleResponse,
ListAuthorizationsRequest,
ListAuthorizationsResponse,
CheckPermissionsRequest,
CheckPermissionsResponse,
CreateModuleRequest,
CreateModuleResponse,
UpdateModuleRequest,
UpdateModuleResponse,
UploadModuleFileRequest,
UploadModuleFileResponse,
GetModuleRequest,
GetModuleResponse,
ListModulesRequest,
ListModulesResponse,
)
from viam.utils import datetime_to_timestamp, dict_to_struct, value_to_primitive


class MockData(DataServiceBase):
Expand Down Expand Up @@ -234,9 +246,6 @@ async def BinaryDataByFilter(self, stream: Stream[BinaryDataByFilterRequest, Bin
async def BinaryDataByIDs(self, stream: Stream[BinaryDataByIDsRequest, BinaryDataByIDsResponse]) -> None:
pass

async def DeleteTabularDataByFilter(self, stream: Stream[DeleteTabularDataByFilterRequest, DeleteTabularDataByFilterResponse]) -> None:
pass

async def DeleteTabularData(self, stream: Stream[DeleteTabularDataRequest, DeleteTabularDataResponse]) -> None:
pass

Expand Down Expand Up @@ -284,6 +293,16 @@ async def GetDatabaseConnection(self, stream: Stream[GetDatabaseConnectionReques
async def ConfigureDatabaseUser(self, stream: Stream[ConfigureDatabaseUserRequest, ConfigureDatabaseUserResponse]) -> None:
pass

async def AddBinaryDataToDatasetByIDs(
self, stream: Stream[AddBinaryDataToDatasetByIDsRequest, AddBinaryDataToDatasetByIDsResponse]
) -> None:
pass

async def RemoveBinaryDataFromDatasetByIDs(
self, stream: Stream[RemoveBinaryDataFromDatasetByIDsRequest, RemoveBinaryDataFromDatasetByIDsResponse]
) -> None:
pass


class MockDataSync(DataSyncServiceBase):
async def DataCaptureUpload(self, stream: Stream[DataCaptureUploadRequest, DataCaptureUploadResponse]) -> None:
Expand Down Expand Up @@ -521,6 +540,20 @@ async def CreateKey(self, stream: Stream[CreateKeyRequest, CreateKeyResponse]) -
async def GetRobotAPIKeys(self, stream: Stream[GetRobotAPIKeysRequest, GetRobotAPIKeysResponse]) -> None:
pass

async def DeleteKey(self, stream: Stream[DeleteKeyRequest, DeleteKeyResponse]) -> None:
pass

async def ListKeys(self, stream: Stream[ListKeysRequest, ListKeysResponse]) -> None:
pass

async def RotateKey(self, stream: Stream[RotateKeyRequest, RotateKeyResponse]) -> None:
pass

async def CreateKeyFromExistingKeyAuthorizations(
self, stream: Stream[CreateKeyFromExistingKeyAuthorizationsRequest, CreateKeyFromExistingKeyAuthorizationsResponse]
) -> None:
pass


async def main(*, host: str = "127.0.0.1", port: int = 9092) -> None:
server = Server([MockData(), MockDataSync(), MockApp()])
Expand Down
7 changes: 6 additions & 1 deletion src/viam/components/board/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from grpclib.server import Stream

from viam.errors import ResourceNotFoundError
from viam.errors import ResourceNotFoundError, MethodNotImplementedError
from viam.proto.common import DoCommandRequest, DoCommandResponse, GetGeometriesRequest, GetGeometriesResponse
from viam.proto.component.board import (
BoardServiceBase,
Expand All @@ -24,6 +24,8 @@
SetPWMResponse,
StatusRequest,
StatusResponse,
WriteAnalogRequest,
WriteAnalogResponse,
)
from viam.resource.rpc_service_base import ResourceRPCServiceBase
from viam.utils import dict_to_struct, struct_to_dict
Expand Down Expand Up @@ -175,6 +177,9 @@ async def SetPowerMode(self, stream: Stream[SetPowerModeRequest, SetPowerModeRes
response = SetPowerModeResponse()
await stream.send_message(response)

async def WriteAnalog(self, stream: Stream[WriteAnalogRequest, WriteAnalogResponse]) -> None:
raise MethodNotImplementedError("WriteAnalog")

async def DoCommand(self, stream: Stream[DoCommandRequest, DoCommandResponse]) -> None:
request = await stream.recv_message()
assert request is not None
Expand Down
Loading

0 comments on commit 4e1bdef

Please sign in to comment.