Skip to content

Commit 7c8dc96

Browse files
Mike ProsserMike Prosser
authored andcommitted
uptake latest proto file with optional value in GetValueResponse
1 parent 0395bba commit 7c8dc96

File tree

7 files changed

+12
-21
lines changed

7 files changed

+12
-21
lines changed

protos/ni/pythonpanel/v1/python_panel_service.proto

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ message GetValueRequest {
9898

9999
message GetValueResponse {
100100
// The value
101-
google.protobuf.Any value = 1;
102-
103-
// Was the value found?
104-
bool found = 2;
101+
optional google.protobuf.Any value = 1;
105102
}
106103

107104
message SetValueRequest {

src/ni/pythonpanel/v1/python_panel_service_pb2.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ni/pythonpanel/v1/python_panel_service_pb2.pyi

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,6 @@ class GetValueResponse(google.protobuf.message.Message):
162162
DESCRIPTOR: google.protobuf.descriptor.Descriptor
163163

164164
VALUE_FIELD_NUMBER: builtins.int
165-
FOUND_FIELD_NUMBER: builtins.int
166-
found: builtins.bool
167-
"""Was the value found?"""
168165
@property
169166
def value(self) -> google.protobuf.any_pb2.Any:
170167
"""The value"""
@@ -173,10 +170,10 @@ class GetValueResponse(google.protobuf.message.Message):
173170
self,
174171
*,
175172
value: google.protobuf.any_pb2.Any | None = ...,
176-
found: builtins.bool = ...,
177173
) -> None: ...
178-
def HasField(self, field_name: typing.Literal["value", b"value"]) -> builtins.bool: ...
179-
def ClearField(self, field_name: typing.Literal["found", b"found", "value", b"value"]) -> None: ...
174+
def HasField(self, field_name: typing.Literal["_value", b"_value", "value", b"value"]) -> builtins.bool: ...
175+
def ClearField(self, field_name: typing.Literal["_value", b"_value", "value", b"value"]) -> None: ...
176+
def WhichOneof(self, oneof_group: typing.Literal["_value", b"_value"]) -> typing.Literal["value"] | None: ...
180177

181178
global___GetValueResponse = GetValueResponse
182179

src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ def GetValue(self, request, context):
7777
"""Get a value for a control on the panel
7878
Status Codes for errors:
7979
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
80-
- NOT_FOUND: The value with the specified identifier was not found
8180
"""
8281
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
8382
context.set_details('Method not implemented!')

src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class PythonPanelServiceStub:
5555
"""Get a value for a control on the panel
5656
Status Codes for errors:
5757
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
58-
- NOT_FOUND: The value with the specified identifier was not found
5958
"""
6059

6160
SetValue: grpc.UnaryUnaryMultiCallable[
@@ -104,7 +103,6 @@ class PythonPanelServiceAsyncStub:
104103
"""Get a value for a control on the panel
105104
Status Codes for errors:
106105
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
107-
- NOT_FOUND: The value with the specified identifier was not found
108106
"""
109107

110108
SetValue: grpc.aio.UnaryUnaryMultiCallable[
@@ -161,7 +159,6 @@ class PythonPanelServiceServicer(metaclass=abc.ABCMeta):
161159
"""Get a value for a control on the panel
162160
Status Codes for errors:
163161
- INVALID_ARGUMENT: The specified identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
164-
- NOT_FOUND: The value with the specified identifier was not found
165162
"""
166163

167164
@abc.abstractmethod

src/nipanel/_panel_client.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,15 @@ def get_value(self, panel_id: str, value_id: str) -> tuple[bool, object]:
124124
value_id: The ID of the control.
125125
126126
Returns:
127-
The value, and a boolean indicating if the value was found.
127+
A tuple containing a boolean indicating whether the value was successfully retrieved and
128+
the value itself (or None if not present).
128129
"""
129130
get_value_request = GetValueRequest(panel_id=panel_id, value_id=value_id)
130131
response = self._invoke_with_retry(self._get_stub().GetValue, get_value_request)
131-
if not response.found:
132+
if response.HasField("value"):
133+
return True, from_any(response.value)
134+
else:
132135
return False, None
133-
the_value = from_any(response.value)
134-
return True, the_value
135136

136137
def _get_stub(self) -> PythonPanelServiceStub:
137138
if self._stub is None:

tests/utils/_fake_python_panel_servicer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ def EnumeratePanels( # noqa: N802
6363
def GetValue(self, request: GetValueRequest, context: Any) -> GetValueResponse: # noqa: N802
6464
"""Trivial implementation for testing."""
6565
if request.value_id not in self._panel_value_ids.get(request.panel_id, {}):
66-
return GetValueResponse(found=False)
66+
return GetValueResponse()
6767
value = self._panel_value_ids[request.panel_id][request.value_id]
68-
return GetValueResponse(found=True, value=value)
68+
return GetValueResponse(value=value)
6969

7070
def SetValue(self, request: SetValueRequest, context: Any) -> SetValueResponse: # noqa: N802
7171
"""Trivial implementation for testing."""

0 commit comments

Comments
 (0)