Skip to content

Tp api 7 #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TouchPortalAPI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def onShutdown(data):
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

__version__ = "1.7.10" # this is read from setup.py and possibly other places
__version__ = "1.8" # this is read from setup.py and possibly other places

# maintain backwards compatability
from . client import Client, TYPES
Expand Down
58 changes: 33 additions & 25 deletions TouchPortalAPI/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ def onAction(data):
See also `pyee.ExecutorEventEmitter.error` event.
"""

class PluginCategory:
# see https://www.touch-portal.com/api/v2/index.php?section=description_file_structure
"""
Register Plug-in in specific category within TouchPortal.
"""
audio = "audio"
""" For all audio, music, and media related plug-ins. """
streaming = "streaming"
""" For all streaming related plug-ins. """
content = "content"
""" For all content Creation related plug-ins. """
homeautomation = "homeautomation"
""" For all home automation related plug-ins. """
social = "social"
""" For all social media related plug-ins. """
games = "games"
""" For all games related plug-ins. """
miscellaneous = "misc"
""" Default category when attribute is not set. All plug-ins not fitting in one of the categories above should be placed in this category. """

class Client(ExecutorEventEmitter):
"""
A TCP/IP client for [Touch Portal API](https://www.touch-portal.com/api) plugin integration.
Expand Down Expand Up @@ -452,6 +472,16 @@ def stateUpdate(self, stateId:str, stateValue:str):
"""
self.__stateUpdate(stateId, stateValue, False)

def updateStateList(self, statid:str, value:list):
"""
Updating state lists API 7.0+

Args:
`statid`: The state id to update list
`value`: The new list of values
"""
self.send({"type": "stateListUpdate", "id": statid, "value": value})

def __stateUpdate(self, stateId:str, stateValue:str, forced:bool):
if stateId:
if forced or stateId not in self.currentStates or self.currentStates[stateId] != stateValue:
Expand Down Expand Up @@ -558,33 +588,11 @@ def updateActionData(self, instanceId:str, stateId:str, minValue, maxValue):
"""
self.send({"type": "updateActionData", "instanceId": instanceId, "data": {"minValue": minValue, "maxValue": maxValue, "id": stateId, "type": "number"}})

def getChoiceUpdatelist(self):
def triggerEvent(self, eventId:str, states:dict):
"""
This will return a dict that `choiceUpdate` registered.
example return value `{"choiceUpdateid1": ["item1", "item2", "item3"], "exampleChoiceId": ["Option1", "Option2", "Option3"]}`

You should use this to verify before Updating the choice list
**Note** This is the same as TPClient.choiceUpdateList variable *DO NOT MODIFY* TPClient.choiceUpdateList unless you know what your doing
"""
return self.choiceUpdateList

def getStatelist(self):
"""
This will return a dict that have key pair of states that you last updated.
Example retun value `{"stateId1": "value1", "stateId2": "value2", "stateId3": "value3"}`
This is used to keep track of all states. It will be automatically updated when you update states
**Note** This is the same as TPClient.currentState variable *DO NOT MODIFY* TPClient.currentState unless you know what your doing
"""
return self.currentStates

def getSettinghistory(self):
"""
This will return a dict that have key pair of setting value that you updated previously.

This is used to track settings value that you have updated previously
**Note** This is the same as TPClient.currentSettings variable *DO NOT MODIFY* TPClient.currentSettings unless you know what your doing
This allows you to trigger predefined Event to TouchPortal.
"""
return self.currentSettings
self.send({"type": "triggerEvent", "id": eventId, "states": states})

def send(self, data):
"""
Expand Down
83 changes: 70 additions & 13 deletions TouchPortalAPI/sdk_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `d`: default value, if any
- `c`: optional list of valid value(s) (choices)
- `l`: lookup table for child data structures, if any
- `DV`: deprecated version (if any)

TODO: List valid attribute values per SDK version?
"""
Expand All @@ -37,9 +38,17 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""

TPSDK_DEFAULT_VERSION = 6
TPSDK_DEFAULT_VERSION = 7
""" Default Touch Portal SDK version for generating entry.tp JSON. """

TPSDK_ATTRIBS_SETTINGS_TOOLTIP = {
# key name sdk V required [type(s)] [default value] [valid value list]
'title': { 'v': 7, 'r': False, 't': str },
'body': { 'v': 7, 'r': True, 't': str },
'docUrl': { 'v': 7, 'r': False, 't': str },
}
""" [Setting Tooltip structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_settings) """

TPSDK_ATTRIBS_SETTINGS = {
# key name sdk V required [type(s)] [default value] [valid value list]
'name': { 'v': 3, 'r': True, 't': str },
Expand All @@ -50,6 +59,7 @@
'minValue': { 'v': 3, 'r': False, 't': int },
'maxValue': { 'v': 3, 'r': False, 't': int },
'readOnly': { 'v': 3, 'r': False, 't': bool, 'd': False },
'tooltip': { 'v': 7, 'r': False, 't': dict, 'l': TPSDK_ATTRIBS_SETTINGS_TOOLTIP },
}
""" [Settings structure](https://www.touch-portal.com/api/index.php?section=settings) """

Expand All @@ -71,16 +81,16 @@
'format': { 'v': 1, 'r': True, 't': str },
'type': { 'v': 1, 'r': True, 't': str, 'd': "communicate", 'c': ["communicate"] },
'valueChoices': { 'v': 1, 'r': True, 't': list, 'd': [] },
'valueType': { 'v': 1, 'r': True, 't': str, 'd': "choice", 'c': ["choice"] },
'valueType': { 'v': 1, 'r': True, 't': str, 'd': "choice", 'c': ["choice", "text"] }, #todo somehow limit `text` to v7+
'valueStateId': { 'v': 1, 'r': True, 't': str },
}
""" [Event structure](https://www.touch-portal.com/api/index.php?section=events) """

