1616CONSUMER_ROOT = '/consumer_exchange_groups/consumer exchanges/consumer_exchanges'
1717PRODUCER_ROOT = '/producer_exchange_groups/producer exchanges/producer_exchanges'
1818
19- def _create_url (device_path , type , exchange = None ):
19+ def _create_url (device_path , ex_type , exchange_name = None ):
2020 '''Creates url object for the "exchange" branch of Kepware's project tree. Used
2121 to build a part of Kepware Configuration API URL structure
2222
@@ -25,18 +25,18 @@ def _create_url(device_path, type, exchange = None):
2525 path_obj = kepconfig .path_split (device_path )
2626 device_root = channel ._create_url (path_obj ['channel' ]) + device ._create_url (path_obj ['device' ])
2727
28- if exchange == None :
29- if type == EGD .CONSUMER_EXCHANGE :
28+ if exchange_name == None :
29+ if ex_type == EGD .CONSUMER_EXCHANGE :
3030 return device_root + CONSUMER_ROOT
3131 else :
3232 return device_root + PRODUCER_ROOT
3333 else :
34- if type == EGD .CONSUMER_EXCHANGE :
35- return '{}/ {}/{}' .format (device_root ,CONSUMER_ROOT ,exchange )
34+ if ex_type == EGD .CONSUMER_EXCHANGE :
35+ return '{}{}/{}' .format (device_root ,CONSUMER_ROOT ,exchange_name )
3636 else :
37- return '{}/ {}/{}' .format (device_root ,PRODUCER_ROOT ,exchange )
37+ return '{}{}/{}' .format (device_root ,PRODUCER_ROOT ,exchange_name )
3838
39- def add_exchange (server , device_path , type , DATA ) -> Union [bool , list ]:
39+ def add_exchange (server , device_path , ex_type , DATA ) -> Union [bool , list ]:
4040 '''Add a "exchange" or multiple "exchange" objects to Kepware. Can be used to pass children of a exchange object
4141 such as ranges. This allows you to create a exchange and ranges for the exchange all in one function, if desired.
4242
@@ -70,7 +70,7 @@ def add_exchange(server, device_path, type, DATA) -> Union[bool, list]:
7070 KepURLError - If urllib provides an URLError
7171 '''
7272
73- r = server ._config_add (server .url + _create_url (device_path , type ), DATA )
73+ r = server ._config_add (server .url + _create_url (device_path , ex_type ), DATA )
7474 if r .code == 201 : return True
7575 elif r .code == 207 :
7676 errors = []
@@ -80,7 +80,7 @@ def add_exchange(server, device_path, type, DATA) -> Union[bool, list]:
8080 return errors
8181 else : return False
8282
83- def del_exchange (server , device_path , type , exchange ) -> bool :
83+ def del_exchange (server , device_path , ex_type , exchange_name ) -> bool :
8484 '''Delete a "exchange" object in Kepware. This will delete all children as well
8585
8686 INPUTS:
@@ -90,9 +90,9 @@ def del_exchange(server, device_path, type, exchange) -> bool:
9090 "device_path" - path to exchanges. Standard Kepware address decimal
9191 notation string such as "channel1.device1"
9292
93- "type " - type of exchange either consumer or producer
93+ "ex_type " - type of exchange either consumer or producer
9494
95- "exchange " - name of exchange
95+ "exchange_name " - name of exchange
9696
9797 RETURNS:
9898
@@ -104,11 +104,11 @@ def del_exchange(server, device_path, type, exchange) -> bool:
104104 KepURLError - If urllib provides an URLError
105105 '''
106106
107- r = server ._config_del (server .url + _create_url (device_path , type , exchange ))
107+ r = server ._config_del (server .url + _create_url (device_path , ex_type , exchange_name ))
108108 if r .code == 200 : return True
109109 else : return False
110110
111- def modify_exchange (server , device_path , type , DATA , exchange_name = None , force = False ) -> bool :
111+ def modify_exchange (server , device_path , ex_type , DATA , exchange_name = None , force = False ) -> bool :
112112 '''Modify a exchange object and it's properties in Kepware. If a "exchange_name" is not provided as an input,
113113 you need to identify the exchange in the 'common.ALLTYPES_NAME' property field in the "DATA". It will
114114 assume that is the exchange that is to be modified.
@@ -120,7 +120,7 @@ def modify_exchange(server, device_path, type, DATA, exchange_name = None, force
120120 "device_path" - path to exchanges. Standard Kepware address decimal
121121 notation string such as "channel1.device1"
122122
123- "type " - type of exchange either consumer or producer
123+ "ex_type " - type of exchange either consumer or producer
124124
125125 "DATA" - properly JSON object (dict) of the exchange properties to be modified.
126126
@@ -141,7 +141,7 @@ def modify_exchange(server, device_path, type, DATA, exchange_name = None, force
141141 exchange_data = server ._force_update_check (force , DATA )
142142 if exchange_name == None :
143143 try :
144- r = server ._config_update (server .url + _create_url (device_path , type , exchange_data ['common.ALLTYPES_NAME' ]), exchange_data )
144+ r = server ._config_update (server .url + _create_url (device_path , ex_type , exchange_data ['common.ALLTYPES_NAME' ]), exchange_data )
145145 if r .code == 200 : return True
146146 else : return False
147147 except KeyError as err :
@@ -150,11 +150,11 @@ def modify_exchange(server, device_path, type, DATA, exchange_name = None, force
150150 # except Exception as e:
151151 # return 'Error: Error with {}: {}'.format(inspect.currentframe().f_code.co_name, str(e))
152152 else :
153- r = server ._config_update (server .url + _create_url (device_path , type , exchange_name ), exchange_data )
153+ r = server ._config_update (server .url + _create_url (device_path , ex_type , exchange_name ), exchange_data )
154154 if r .code == 200 : return True
155155 else : return False
156156
157- def get_exchange (server , device_path , type , exchange_name = None ) -> Union [dict , list ]:
157+ def get_exchange (server , device_path , ex_type , exchange_name = None ) -> Union [dict , list ]:
158158 '''Returns the properties of the exchange object or a list of all exchanges and their
159159 properties for the type input. Returned object is JSON.
160160
@@ -165,7 +165,7 @@ def get_exchange(server, device_path, type, exchange_name = None) -> Union[dict,
165165 "device_path" - path to exchanges. Standard Kepware address decimal
166166 notation string such as "channel1.device1"
167167
168- "type " - type of exchange either consumer or producer
168+ "ex_type " - type of exchange either consumer or producer
169169
170170 "exchange_name" - name of exchange
171171
@@ -179,9 +179,9 @@ def get_exchange(server, device_path, type, exchange_name = None) -> Union[dict,
179179 KepURLError - If urllib provides an URLError
180180 '''
181181 if exchange_name == None :
182- r = server ._config_get (server .url + _create_url (device_path , type ))
182+ r = server ._config_get (server .url + _create_url (device_path , ex_type ))
183183 else :
184- r = server ._config_get (server .url + _create_url (device_path , type , exchange_name ))
184+ r = server ._config_get (server .url + _create_url (device_path , ex_type , exchange_name ))
185185 return r .payload
186186
187187def get_all_exchanges (server , device_path ):
0 commit comments