kepconfig.adv_tags.average_tags

average_tags exposes an API to allow modifications (add, delete, modify) to average 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"""`average_tags` exposes an API to allow modifications (add, delete, modify) to 
 11average 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
 20AVERAGE_TAGS_ROOT = '/average_tags'
 21
 22def _get_average_tags_url(tag: str = None) -> str:
 23    '''Creates url object for the "average_tags" branch of Kepware's project tree.
 24    
 25    Returns the average tag specific url when a value is passed as the tag name.
 26    '''
 27    if tag is None:
 28        return AVERAGE_TAGS_ROOT
 29    else:
 30        return f'{AVERAGE_TAGS_ROOT}/{_url_parse_object(tag)}'
 31
 32def add_average_tag(server: server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
 33    '''Add `"average_tag"` or multiple `"average_tag"` objects to a specific path in Kepware.
 34    Can be used to pass a list of average 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 average 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 average 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    average 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_average_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 = []
 56        for item in r.payload:
 57            if item['code'] != 201:
 58                errors.append(item)
 59        return errors
 60    else:
 61        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
 62
 63def modify_average_tag(server: server, avg_tag_path: str, DATA: dict, force: bool = False) -> bool:
 64    '''Modify an `"average_tag"` object and its properties in Kepware.
 65
 66    :param server: instance of the `server` class
 67    :param avg_tag_path: path identifying location and average tag to modify. Standard Kepware address decimal 
 68    notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
 69    :param DATA: Dict of the `average_tag` properties to be modified
 70    :param force: *(optional)* if True, will force the configuration update to the Kepware server
 71
 72    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 73
 74    :raises KepHTTPError: If urllib provides an HTTPError
 75    :raises KepURLError: If urllib provides an URLError
 76    '''
 77    avg_tag_data = server._force_update_check(force, DATA)
 78    path_obj = adv_tags._adv_tag_path_split(avg_tag_path, isItem=True)
 79    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url(path_obj['item'])
 80
 81    r = server._config_update(url, avg_tag_data)
 82    if r.code == 200:
 83        return True
 84    else:
 85        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
 86
 87def del_average_tag(server: server, avg_tag_path: str) -> bool:
 88    '''Delete `"average_tag"` object at a specific path in Kepware.
 89
 90    :param server: instance of the `server` class
 91    :param avg_tag_path: path identifying location and average tag to delete. Standard Kepware address decimal 
 92    notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
 93
 94    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 95
 96    :raises KepHTTPError: If urllib provides an HTTPError
 97    :raises KepURLError: If urllib provides an URLError
 98    '''
 99    path_obj = adv_tags._adv_tag_path_split(avg_tag_path, isItem=True)
100    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url(path_obj['item'])
101
102    r = server._config_del(url)
103    if r.code == 200:
104        return True
105    else:
106        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)
107
108def get_average_tag(server: server, avg_tag_path: str) -> dict:
109    '''Returns the properties of the `"average_tag"` object at a specific path in Kepware.
110
111    :param server: instance of the `server` class
112    :param avg_tag_path: path identifying location and average tag to retrieve. Standard Kepware address decimal 
113    notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
114
115    :return: Dict of data for the average tag requested
116
117    :raises KepHTTPError: If urllib provides an HTTPError
118    :raises KepURLError: If urllib provides an URLError
119    '''
120    path_obj = adv_tags._adv_tag_path_split(avg_tag_path, isItem=True)
121    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url(path_obj['item'])
122
123    r = server._config_get(url)
124    return r.payload
125
126def get_all_average_tags(server: server, adv_tag_group_path: str, *, options: dict = None) -> list:
127    '''Returns the properties of all `"average_tag"` objects at a specific path in Kepware.
128
129    :param server: instance of the `server` class
130    :param adv_tag_group_path: path identifying location to retrieve average tag list. Standard Kepware address decimal
131    notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
132    :param options: *(optional)* Dict of parameters to filter, sort or paginate the list of average tags. Options are `filter`,
133        `sortOrder`, `sortProperty`, `pageNumber`, and `pageSize`
134
135    :return: List of data for all average tags
136
137    :raises KepHTTPError: If urllib provides an HTTPError
138    :raises KepURLError: If urllib provides an URLError
139    '''
140    path_obj = adv_tags._adv_tag_path_split(adv_tag_group_path, isItem=False)
141    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url()
142
143    r = server._config_get(url, params=options)
144    return r.payload
AVERAGE_TAGS_ROOT = '/average_tags'
def add_average_tag( server: kepconfig.connection.server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
33def add_average_tag(server: server, adv_tag_group_path: str, DATA: Union[dict, list]) -> Union[bool, list]:
34    '''Add `"average_tag"` or multiple `"average_tag"` objects to a specific path in Kepware.
35    Can be used to pass a list of average 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 average 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 average 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    average 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_average_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 = []
57        for item in r.payload:
58            if item['code'] != 201:
59                errors.append(item)
60        return errors
61    else:
62        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

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

Parameters
  • server: instance of the server class
  • adv_tag_group_path: path identifying where to add average tag(s). Standard Kepware address decimal notation string such as "_advancedtags.AdvTagGroup1" or "_advancedtags.AdvTagGroup1.AdvTagGroupChild"
  • DATA: Dict or List of Dicts of the average 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 average tags added that failed.

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

Modify an "average_tag" object and its properties in Kepware.

Parameters
  • server: instance of the server class
  • avg_tag_path: path identifying location and average tag to modify. Standard Kepware address decimal notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
  • DATA: Dict of the average_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_average_tag(server: kepconfig.connection.server, avg_tag_path: str) -> bool:
 88def del_average_tag(server: server, avg_tag_path: str) -> bool:
 89    '''Delete `"average_tag"` object at a specific path in Kepware.
 90
 91    :param server: instance of the `server` class
 92    :param avg_tag_path: path identifying location and average tag to delete. Standard Kepware address decimal 
 93    notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
 94
 95    :return: True - If a "HTTP 200 - OK" is received from Kepware server
 96
 97    :raises KepHTTPError: If urllib provides an HTTPError
 98    :raises KepURLError: If urllib provides an URLError
 99    '''
100    path_obj = adv_tags._adv_tag_path_split(avg_tag_path, isItem=True)
101    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url(path_obj['item'])
102
103    r = server._config_del(url)
104    if r.code == 200:
105        return True
106    else:
107        raise KepHTTPError(r.url, r.code, r.msg, r.hdrs, r.payload)

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

Parameters
  • server: instance of the server class
  • avg_tag_path: path identifying location and average tag to delete. Standard Kepware address decimal notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
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_average_tag(server: kepconfig.connection.server, avg_tag_path: str) -> dict:
109def get_average_tag(server: server, avg_tag_path: str) -> dict:
110    '''Returns the properties of the `"average_tag"` object at a specific path in Kepware.
111
112    :param server: instance of the `server` class
113    :param avg_tag_path: path identifying location and average tag to retrieve. Standard Kepware address decimal 
114    notation string including the average tag such as "_advancedtags.AdvTagGroup1.AvgTag1"
115
116    :return: Dict of data for the average tag requested
117
118    :raises KepHTTPError: If urllib provides an HTTPError
119    :raises KepURLError: If urllib provides an URLError
120    '''
121    path_obj = adv_tags._adv_tag_path_split(avg_tag_path, isItem=True)
122    url = adv_tags._create_adv_tags_base_url(server.url, path_obj) + _get_average_tags_url(path_obj['item'])
123
124    r = server._config_get(url)
125    return r.payload

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

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

Dict of data for the average tag requested

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

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

Parameters
  • server: instance of the server class
  • adv_tag_group_path: path identifying location to retrieve average 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 average tags. Options are filter, sortOrder, sortProperty, pageNumber, and pageSize
Returns

List of data for all average tags

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