TPSDK_ATTRIBS_ACT_DATA = {
# key name sdk V required [type(s)] [default value] [valid value list]
# key name sdk V required [type(s)] [default value] [valid value list] [Deprecate version(DV)]
'id': { 'v': 1, 'r': True, 't': str },
'type': { 'v': 1, 'r': True, 't': str, 'd': "text", 'c': ["text","number","switch","choice","file","folder","color"] },
'label': { 'v': 1, 'r': True, 't': str },
'label': { 'v': 1, 'r': True, 't': str, "DV": 7 }, # DEPRECATED V7
'default': { 'v': 1, 'r': True, 't': (str,int,float,bool), 'd': "" },
'valueChoices': { 'v': 1, 'r': False, 't': list },
'extensions': { 'v': 2, 'r': False, 't': list },
Expand All @@ -90,19 +100,48 @@
}
""" [Action Data structure](https://www.touch-portal.com/api/index.php?section=action-data) """

TPSDK_ATTRIBS_ACTION = {
TPSDK_ATTRIBS_LINEACT_SUGGESTION = {
# key name sdk V required [type(s)] [default value] [valid value list]
'firstLineItemLabelWidth': { 'v': 7, 'r': False, 't': int },
'lineIndentation': { 'v': 7, 'r': False, 't': int },
}
""" [Line Action Suggestion structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_actions) """

TPSDK_ATTRIBS_LINE_OBJ = {
# key name sdk V required [type(s)] [default value] [valid value list] [lookup table]
'language': { 'v': 7, 'r': True, 't': str, 'd': "default" },
'data': { 'v': 7, 'r': True, 't': list, 'l': TPSDK_ATTRIBS_ACT_DATA },
'suggestions': { 'v': 7, 'r': False, 't': dict, 'l': TPSDK_ATTRIBS_LINEACT_SUGGESTION },
}
""" [Line Action structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_actions) """

TPSDK_ATTRIBS_LINE = {
# key name sdk V required [type(s)] [default value] [valid value list] [lookup table]
'action': { 'v': 7, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_LINE_OBJ },
'onHold': { 'v': 7, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_LINE_OBJ },
}
""" [Line structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_actions) """

TPSDK_ATTRIBS_ACTION = {
# key name sdk V required [type(s)] [default value] [valid value list] [lookup table] [Deprecate version(DV)]
'id': { 'v': 1, 'r': True, 't': str },
'name': { 'v': 1, 'r': True, 't': str },
'prefix': { 'v': 1, 'r': True, 't': str }, # dynamic default? based on category name?
'name_nl': { 'v': 7, 'r': False, 't': str },
'name_de': { 'v': 7, 'r': False, 't': str },
'name_es': { 'v': 7, 'r': False, 't': str },
'name_fr': { 'v': 7, 'r': False, 't': str },
'name_pt': { 'v': 7, 'r': False, 't': str },
'name_tr': { 'v': 7, 'r': False, 't': str },
'prefix': { 'v': 1, 'r': True, 't': str, 'DV': 7}, # dynamic default? based on category name? # DEPRECATED V7
'type': { 'v': 1, 'r': True, 't': str, 'd': "communicate", 'c': ["communicate","execute"] },
'description': { 'v': 1, 'r': False, 't': str },
'format': { 'v': 1, 'r': False, 't': str },
'description': { 'v': 1, 'r': False, 't': str, 'DV': 7 }, # DEPRECATED V7
'format': { 'v': 1, 'r': False, 't': str, 'DV': 7 }, # DEPRECATED V7
'executionType': { 'v': 1, 'r': False, 't': str },
'execution_cmd': { 'v': 1, 'r': False, 't': str },
'tryInline': { 'v': 1, 'r': False, 't': bool },
'hasHoldFunctionality': { 'v': 3, 'r': False, 't': bool },
'tryInline': { 'v': 1, 'r': False, 't': bool, 'DV': 7 }, # DEPRECATED V7
'hasHoldFunctionality': { 'v': 3, 'r': False, 't': bool, 'DV': 7 }, # DEPRECATED V7
'data': { 'v': 1, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_ACT_DATA },
'lines': { 'v': 7, 'r': True, 't': dict, 'l': TPSDK_ATTRIBS_LINE },
}
""" [Dynamic Action structure](https://www.touch-portal.com/api/index.php?section=dynamic-actions) """

Expand All @@ -115,25 +154,43 @@
}
""" [Connector structure](https://www.touch-portal.com/api/index.php?section=connectors) """

