Skip to content

Commit a32874c

Browse files
Mike ProsserMike Prosser
authored andcommitted
client.get_value() and .try_get_value()
1 parent dcaf070 commit a32874c

File tree

9 files changed

+199
-29
lines changed

9 files changed

+199
-29
lines changed

protos/ni/pythonpanel/v1/python_panel_service.proto

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,22 @@ service PythonPanelService {
3535
// Enumerate the panels available in the system, including information about the state of the panels and what values they have.
3636
// Status Codes for errors:
3737
rpc EnumeratePanels(EnumeratePanelsRequest) returns (EnumeratePanelsResponse);
38+
39+
// Get a value for a control on the panel
40+
// Status Codes for errors:
41+
// - INVALID_ARGUMENT:
42+
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
43+
// - The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
44+
// - NOT_FOUND:
45+
// - The value with the specified identifier was not found.
46+
rpc GetValue(GetValueRequest) returns (GetValueResponse);
3847

3948
// Try to get a value for a control on the panel
4049
// Status Codes for errors:
4150
// - INVALID_ARGUMENT:
4251
// - The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
4352
// - The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
44-
rpc TryGetValue(TryGetValueRequest) returns (TryGetValueResponse);
53+
rpc TryGetValue(GetValueRequest) returns (TryGetValueResponse);
4554

4655
// Set a value for a control on the panel
4756
// Status Codes for errors:
@@ -97,14 +106,19 @@ message EnumeratePanelsResponse {
97106
repeated PanelInformation panels = 1;
98107
}
99108

100-
message TryGetValueRequest {
109+
message GetValueRequest {
101110
// Unique ID of the panel
102111
string panel_id = 1;
103112

104113
// Unique ID of value
105114
string value_id = 2;
106115
}
107116

117+
message GetValueResponse {
118+
// The value
119+
google.protobuf.Any value = 1;
120+
}
121+
108122
message TryGetValueResponse {
109123
// The value, if it was found
110124
optional google.protobuf.Any value = 1;

src/ni/pythonpanel/v1/python_panel_service_pb2.py

Lines changed: 13 additions & 11 deletions
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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class EnumeratePanelsResponse(google.protobuf.message.Message):
138138
global___EnumeratePanelsResponse = EnumeratePanelsResponse
139139

140140
@typing.final
141-
class TryGetValueRequest(google.protobuf.message.Message):
141+
class GetValueRequest(google.protobuf.message.Message):
142142
DESCRIPTOR: google.protobuf.descriptor.Descriptor
143143

144144
PANEL_ID_FIELD_NUMBER: builtins.int
@@ -155,7 +155,26 @@ class TryGetValueRequest(google.protobuf.message.Message):
155155
) -> None: ...
156156
def ClearField(self, field_name: typing.Literal["panel_id", b"panel_id", "value_id", b"value_id"]) -> None: ...
157157

158-
global___TryGetValueRequest = TryGetValueRequest
158+
global___GetValueRequest = GetValueRequest
159+
160+
@typing.final
161+
class GetValueResponse(google.protobuf.message.Message):
162+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
163+
164+
VALUE_FIELD_NUMBER: builtins.int
165+
@property
166+
def value(self) -> google.protobuf.any_pb2.Any:
167+
"""The value"""
168+
169+
def __init__(
170+
self,
171+
*,
172+
value: google.protobuf.any_pb2.Any | None = ...,
173+
) -> None: ...
174+
def HasField(self, field_name: typing.Literal["value", b"value"]) -> builtins.bool: ...
175+
def ClearField(self, field_name: typing.Literal["value", b"value"]) -> None: ...
176+
177+
global___GetValueResponse = GetValueResponse
159178

160179
@typing.final
161180
class TryGetValueResponse(google.protobuf.message.Message):

src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ def __init__(self, channel):
3030
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.EnumeratePanelsRequest.SerializeToString,
3131
response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.EnumeratePanelsResponse.FromString,
3232
)
33+
self.GetValue = channel.unary_unary(
34+
'/ni.pythonpanel.v1.PythonPanelService/GetValue',
35+
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.SerializeToString,
36+
response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueResponse.FromString,
37+
)
3338
self.TryGetValue = channel.unary_unary(
3439
'/ni.pythonpanel.v1.PythonPanelService/TryGetValue',
35-
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.SerializeToString,
40+
request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.SerializeToString,
3641
response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.FromString,
3742
)
3843
self.SetValue = channel.unary_unary(
@@ -78,6 +83,19 @@ def EnumeratePanels(self, request, context):
7883
context.set_details('Method not implemented!')
7984
raise NotImplementedError('Method not implemented!')
8085

86+
def GetValue(self, request, context):
87+
"""Get a value for a control on the panel
88+
Status Codes for errors:
89+
- INVALID_ARGUMENT:
90+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
91+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
92+
- NOT_FOUND:
93+
- The value with the specified identifier was not found.
94+
"""
95+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
96+
context.set_details('Method not implemented!')
97+
raise NotImplementedError('Method not implemented!')
98+
8199
def TryGetValue(self, request, context):
82100
"""Try to get a value for a control on the panel
83101
Status Codes for errors:
@@ -118,9 +136,14 @@ def add_PythonPanelServiceServicer_to_server(servicer, server):
118136
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.EnumeratePanelsRequest.FromString,
119137
response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.EnumeratePanelsResponse.SerializeToString,
120138
),
139+
'GetValue': grpc.unary_unary_rpc_method_handler(
140+
servicer.GetValue,
141+
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.FromString,
142+
response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueResponse.SerializeToString,
143+
),
121144
'TryGetValue': grpc.unary_unary_rpc_method_handler(
122145
servicer.TryGetValue,
123-
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.FromString,
146+
request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.FromString,
124147
response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.SerializeToString,
125148
),
126149
'SetValue': grpc.unary_unary_rpc_method_handler(
@@ -190,6 +213,23 @@ def EnumeratePanels(request,
190213
options, channel_credentials,
191214
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
192215

216+
@staticmethod
217+
def GetValue(request,
218+
target,
219+
options=(),
220+
channel_credentials=None,
221+
call_credentials=None,
222+
insecure=False,
223+
compression=None,
224+
wait_for_ready=None,
225+
timeout=None,
226+
metadata=None):
227+
return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/GetValue',
228+
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.SerializeToString,
229+
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueResponse.FromString,
230+
options, channel_credentials,
231+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
232+
193233
@staticmethod
194234
def TryGetValue(request,
195235
target,
@@ -202,7 +242,7 @@ def TryGetValue(request,
202242
timeout=None,
203243
metadata=None):
204244
return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/TryGetValue',
205-
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueRequest.SerializeToString,
245+
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.GetValueRequest.SerializeToString,
206246
ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.TryGetValueResponse.FromString,
207247
options, channel_credentials,
208248
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,21 @@ class PythonPanelServiceStub:
5353
Status Codes for errors:
5454
"""
5555

56+
GetValue: grpc.UnaryUnaryMultiCallable[
57+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
58+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse,
59+
]
60+
"""Get a value for a control on the panel
61+
Status Codes for errors:
62+
- INVALID_ARGUMENT:
63+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
64+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
65+
- NOT_FOUND:
66+
- The value with the specified identifier was not found.
67+
"""
68+
5669
TryGetValue: grpc.UnaryUnaryMultiCallable[
57-
ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueRequest,
70+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
5871
ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueResponse,
5972
]
6073
"""Try to get a value for a control on the panel
@@ -110,8 +123,21 @@ class PythonPanelServiceAsyncStub:
110123
Status Codes for errors:
111124
"""
112125

126+
GetValue: grpc.aio.UnaryUnaryMultiCallable[
127+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
128+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse,
129+
]
130+
"""Get a value for a control on the panel
131+
Status Codes for errors:
132+
- INVALID_ARGUMENT:
133+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
134+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
135+
- NOT_FOUND:
136+
- The value with the specified identifier was not found.
137+
"""
138+
113139
TryGetValue: grpc.aio.UnaryUnaryMultiCallable[
114-
ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueRequest,
140+
ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
115141
ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueResponse,
116142
]
117143
"""Try to get a value for a control on the panel
@@ -173,10 +199,25 @@ class PythonPanelServiceServicer(metaclass=abc.ABCMeta):
173199
Status Codes for errors:
174200
"""
175201

202+
@abc.abstractmethod
203+
def GetValue(
204+
self,
205+
request: ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
206+
context: _ServicerContext,
207+
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse]]:
208+
"""Get a value for a control on the panel
209+
Status Codes for errors:
210+
- INVALID_ARGUMENT:
211+
- The panel identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
212+
- The value identifier contains invalid characters. Only alphanumeric characters and underscores are allowed.
213+
- NOT_FOUND:
214+
- The value with the specified identifier was not found.
215+
"""
216+
176217
@abc.abstractmethod
177218
def TryGetValue(
178219
self,
179-
request: ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueRequest,
220+
request: ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest,
180221
context: _ServicerContext,
181222
) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.TryGetValueResponse]]:
182223
"""Try to get a value for a control on the panel

src/nipanel/_panel_client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
StartPanelRequest,
1212
StopPanelRequest,
1313
EnumeratePanelsRequest,
14-
TryGetValueRequest,
14+
GetValueRequest,
1515
SetValueRequest,
1616
)
1717
from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub
@@ -116,6 +116,20 @@ def set_value(self, panel_id: str, value_id: str, value: object, notify: bool) -
116116
)
117117
self._invoke_with_retry(self._get_stub().SetValue, set_value_request)
118118

119+
def get_value(self, panel_id: str, value_id: str) -> object:
120+
"""Get the value for the control with value_id.
121+
122+
Args:
123+
panel_id: The ID of the panel.
124+
value_id: The ID of the control.
125+
126+
Returns:
127+
The value.
128+
"""
129+
try_get_value_request = GetValueRequest(panel_id=panel_id, value_id=value_id)
130+
response = self._invoke_with_retry(self._get_stub().GetValue, try_get_value_request)
131+
return from_any(response.value)
132+
119133
def try_get_value(self, panel_id: str, value_id: str) -> tuple[bool, object]:
120134
"""Try to get the value for the control with value_id.
121135
@@ -127,7 +141,7 @@ def try_get_value(self, panel_id: str, value_id: str) -> tuple[bool, object]:
127141
A tuple containing a boolean indicating whether the value was successfully retrieved and
128142
the value itself (or None if not present).
129143
"""
130-
try_get_value_request = TryGetValueRequest(panel_id=panel_id, value_id=value_id)
144+
try_get_value_request = GetValueRequest(panel_id=panel_id, value_id=value_id)
131145
response = self._invoke_with_retry(self._get_stub().TryGetValue, try_get_value_request)
132146
if response.HasField("value"):
133147
return True, from_any(response.value)

tests/unit/test_panel_client.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import grpc
2+
import pytest
23

34
from nipanel._panel_client import PanelClient
45

@@ -50,7 +51,14 @@ def test___start_panels___stop_panel_1_without_reset___enumerate_has_both_panels
5051
}
5152

5253

53-
def test___get_unset_value___returns_not_found(fake_panel_channel: grpc.Channel) -> None:
54+
def test___get_unset_value_raises_exception(fake_panel_channel: grpc.Channel) -> None:
55+
client = create_panel_client(fake_panel_channel)
56+
57+
with pytest.raises(Exception):
58+
client.get_value("panel1", "unset_id")
59+
60+
61+
def test___try_get_unset_value___returns_not_found(fake_panel_channel: grpc.Channel) -> None:
5462
client = create_panel_client(fake_panel_channel)
5563

5664
response = client.try_get_value("panel1", "unset_id")

0 commit comments

Comments
 (0)