@@ -26,25 +26,19 @@ def _create_url(endpoint = None):
2626 else :
2727 return '{}/{}' .format (UA_ROOT ,endpoint )
2828
29- def add_endpoint (server , DATA ) -> Union [bool , list ]:
30- '''Add an "endpoint" or multiple "endpoint" objects to Kepware UA Server by passing a
29+ def add_endpoint (server : server , DATA : dict | list ) -> Union [bool , list ]:
30+ '''Add an ` "endpoint"` or multiple ` "endpoint"` objects to Kepware UA Server by passing a
3131 list of endpoints to be added all at once.
3232
33- INPUTS:
34- "server" - instance of the "server" class
33+ :param server: instance of the `server` class
34+ :param DATA: Dict or List of Dicts of the UA Endpoints to add
3535
36- "DATA" - properly JSON object (dict) of the endpoint
37- expected by Kepware Configuration API
38-
39- RETURNS:
40- True - If a "HTTP 201 - Created" is received from Kepware
41-
42- List - If a "HTTP 207 - Multi-Status" is received from Kepware with a list of dict error responses for all
36+ :return: True - If a "HTTP 201 - Created" is received from Kepware server
37+ :return: If a "HTTP 207 - Multi-Status" is received from Kepware with a list of dict error responses for all
4338 endpoints added that failed.
4439
45- EXCEPTIONS:
46- KepHTTPError - If urllib provides an HTTPError
47- KepURLError - If urllib provides an URLError
40+ :raises KepHTTPError: If urllib provides an HTTPError
41+ :raises KepURLError: If urllib provides an URLError
4842 '''
4943
5044 r = server ._config_add (server .url + _create_url (), DATA )
@@ -57,47 +51,37 @@ def add_endpoint(server, DATA) -> Union[bool, list]:
5751 return errors
5852 else : raise KepHTTPError (r .url , r .code , r .msg , r .hdrs , r .payload )
5953
60- def del_endpoint (server , endpoint ) -> bool :
61- '''Delete a "endpoint" object in Kepware UA Server
54+ def del_endpoint (server : server , endpoint : str ) -> bool :
55+ '''Delete an ` "endpoint"` object in Kepware UA Server
6256
63- INPUTS:
64- "server" - instance of the "server" class
65-
66- "endpoint" - name of endpoint
57+ :param server: instance of the `server` class
58+ :param endpoint: name of endpoint to delete
6759
68- RETURNS:
69- True - If a "HTTP 200 - OK" is received from Kepware
60+ :return: True - If a "HTTP 200 - OK" is received from Kepware server
7061
71- EXCEPTIONS:
72- KepHTTPError - If urllib provides an HTTPError
73- KepURLError - If urllib provides an URLError
62+ :raises KepHTTPError: If urllib provides an HTTPError
63+ :raises KepURLError: If urllib provides an URLError
7464 '''
7565
7666 r = server ._config_del (server .url + _create_url (endpoint ))
7767 if r .code == 200 : return True
7868 else : raise KepHTTPError (r .url , r .code , r .msg , r .hdrs , r .payload )
7969
80- def modify_endpoint (server , DATA , endpoint = None ) -> bool :
81- '''Modify a endpoint object and it's properties in Kepware UA Server. If a "endpoint" is not provided as an input,
82- you need to identify the endpoint in the 'common.ALLTYPES_NAME' property field in the "DATA". It will
70+ def modify_endpoint (server : server , DATA : dict , endpoint : str = None ) -> bool :
71+ '''Modify a `" endpoint"` object and it's properties in Kepware UA Server. If a ` "endpoint"` is not provided as an input,
72+ you need to identify the endpoint in the * 'common.ALLTYPES_NAME'* property field in the ` "DATA"` . It will
8373 assume that is the endpoint that is to be modified.
8474
85- INPUTS:
86- "server" - instance of the "server" class
87-
88- "DATA" - properly JSON object (dict) of the endpoint properties to be modified.
89-
90- "endpoint" (optional) - name of endpoint to modify. Only needed if not existing in "DATA"
75+ :param server: instance of the `server` class
76+ :param DATA: Dict of the UA endpoint properties to be modified.
77+ :param endpoint: *(optional)* name of endpoint to modify. Only needed if not existing in `"DATA"`
9178
92- RETURNS:
93- True - If a "HTTP 200 - OK" is received from Kepware
79+ :return: True - If a "HTTP 200 - OK" is received from Kepware server
9480
95- EXCEPTIONS:
96- KepHTTPError - If urllib provides an HTTPError
97- KepURLError - If urllib provides an URLError
81+ :raises KepHTTPError: If urllib provides an HTTPError
82+ :raises KepURLError: If urllib provides an URLError
9883 '''
99-
100- # channel_data = server._force_update_check(force, DATA)
84+
10185 if endpoint == None :
10286 try :
10387 r = server ._config_update (server .url + _create_url (DATA ['common.ALLTYPES_NAME' ]), DATA )
@@ -106,48 +90,37 @@ def modify_endpoint(server, DATA, endpoint = None) -> bool:
10690 except KeyError as err :
10791 err_msg = 'Error: No UA Endpoint identified in DATA | Key Error: {}' .format (err )
10892 raise KepError (err_msg )
109-
110- # except Exception as e:
111- # return 'Error: Error with {}: {}'.format(inspect.currentframe().f_code.co_name, str(e))
11293 else :
11394 r = server ._config_update (server .url + _create_url (endpoint ), DATA )
11495 if r .code == 200 : return True
11596 else : raise KepHTTPError (r .url , r .code , r .msg , r .hdrs , r .payload )
11697
117- def get_endpoint (server , endpoint ) -> dict :
118- '''Returns the properties of the endpoint object. Returned object is JSON .
98+ def get_endpoint (server : server , endpoint : str ) -> dict :
99+ '''Returns the properties of the `" endpoint"` object.
119100
120- INPUTS:
121- "server" - instance of the "server" class
122-
123- "endpoint" - name of endpoint
101+ :param server: instance of the `server` class
102+ :param endpoint: name of endpoint to retrieve
124103
125- RETURNS:
126- dict - data for the endpoint requested
104+ :return: Dict of properties for the UA endpoint requested
127105
128- EXCEPTIONS:
129- KepHTTPError - If urllib provides an HTTPError
130- KepURLError - If urllib provides an URLError
106+ :raises KepHTTPError: If urllib provides an HTTPError
107+ :raises KepURLError: If urllib provides an URLError
131108 '''
132109
133110 r = server ._config_get (server .url + _create_url (endpoint ))
134111 return r .payload
135112
136113def get_all_endpoints (server : server , * , options : dict = None ) -> list :
137- '''Returns list of all endpoint objects and their properties. Returned object is JSON list .
114+ '''Returns list of all `" endpoint"` objects and their properties.
138115
139- INPUTS:
140- server - instance of the "server" class
141-
142- options - (optional) Dict of parameters to filter, sort or pagenate the list of UA endpoints. Options are 'filter',
143- 'sortOrder', 'sortProperty', 'pageNumber', and 'pageSize'.
116+ :param server: instance of the `server` class
117+ :param options: *(optional)* Dict of parameters to filter, sort or pagenate the list of UA endpoints. Options are 'filter',
118+ 'sortOrder', 'sortProperty', 'pageNumber', and 'pageSize.
144119
145- RETURNS:
146- list - data for all endpoints requested
120+ :return: List of properties for all UA endpoints requested
147121
148- EXCEPTIONS:
149- KepHTTPError - If urllib provides an HTTPError
150- KepURLError - If urllib provides an URLError
122+ :raises KepHTTPError: If urllib provides an HTTPError
123+ :raises KepURLError: If urllib provides an URLError
151124 '''
152125
153126 r = server ._config_get (f'{ server .url } { _create_url ()} ' , params = options )
0 commit comments