diff --git a/protos/ni/pythonpanel/v1/python_panel_service.proto b/protos/ni/pythonpanel/v1/python_panel_service.proto index ba1b02d..0dd6073 100644 --- a/protos/ni/pythonpanel/v1/python_panel_service.proto +++ b/protos/ni/pythonpanel/v1/python_panel_service.proto @@ -14,17 +14,12 @@ option objc_class_prefix = "NIPP"; option php_namespace = "NI\\PythonPanel\\V1"; option ruby_package = "NI::PythonPanel::V1"; -// Service interface for connecting to python panels +// Service interface for interacting with python panels service PythonPanelService { - // Connect to a panel and open it + // Open a panel // Status Codes for errors: // - NOT_FOUND: the file for the panel was not found - rpc Connect(ConnectRequest) returns (ConnectResponse); - - // Disconnect from a panel (does not close the panel) - // Status Codes for errors: - // - NOT_FOUND: the panel with the specified id was not found - rpc Disconnect(DisconnectRequest) returns (DisconnectResponse); + rpc OpenPanel(OpenPanelRequest) returns (OpenPanelResponse); // Get a value for a control on the panel // Status Codes for errors: @@ -37,7 +32,7 @@ service PythonPanelService { rpc SetValue(SetValueRequest) returns (SetValueResponse); } -message ConnectRequest { +message OpenPanelRequest { // Unique ID of the panel string panel_id = 1; @@ -45,15 +40,7 @@ message ConnectRequest { string panel_uri = 2; } -message ConnectResponse { -} - -message DisconnectRequest { - // Unique ID of the panel - string panel_id = 1; -} - -message DisconnectResponse { +message OpenPanelResponse { } message GetValueRequest { diff --git a/src/ni/pythonpanel/v1/python_panel_service_pb2.py b/src/ni/pythonpanel/v1/python_panel_service_pb2.py index 173c5a6..f2c1e9c 100644 --- a/src/ni/pythonpanel/v1/python_panel_service_pb2.py +++ b/src/ni/pythonpanel/v1/python_panel_service_pb2.py @@ -14,7 +14,7 @@ from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,ni/pythonpanel/v1/python_panel_service.proto\x12\x11ni.pythonpanel.v1\x1a\x19google/protobuf/any.proto\"5\n\x0e\x43onnectRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x11\n\tpanel_uri\x18\x02 \x01(\t\"\x11\n\x0f\x43onnectResponse\"%\n\x11\x44isconnectRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\"\x14\n\x12\x44isconnectResponse\"5\n\x0fGetValueRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x10\n\x08value_id\x18\x02 \x01(\t\"7\n\x10GetValueResponse\x12#\n\x05value\x18\x01 \x01(\x0b\x32\x14.google.protobuf.Any\"Z\n\x0fSetValueRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x10\n\x08value_id\x18\x02 \x01(\t\x12#\n\x05value\x18\x03 \x01(\x0b\x32\x14.google.protobuf.Any\"\x12\n\x10SetValueResponse2\xeb\x02\n\x12PythonPanelService\x12P\n\x07\x43onnect\x12!.ni.pythonpanel.v1.ConnectRequest\x1a\".ni.pythonpanel.v1.ConnectResponse\x12Y\n\nDisconnect\x12$.ni.pythonpanel.v1.DisconnectRequest\x1a%.ni.pythonpanel.v1.DisconnectResponse\x12S\n\x08GetValue\x12\".ni.pythonpanel.v1.GetValueRequest\x1a#.ni.pythonpanel.v1.GetValueResponse\x12S\n\x08SetValue\x12\".ni.pythonpanel.v1.SetValueRequest\x1a#.ni.pythonpanel.v1.SetValueResponseB\x9a\x01\n\x15\x63om.ni.pythonpanel.v1B\x17PythonPanelServiceProtoP\x01Z\rpythonpanelv1\xf8\x01\x01\xa2\x02\x04NIPP\xaa\x02\"NationalInstruments.PythonPanel.V1\xca\x02\x11NI\\PythonPanel\\V1\xea\x02\x13NI::PythonPanel::V1b\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n,ni/pythonpanel/v1/python_panel_service.proto\x12\x11ni.pythonpanel.v1\x1a\x19google/protobuf/any.proto\"7\n\x10OpenPanelRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x11\n\tpanel_uri\x18\x02 \x01(\t\"\x13\n\x11OpenPanelResponse\"5\n\x0fGetValueRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x10\n\x08value_id\x18\x02 \x01(\t\"7\n\x10GetValueResponse\x12#\n\x05value\x18\x01 \x01(\x0b\x32\x14.google.protobuf.Any\"Z\n\x0fSetValueRequest\x12\x10\n\x08panel_id\x18\x01 \x01(\t\x12\x10\n\x08value_id\x18\x02 \x01(\t\x12#\n\x05value\x18\x03 \x01(\x0b\x32\x14.google.protobuf.Any\"\x12\n\x10SetValueResponse2\x96\x02\n\x12PythonPanelService\x12V\n\tOpenPanel\x12#.ni.pythonpanel.v1.OpenPanelRequest\x1a$.ni.pythonpanel.v1.OpenPanelResponse\x12S\n\x08GetValue\x12\".ni.pythonpanel.v1.GetValueRequest\x1a#.ni.pythonpanel.v1.GetValueResponse\x12S\n\x08SetValue\x12\".ni.pythonpanel.v1.SetValueRequest\x1a#.ni.pythonpanel.v1.SetValueResponseB\x9a\x01\n\x15\x63om.ni.pythonpanel.v1B\x17PythonPanelServiceProtoP\x01Z\rpythonpanelv1\xf8\x01\x01\xa2\x02\x04NIPP\xaa\x02\"NationalInstruments.PythonPanel.V1\xca\x02\x11NI\\PythonPanel\\V1\xea\x02\x13NI::PythonPanel::V1b\x06proto3') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'ni.pythonpanel.v1.python_panel_service_pb2', globals()) @@ -22,22 +22,18 @@ DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b'\n\025com.ni.pythonpanel.v1B\027PythonPanelServiceProtoP\001Z\rpythonpanelv1\370\001\001\242\002\004NIPP\252\002\"NationalInstruments.PythonPanel.V1\312\002\021NI\\PythonPanel\\V1\352\002\023NI::PythonPanel::V1' - _CONNECTREQUEST._serialized_start=94 - _CONNECTREQUEST._serialized_end=147 - _CONNECTRESPONSE._serialized_start=149 - _CONNECTRESPONSE._serialized_end=166 - _DISCONNECTREQUEST._serialized_start=168 - _DISCONNECTREQUEST._serialized_end=205 - _DISCONNECTRESPONSE._serialized_start=207 - _DISCONNECTRESPONSE._serialized_end=227 - _GETVALUEREQUEST._serialized_start=229 - _GETVALUEREQUEST._serialized_end=282 - _GETVALUERESPONSE._serialized_start=284 - _GETVALUERESPONSE._serialized_end=339 - _SETVALUEREQUEST._serialized_start=341 - _SETVALUEREQUEST._serialized_end=431 - _SETVALUERESPONSE._serialized_start=433 - _SETVALUERESPONSE._serialized_end=451 - _PYTHONPANELSERVICE._serialized_start=454 - _PYTHONPANELSERVICE._serialized_end=817 + _OPENPANELREQUEST._serialized_start=94 + _OPENPANELREQUEST._serialized_end=149 + _OPENPANELRESPONSE._serialized_start=151 + _OPENPANELRESPONSE._serialized_end=170 + _GETVALUEREQUEST._serialized_start=172 + _GETVALUEREQUEST._serialized_end=225 + _GETVALUERESPONSE._serialized_start=227 + _GETVALUERESPONSE._serialized_end=282 + _SETVALUEREQUEST._serialized_start=284 + _SETVALUEREQUEST._serialized_end=374 + _SETVALUERESPONSE._serialized_start=376 + _SETVALUERESPONSE._serialized_end=394 + _PYTHONPANELSERVICE._serialized_start=397 + _PYTHONPANELSERVICE._serialized_end=675 # @@protoc_insertion_point(module_scope) diff --git a/src/ni/pythonpanel/v1/python_panel_service_pb2.pyi b/src/ni/pythonpanel/v1/python_panel_service_pb2.pyi index 919ea75..989f29f 100644 --- a/src/ni/pythonpanel/v1/python_panel_service_pb2.pyi +++ b/src/ni/pythonpanel/v1/python_panel_service_pb2.pyi @@ -12,7 +12,7 @@ import typing DESCRIPTOR: google.protobuf.descriptor.FileDescriptor @typing.final -class ConnectRequest(google.protobuf.message.Message): +class OpenPanelRequest(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor PANEL_ID_FIELD_NUMBER: builtins.int @@ -29,43 +29,17 @@ class ConnectRequest(google.protobuf.message.Message): ) -> None: ... def ClearField(self, field_name: typing.Literal["panel_id", b"panel_id", "panel_uri", b"panel_uri"]) -> None: ... -global___ConnectRequest = ConnectRequest +global___OpenPanelRequest = OpenPanelRequest @typing.final -class ConnectResponse(google.protobuf.message.Message): +class OpenPanelResponse(google.protobuf.message.Message): DESCRIPTOR: google.protobuf.descriptor.Descriptor def __init__( self, ) -> None: ... -global___ConnectResponse = ConnectResponse - -@typing.final -class DisconnectRequest(google.protobuf.message.Message): - DESCRIPTOR: google.protobuf.descriptor.Descriptor - - PANEL_ID_FIELD_NUMBER: builtins.int - panel_id: builtins.str - """Unique ID of the panel""" - def __init__( - self, - *, - panel_id: builtins.str = ..., - ) -> None: ... - def ClearField(self, field_name: typing.Literal["panel_id", b"panel_id"]) -> None: ... - -global___DisconnectRequest = DisconnectRequest - -@typing.final -class DisconnectResponse(google.protobuf.message.Message): - DESCRIPTOR: google.protobuf.descriptor.Descriptor - - def __init__( - self, - ) -> None: ... - -global___DisconnectResponse = DisconnectResponse +global___OpenPanelResponse = OpenPanelResponse @typing.final class GetValueRequest(google.protobuf.message.Message): diff --git a/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py b/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py index 8d80a98..4b04c3e 100644 --- a/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py +++ b/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.py @@ -6,7 +6,7 @@ class PythonPanelServiceStub(object): - """Service interface for connecting to python panels + """Service interface for interacting with python panels """ def __init__(self, channel): @@ -15,15 +15,10 @@ def __init__(self, channel): Args: channel: A grpc.Channel. """ - self.Connect = channel.unary_unary( - '/ni.pythonpanel.v1.PythonPanelService/Connect', - request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectRequest.SerializeToString, - response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectResponse.FromString, - ) - self.Disconnect = channel.unary_unary( - '/ni.pythonpanel.v1.PythonPanelService/Disconnect', - request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectRequest.SerializeToString, - response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectResponse.FromString, + self.OpenPanel = channel.unary_unary( + '/ni.pythonpanel.v1.PythonPanelService/OpenPanel', + request_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelRequest.SerializeToString, + response_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelResponse.FromString, ) self.GetValue = channel.unary_unary( '/ni.pythonpanel.v1.PythonPanelService/GetValue', @@ -38,11 +33,11 @@ def __init__(self, channel): class PythonPanelServiceServicer(object): - """Service interface for connecting to python panels + """Service interface for interacting with python panels """ - def Connect(self, request, context): - """Connect to a panel and open it + def OpenPanel(self, request, context): + """Open a panel Status Codes for errors: - NOT_FOUND: the file for the panel was not found """ @@ -50,15 +45,6 @@ def Connect(self, request, context): context.set_details('Method not implemented!') raise NotImplementedError('Method not implemented!') - def Disconnect(self, request, context): - """Disconnect from a panel (does not close the panel) - Status Codes for errors: - - NOT_FOUND: the panel with the specified id was not found - """ - context.set_code(grpc.StatusCode.UNIMPLEMENTED) - context.set_details('Method not implemented!') - raise NotImplementedError('Method not implemented!') - def GetValue(self, request, context): """Get a value for a control on the panel Status Codes for errors: @@ -80,15 +66,10 @@ def SetValue(self, request, context): def add_PythonPanelServiceServicer_to_server(servicer, server): rpc_method_handlers = { - 'Connect': grpc.unary_unary_rpc_method_handler( - servicer.Connect, - request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectRequest.FromString, - response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectResponse.SerializeToString, - ), - 'Disconnect': grpc.unary_unary_rpc_method_handler( - servicer.Disconnect, - request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectRequest.FromString, - response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectResponse.SerializeToString, + 'OpenPanel': grpc.unary_unary_rpc_method_handler( + servicer.OpenPanel, + request_deserializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelRequest.FromString, + response_serializer=ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelResponse.SerializeToString, ), 'GetValue': grpc.unary_unary_rpc_method_handler( servicer.GetValue, @@ -108,28 +89,11 @@ def add_PythonPanelServiceServicer_to_server(servicer, server): # This class is part of an EXPERIMENTAL API. class PythonPanelService(object): - """Service interface for connecting to python panels + """Service interface for interacting with python panels """ @staticmethod - def Connect(request, - target, - options=(), - channel_credentials=None, - call_credentials=None, - insecure=False, - compression=None, - wait_for_ready=None, - timeout=None, - metadata=None): - return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/Connect', - ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectRequest.SerializeToString, - ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.ConnectResponse.FromString, - options, channel_credentials, - insecure, call_credentials, compression, wait_for_ready, timeout, metadata) - - @staticmethod - def Disconnect(request, + def OpenPanel(request, target, options=(), channel_credentials=None, @@ -139,9 +103,9 @@ def Disconnect(request, wait_for_ready=None, timeout=None, metadata=None): - return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/Disconnect', - ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectRequest.SerializeToString, - ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.DisconnectResponse.FromString, + return grpc.experimental.unary_unary(request, target, '/ni.pythonpanel.v1.PythonPanelService/OpenPanel', + ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelRequest.SerializeToString, + ni_dot_pythonpanel_dot_v1_dot_python__panel__service__pb2.OpenPanelResponse.FromString, options, channel_credentials, insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi b/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi index 97ac81a..4b9a62a 100644 --- a/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi +++ b/src/ni/pythonpanel/v1/python_panel_service_pb2_grpc.pyi @@ -18,27 +18,18 @@ class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ... class PythonPanelServiceStub: - """Service interface for connecting to python panels""" + """Service interface for interacting with python panels""" def __init__(self, channel: typing.Union[grpc.Channel, grpc.aio.Channel]) -> None: ... - Connect: grpc.UnaryUnaryMultiCallable[ - ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest, - ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse, + OpenPanel: grpc.UnaryUnaryMultiCallable[ + ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelRequest, + ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelResponse, ] - """Connect to a panel and open it + """Open a panel Status Codes for errors: - NOT_FOUND: the file for the panel was not found """ - Disconnect: grpc.UnaryUnaryMultiCallable[ - ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest, - ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse, - ] - """Disconnect from a panel (does not close the panel) - Status Codes for errors: - - NOT_FOUND: the panel with the specified id was not found - """ - GetValue: grpc.UnaryUnaryMultiCallable[ ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest, ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse, @@ -58,26 +49,17 @@ class PythonPanelServiceStub: """ class PythonPanelServiceAsyncStub: - """Service interface for connecting to python panels""" + """Service interface for interacting with python panels""" - Connect: grpc.aio.UnaryUnaryMultiCallable[ - ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest, - ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse, + OpenPanel: grpc.aio.UnaryUnaryMultiCallable[ + ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelRequest, + ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelResponse, ] - """Connect to a panel and open it + """Open a panel Status Codes for errors: - NOT_FOUND: the file for the panel was not found """ - Disconnect: grpc.aio.UnaryUnaryMultiCallable[ - ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest, - ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse, - ] - """Disconnect from a panel (does not close the panel) - Status Codes for errors: - - NOT_FOUND: the panel with the specified id was not found - """ - GetValue: grpc.aio.UnaryUnaryMultiCallable[ ni.pythonpanel.v1.python_panel_service_pb2.GetValueRequest, ni.pythonpanel.v1.python_panel_service_pb2.GetValueResponse, @@ -97,30 +79,19 @@ class PythonPanelServiceAsyncStub: """ class PythonPanelServiceServicer(metaclass=abc.ABCMeta): - """Service interface for connecting to python panels""" + """Service interface for interacting with python panels""" @abc.abstractmethod - def Connect( + def OpenPanel( self, - request: ni.pythonpanel.v1.python_panel_service_pb2.ConnectRequest, + request: ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelRequest, context: _ServicerContext, - ) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.ConnectResponse]]: - """Connect to a panel and open it + ) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.OpenPanelResponse]]: + """Open a panel Status Codes for errors: - NOT_FOUND: the file for the panel was not found """ - @abc.abstractmethod - def Disconnect( - self, - request: ni.pythonpanel.v1.python_panel_service_pb2.DisconnectRequest, - context: _ServicerContext, - ) -> typing.Union[ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse, collections.abc.Awaitable[ni.pythonpanel.v1.python_panel_service_pb2.DisconnectResponse]]: - """Disconnect from a panel (does not close the panel) - Status Codes for errors: - - NOT_FOUND: the panel with the specified id was not found - """ - @abc.abstractmethod def GetValue( self, diff --git a/src/nipanel/_panel.py b/src/nipanel/_panel.py index 91a1c46..4e6ca3a 100644 --- a/src/nipanel/_panel.py +++ b/src/nipanel/_panel.py @@ -1,9 +1,6 @@ from __future__ import annotations -import sys from abc import ABC -from types import TracebackType -from typing import TYPE_CHECKING import grpc from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient @@ -11,15 +8,9 @@ from nipanel._panel_client import PanelClient -if TYPE_CHECKING: - if sys.version_info >= (3, 11): - from typing import Self - else: - from typing_extensions import Self - class Panel(ABC): - """This class allows you to connect to a panel and specify values for its controls.""" + """This class allows you to open a panel and specify values for its controls.""" _panel_client: PanelClient _panel_id: str @@ -59,28 +50,9 @@ def panel_uri(self) -> str: """Read-only accessor for the panel URI.""" return self._panel_uri - def __enter__(self) -> Self: - """Enter the runtime context related to this object.""" - self.connect() - return self - - def __exit__( - self, - exctype: type[BaseException] | None, - excinst: BaseException | None, - exctb: TracebackType | None, - ) -> bool | None: - """Exit the runtime context related to this object.""" - self.disconnect() - return None - - def connect(self) -> None: - """Connect to the panel and open it.""" - self._panel_client.connect(self._panel_id, self._panel_uri) - - def disconnect(self) -> None: - """Disconnect from the panel (does not close the panel).""" - self._panel_client.disconnect(self._panel_id) + def open_panel(self) -> None: + """Open the panel.""" + self._panel_client.open_panel(self._panel_id, self._panel_uri) def get_value(self, value_id: str) -> object: """Get the value for a control on the panel. diff --git a/src/nipanel/_panel_client.py b/src/nipanel/_panel_client.py index 4b97440..9e62763 100644 --- a/src/nipanel/_panel_client.py +++ b/src/nipanel/_panel_client.py @@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Callable, TypeVar import grpc -from ni.pythonpanel.v1.python_panel_service_pb2 import ConnectRequest, DisconnectRequest +from ni.pythonpanel.v1.python_panel_service_pb2 import OpenPanelRequest from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool @@ -52,15 +52,10 @@ def __init__( self._grpc_channel = grpc_channel self._stub: PythonPanelServiceStub | None = None - def connect(self, panel_id: str, panel_uri: str) -> None: - """Connect to the panel and open it.""" - connect_request = ConnectRequest(panel_id=panel_id, panel_uri=panel_uri) - self._invoke_with_retry(self._get_stub().Connect, connect_request) - - def disconnect(self, panel_id: str) -> None: - """Disconnect from the panel (does not close the panel).""" - disconnect_request = DisconnectRequest(panel_id=panel_id) - self._invoke_with_retry(self._get_stub().Disconnect, disconnect_request) + def open_panel(self, panel_id: str, panel_uri: str) -> None: + """Open the panel.""" + open_panel_request = OpenPanelRequest(panel_id=panel_id, panel_uri=panel_uri) + self._invoke_with_retry(self._get_stub().OpenPanel, open_panel_request) def _get_stub(self) -> PythonPanelServiceStub: if self._stub is None: diff --git a/src/nipanel/_streamlit_panel.py b/src/nipanel/_streamlit_panel.py index aac55c9..246d24b 100644 --- a/src/nipanel/_streamlit_panel.py +++ b/src/nipanel/_streamlit_panel.py @@ -8,7 +8,7 @@ class StreamlitPanel(Panel): - """This class allows you to connect to a Streamlit panel and specify values for its controls.""" + """This class allows you to open a Streamlit panel and specify values for its controls.""" PYTHON_PANEL_SERVICE = "ni.pythonpanel.v1.PythonPanelService" diff --git a/tests/unit/test_python_panel_service_stub.py b/tests/unit/test_python_panel_service_stub.py index f7e4171..3aaf911 100644 --- a/tests/unit/test_python_panel_service_stub.py +++ b/tests/unit/test_python_panel_service_stub.py @@ -1,26 +1,16 @@ from google.protobuf.any_pb2 import Any from google.protobuf.wrappers_pb2 import StringValue from ni.pythonpanel.v1.python_panel_service_pb2 import ( - ConnectRequest, - DisconnectRequest, + OpenPanelRequest, GetValueRequest, SetValueRequest, ) from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub -def test___connect___gets_response(python_panel_service_stub: PythonPanelServiceStub) -> None: - request = ConnectRequest(panel_id="test_panel", panel_uri="path/to/panel") - response = python_panel_service_stub.Connect(request) - - assert response is not None # Ensure response is returned - - -def test___disconnect___gets_response( - python_panel_service_stub: PythonPanelServiceStub, -) -> None: - request = DisconnectRequest(panel_id="test_panel") - response = python_panel_service_stub.Disconnect(request) +def test___open_panel___gets_response(python_panel_service_stub: PythonPanelServiceStub) -> None: + request = OpenPanelRequest(panel_id="test_panel", panel_uri="path/to/panel") + response = python_panel_service_stub.OpenPanel(request) assert response is not None # Ensure response is returned diff --git a/tests/unit/test_streamlit_panel.py b/tests/unit/test_streamlit_panel.py index 723da17..3ffb5c2 100644 --- a/tests/unit/test_streamlit_panel.py +++ b/tests/unit/test_streamlit_panel.py @@ -10,45 +10,32 @@ def test___panel___has_panel_id_and_panel_uri() -> None: assert panel.panel_uri == "path/to/script" -def test___connected_panel___set_value___gets_same_value( +def test___opened_panel___set_value___gets_same_value( grpc_channel_for_fake_panel_service: grpc.Channel, ) -> None: channel = grpc_channel_for_fake_panel_service panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=channel) - panel.connect() + panel.open_panel() panel.set_value("test_id", "test_value") # TODO: AB#3095681 - change asserted value to test_value assert panel.get_value("test_id") == "placeholder value" - panel.disconnect() -def test___with_panel___set_value___gets_same_value( - grpc_channel_for_fake_panel_service: grpc.Channel, -) -> None: - channel = grpc_channel_for_fake_panel_service - with StreamlitPanel("my_panel", "path/to/script", grpc_channel=channel) as panel: - panel.set_value("test_id", "test_value") - - # TODO: AB#3095681 - change asserted value to test_value - assert panel.get_value("test_id") == "placeholder value" - - -def test___first_connect_fails___connect___gets_value( +def test___first_open_panel_fails___open_panel___gets_value( fake_python_panel_service: FakePythonPanelService, grpc_channel_for_fake_panel_service: grpc.Channel, ) -> None: - """Test that panel.connect() will automatically retry once.""" + """Test that panel.open_panel() will automatically retry once.""" channel = grpc_channel_for_fake_panel_service service = fake_python_panel_service - # Simulate a failure on the first connect attempt - service.servicer.fail_next_connect() + # Simulate a failure on the first attempt + service.servicer.fail_next_open_panel() panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=channel) - panel.connect() + panel.open_panel() panel.set_value("test_id", "test_value") # TODO: AB#3095681 - change asserted value to test_value assert panel.get_value("test_id") == "placeholder value" - panel.disconnect() diff --git a/tests/utils/_fake_python_panel_servicer.py b/tests/utils/_fake_python_panel_servicer.py index 9895e99..7427400 100644 --- a/tests/utils/_fake_python_panel_servicer.py +++ b/tests/utils/_fake_python_panel_servicer.py @@ -3,10 +3,8 @@ import google.protobuf.any_pb2 as any_pb2 import grpc from ni.pythonpanel.v1.python_panel_service_pb2 import ( - ConnectRequest, - ConnectResponse, - DisconnectRequest, - DisconnectResponse, + OpenPanelRequest, + OpenPanelResponse, GetValueRequest, GetValueResponse, SetValueRequest, @@ -19,20 +17,14 @@ class FakePythonPanelServicer(PythonPanelServiceServicer): """Fake implementation of the PythonPanelServicer for testing.""" _values = {"test_value": any_pb2.Any()} - _fail_next_connect = False + _fail_next_open_panel = False - def Connect(self, request: ConnectRequest, context: Any) -> ConnectResponse: # noqa: N802 + def OpenPanel(self, request: OpenPanelRequest, context: Any) -> OpenPanelResponse: # noqa: N802 """Trivial implementation for testing.""" - if self._fail_next_connect: - self._fail_next_connect = False - context.abort(grpc.StatusCode.UNAVAILABLE, "Simulated connection failure") - return ConnectResponse() - - def Disconnect( # noqa: N802 - self, request: DisconnectRequest, context: Any - ) -> DisconnectResponse: - """Trivial implementation for testing.""" - return DisconnectResponse() + if self._fail_next_open_panel: + self._fail_next_open_panel = False + context.abort(grpc.StatusCode.UNAVAILABLE, "Simulated failure") + return OpenPanelResponse() def GetValue(self, request: GetValueRequest, context: Any) -> GetValueResponse: # noqa: N802 """Trivial implementation for testing.""" @@ -44,6 +36,6 @@ def SetValue(self, request: SetValueRequest, context: Any) -> SetValueResponse: self._values[request.value_id] = request.value return SetValueResponse() - def fail_next_connect(self) -> None: - """Set whether the Connect method should fail the next time it is called.""" - self._fail_next_connect = True + def fail_next_open_panel(self) -> None: + """Set whether the OpenPanel method should fail the next time it is called.""" + self._fail_next_open_panel = True