TPSDK_ATTRIBS_SUBCATEGORIES = {
# key name sdk V required [type(s)] [default value] [valid value list]
'id': { 'v': 7, 'r': True, 't': str },
'name': { 'v': 7, 'r': True, 't': str },
'iconRelativePath': { 'v': 7, 'r': False, 't': str },
}
""" [Subcategory structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_subcategories) """

TPSDK_ATTRIBS_CATEGORY = {
# key name sdk V required [type(s)] [lookup table]
'id': { 'v': 1, 'r': True, 't': str }, # dynamic default id based on plugin id?
'name': { 'v': 1, 'r': True, 't': str }, # dynamic default based on plugin name?
'imagepath': { 'v': 1, 'r': False, 't': str },
'subCategories': { 'v': 7, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_SUBCATEGORIES },
'actions': { 'v': 1, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_ACTION },
'connectors': { 'v': 4, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_CONNECTOR },
'states': { 'v': 1, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_STATE },
'events': { 'v': 1, 'r': False, 't': list, 'l': TPSDK_ATTRIBS_EVENT },
}
""" [Category structure](https://www.touch-portal.com/api/index.php?section=categories) """

TPSDK_ATTRIBS_CONFIGURATION = {
# key name sdk V required [type(s)] [default value] [valid value list]
'colorDark': { 'v': 1, 'r': False, 't': str },
'colorLight': { 'v': 1, 'r': False, 't': str },
'parentCategory': { 'v': 7, 'r': False, 't': str, 'd': "misc", 'c': ["audio", "streaming", "content", "homeautomation", "social", "games", "misc"] },
}
""" [Configuration structure](https://www.touch-portal.com/api/v2/index.php?section=description_file_structure) """

TPSDK_ATTRIBS_ROOT = {
# key name sdk V required [type(s)] [default value] [valid value list] [lookup table]
'sdk': { 'v': 1, 'r': True, 't': int, 'd': TPSDK_DEFAULT_VERSION, 'c': [1,2,3,4,5,6] },
# key name sdk V required [type(s)] [default value] [valid value list] [lookup table] [Deprecate version(DV)]
'sdk': { 'v': 1, 'r': True, 't': int, 'd': TPSDK_DEFAULT_VERSION, 'c': [1,2,3,4,5,6], "DV": 7 },
'api': { 'v': 7, 'r': True, 't': int, 'd': TPSDK_DEFAULT_VERSION, 'c': [1,2,3,4,5,6,7,8,9,10]},
'version': { 'v': 1, 'r': True, 't': int, 'd': 1 },
'name': { 'v': 1, 'r': True, 't': str },
'id': { 'v': 1, 'r': True, 't': str },
'configuration': { 'v': 1, 'r': False, 't': dict },
'configuration': { 'v': 1, 'r': False, 't': dict, 'l': TPSDK_ATTRIBS_CONFIGURATION },
'plugin_start_cmd': { 'v': 1, 'r': False, 't': str },
'plugin_start_cmd_windows': { 'v': 4, 'r': False, 't': str },
'plugin_start_cmd_linux': { 'v': 4, 'r': False, 't': str },
Expand Down
Loading
Loading