kepconfig.adv_tags.min_tags

minimum_tags exposes an API to allow modifications (add, delete, modify) to minimum tag objects within the Kepware Configuration API

  1# -------------------------------------------------------------------------
  2# Copyright (c) PTC Inc. and/or all its affiliates. All rights reserved.
  3# See License.txt in the project root for
  4# license information.
  5# --------------------------------------------------------------------------
  6
  7# Note: The code within this file was created in total or in part
  8#  with the use of AI tools.
  9
 10r"""`minimum_tags` exposes an API to allow modifications (add, delete, modify) to 
 11minimum tag objects within the Kepware Configuration API
 12"""
 13
 14from ..connection import server
 15from ..error import KepError, KepHTTPError
 16from ..utils import _url_parse_object
 17from typing import Union
 18from .. import adv_tags
 19
 20MINIMUM_TAGS_ROOT = '/minimum_tags'
 21
 22def _get_minimum_tags_url(tag: str = None) -> str:
 23    '''Creates url object for the "minimum_tags" branch of Kepware's project tree.
 24    
 25    Returns the minimum tag specific url when a value is passed as the tag name.
 26    '''
 27    if tag is None:
 28        return MINIMUM_TAGS_ROOT
 29    else:
 30        return f'{MINIMUM_TAGS_ROOT}/{_url_parse_object(tag)}'
 31
 32def add_minimum_tag(server: server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
 33    '''Add `"minimum_tag"` or multiple `"minimum_tag"` objects to a specific path in Kepware.
 34    Can be used to pass a list of minimum tags to be added at one path location.
 35
 36    :param server: instance of the `server` class
 37    :param adv_tag_group_path: path identifying where to add minimum tag(s). Standard Kepware address decimal 
 38    notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
 39    :param DATA: Dict or List of Dicts of the minimum tag(s) to add
 40
 41    :return: True - If a "HTTP 201 - Created" is received from Kepware server
 42    :return: If a "HTTP 207 - Multi-Status" is received from Kepware with a list of dict error responses for all 
 43    minimum tags added that failed.
 44
 45    :raises KepHTTPError: If urllib provides an HTTPError
 46    :raises KepURLError: If urllib provides an URLError
 47    '''
 48    path_obj = adv_tags._adv_tag_path_split(adv_tag_group_path, isItem=False)
 49    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url()
 50
 51    r = server._config_add(url, DATA)
 52    if r.code == 201:
 53        return True
 54    elif r.code == 207:
 55        errors = [item for item in r.payload if item['code'] != 201]
 56        return errors
 57    else:
 58        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
 59
 60def modify_minimum_tag(server: server, min_tag_path: str, DATA: dict, force: bool = False) -> bool:
 61    '''Modify a `"minimum_tag"` object and its properties in Kepware.
 62
 63    :param server: instance of the `server` class
 64    :param min_tag_path: path identifying location and minimum tag to modify. Standard Kepware address decimal 
 65    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
 66    :param DATA: Dict of the `minimum_tag` properties to be modified
 67    :param force: *(optional)* if True, will force the configuration update to the Kepware server
 68
 69    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 70
 71    :raises KepHTTPError: If urllib provides an HTTPError
 72    :raises KepURLError: If urllib provides an URLError
 73    '''
 74    min_tag_data = server._force_update_check(force, DATA)
 75    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
 76    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
 77
 78    r = server._config_update(url, min_tag_data)
 79    if r.code == 200:
 80        return True
 81    else:
 82        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
 83
 84def del_minimum_tag(server: server, min_tag_path: str) -> bool:
 85    '''Delete `"minimum_tag"` object at a specific path in Kepware.
 86
 87    :param server: instance of the `server` class
 88    :param min_tag_path: path identifying location and minimum tag to delete. Standard Kepware address decimal 
 89    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
 90
 91    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 92
 93    :raises KepHTTPError: If urllib provides an HTTPError
 94    :raises KepURLError: If urllib provides an URLError
 95    '''
 96    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
 97    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
 98
 99    r = server._config_del(url)
100    if r.code == 200:
101        return True
102    else:
103        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
104
105def get_minimum_tag(server: server, min_tag_path: str) -> dict:
106    '''Returns the properties of the `"minimum_tag"` object at a specific path in Kepware.
107
108    :param server: instance of the `server` class
109    :param min_tag_path: path identifying location and minimum tag to retrieve. Standard Kepware address decimal 
110    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
111
112    :return: Dict of data for the minimum tag requested
113
114    :raises KepHTTPError: If urllib provides an HTTPError
115    :raises KepURLError: If urllib provides an URLError
116    '''
117    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
118    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
119
120    r = server._config_get(url)
121    return r.payload
122
123def get_all_minimum_tags(server: server, adv_tag_group_path: str, *, options: dict = None) -> list:
124    '''Returns the properties of all `"minimum_tag"` objects at a specific path in Kepware.
125
126    :param server: instance of the `server` class
127    :param adv_tag_group_path: path identifying location to retrieve minimum tag list. Standard Kepware address decimal
128    notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
129    :param options: *(optional)* Dict of parameters to filter, sort or paginate the list of minimum tags. Options are `filter`,
130        `sortOrder`, `sortProperty`, `pageNumber`, and `pageSize`
131
132    :return: List of data for all minimum tags
133
134    :raises KepHTTPError: If urllib provides an HTTPError
135    :raises KepURLError: If urllib provides an URLError
136    '''
137    path_obj = adv_tags._adv_tag_path_split(adv_tag_group_path, isItem=False)
138    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url()
139
140    r = server._config_get(url, params=options)
141    return r.payload
MINIMUM_TAGS_ROOT = '/minimum_tags'
def add_minimum_tag( server: kepconfig.connection.server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
33def add_minimum_tag(server: server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
34    '''Add `"minimum_tag"` or multiple `"minimum_tag"` objects to a specific path in Kepware.
35    Can be used to pass a list of minimum tags to be added at one path location.
36
37    :param server: instance of the `server` class
38    :param adv_tag_group_path: path identifying where to add minimum tag(s). Standard Kepware address decimal 
39    notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
40    :param DATA: Dict or List of Dicts of the minimum tag(s) to add
41
42    :return: True - If a "HTTP 201 - Created" is received from Kepware server
43    :return: If a "HTTP 207 - Multi-Status" is received from Kepware with a list of dict error responses for all 
44    minimum tags added that failed.
45
46    :raises KepHTTPError: If urllib provides an HTTPError
47    :raises KepURLError: If urllib provides an URLError
48    '''
49    path_obj = adv_tags._adv_tag_path_split(adv_tag_group_path, isItem=False)
50    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url()
51
52    r = server._config_add(url, DATA)
53    if r.code == 201:
54        return True
55    elif r.code == 207:
56        errors = [item for item in r.payload if item['code'] != 201]
57        return errors
58    else:
59        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

Add "minimum_tag" or multiple "minimum_tag" objects to a specific path in Kepware. Can be used to pass a list of minimum tags to be added at one path location.

Parameters
  • server: instance of the server class
  • adv_tag_group_path: path identifying where to add minimum tag(s). Standard Kepware address decimal notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
  • DATA: Dict or List of Dicts of the minimum tag(s) to add
Returns

True - If a "HTTP 201 - Created" is received from Kepware server

Returns

If a "HTTP 207 - Multi-Status" is received from Kepware with a list of dict error responses for all minimum tags added that failed.

Raises
  • KepHTTPError: If urllib provides an HTTPError
  • KepURLError: If urllib provides an URLError
def modify_minimum_tag( server: kepconfig.connection.server, min_tag_path: str, DATA: dict, force: bool = False) -> bool:
61def modify_minimum_tag(server: server, min_tag_path: str, DATA: dict, force: bool = False) -> bool:
62    '''Modify a `"minimum_tag"` object and its properties in Kepware.
63
64    :param server: instance of the `server` class
65    :param min_tag_path: path identifying location and minimum tag to modify. Standard Kepware address decimal 
66    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
67    :param DATA: Dict of the `minimum_tag` properties to be modified
68    :param force: *(optional)* if True, will force the configuration update to the Kepware server
69
70    :return: True - If a "HTTP 200 - OK" is received from Kepware server
71
72    :raises KepHTTPError: If urllib provides an HTTPError
73    :raises KepURLError: If urllib provides an URLError
74    '''
75    min_tag_data = server._force_update_check(force, DATA)
76    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
77    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
78
79    r = server._config_update(url, min_tag_data)
80    if r.code == 200:
81        return True
82    else:
83        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

Modify a "minimum_tag" object and its properties in Kepware.

Parameters
  • server: instance of the server class
  • min_tag_path: path identifying location and minimum tag to modify. Standard Kepware address decimal notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
  • DATA: Dict of the minimum_tag properties to be modified
  • force: (optional) if True, will force the configuration update to the Kepware server
Returns

True - If a "HTTP 200 - OK" is received from Kepware server

Raises
  • KepHTTPError: If urllib provides an HTTPError
  • KepURLError: If urllib provides an URLError
def del_minimum_tag(server: kepconfig.connection.server, min_tag_path: str) -> bool:
 85def del_minimum_tag(server: server, min_tag_path: str) -> bool:
 86    '''Delete `"minimum_tag"` object at a specific path in Kepware.
 87
 88    :param server: instance of the `server` class
 89    :param min_tag_path: path identifying location and minimum tag to delete. Standard Kepware address decimal 
 90    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
 91
 92    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 93
 94    :raises KepHTTPError: If urllib provides an HTTPError
 95    :raises KepURLError: If urllib provides an URLError
 96    '''
 97    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
 98    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
 99
100    r = server._config_del(url)
101    if r.code == 200:
102        return True
103    else:
104        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

Delete "minimum_tag" object at a specific path in Kepware.

Parameters
  • server: instance of the server class
  • min_tag_path: path identifying location and minimum tag to delete. Standard Kepware address decimal notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
Returns

True - If a "HTTP 200 - OK" is received from Kepware server

Raises
  • KepHTTPError: If urllib provides an HTTPError
  • KepURLError: If urllib provides an URLError
def get_minimum_tag(server: kepconfig.connection.server, min_tag_path: str) -> dict:
106def get_minimum_tag(server: server, min_tag_path: str) -> dict:
107    '''Returns the properties of the `"minimum_tag"` object at a specific path in Kepware.
108
109    :param server: instance of the `server` class
110    :param min_tag_path: path identifying location and minimum tag to retrieve. Standard Kepware address decimal 
111    notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
112
113    :return: Dict of data for the minimum tag requested
114
115    :raises KepHTTPError: If urllib provides an HTTPError
116    :raises KepURLError: If urllib provides an URLError
117    '''
118    path_obj = adv_tags._adv_tag_path_split(min_tag_path, isItem=True)
119    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url(path_obj['item'])
120
121    r = server._config_get(url)
122    return r.payload

Returns the properties of the "minimum_tag" object at a specific path in Kepware.

Parameters
  • server: instance of the server class
  • min_tag_path: path identifying location and minimum tag to retrieve. Standard Kepware address decimal notation string including the minimum tag such as "_advancedtags.AdvTagGroup1.MinTag1"
Returns

Dict of data for the minimum tag requested

Raises
  • KepHTTPError: If urllib provides an HTTPError
  • KepURLError: If urllib provides an URLError
def get_all_minimum_tags( server: kepconfig.connection.server, adv_tag_group_path: str, *, options: dict = None) -> list:
124def get_all_minimum_tags(server: server, adv_tag_group_path: str, *, options: dict = None) -> list:
125    '''Returns the properties of all `"minimum_tag"` objects at a specific path in Kepware.
126
127    :param server: instance of the `server` class
128    :param adv_tag_group_path: path identifying location to retrieve minimum tag list. Standard Kepware address decimal
129    notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
130    :param options: *(optional)* Dict of parameters to filter, sort or paginate the list of minimum tags. Options are `filter`,
131        `sortOrder`, `sortProperty`, `pageNumber`, and `pageSize`
132
133    :return: List of data for all minimum tags
134
135    :raises KepHTTPError: If urllib provides an HTTPError
136    :raises KepURLError: If urllib provides an URLError
137    '''
138    path_obj = adv_tags._adv_tag_path_split(adv_tag_group_path, isItem=False)
139    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_minimum_tags_url()
140
141    r = server._config_get(url, params=options)
142    return r.payload

Returns the properties of all "minimum_tag" objects at a specific path in Kepware.

Parameters
  • server: instance of the server class
  • adv_tag_group_path: path identifying location to retrieve minimum tag list. Standard Kepware address decimal notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
  • options: (optional) Dict of parameters to filter, sort or paginate the list of minimum tags. Options are filter, sortOrder, sortProperty, pageNumber, and pageSize
Returns

List of data for all minimum tags

Raises
  • KepHTTPError: If urllib provides an HTTPError
  • KepURLError: If urllib provides an URLError