python-openhab-rest-client 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. openhab/Actions.py +43 -0
  2. openhab/Addons.py +163 -0
  3. openhab/Audio.py +66 -0
  4. openhab/Auth.py +105 -0
  5. openhab/ChannelTypes.py +54 -0
  6. openhab/Client.py +197 -0
  7. openhab/ConfigDescriptions.py +44 -0
  8. openhab/Discovery.py +28 -0
  9. openhab/Events.py +302 -0
  10. openhab/Iconsets.py +21 -0
  11. openhab/Inbox.py +64 -0
  12. openhab/Items.py +264 -0
  13. openhab/Links.py +98 -0
  14. openhab/Logging.py +55 -0
  15. openhab/ModuleTypes.py +47 -0
  16. openhab/Persistence.py +103 -0
  17. openhab/ProfileTypes.py +32 -0
  18. openhab/Rules.py +206 -0
  19. openhab/Services.py +78 -0
  20. openhab/Sitemaps.py +88 -0
  21. openhab/Systeminfo.py +34 -0
  22. openhab/Tags.py +82 -0
  23. openhab/Templates.py +38 -0
  24. openhab/ThingTypes.py +42 -0
  25. openhab/Things.py +199 -0
  26. openhab/Transformations.py +58 -0
  27. openhab/UI.py +75 -0
  28. openhab/UUID.py +18 -0
  29. openhab/Voice.py +147 -0
  30. openhab/__init__.py +66 -0
  31. python_openhab_rest_client-0.1.0.dist-info/LICENSE +21 -0
  32. python_openhab_rest_client-0.1.0.dist-info/METADATA +2391 -0
  33. python_openhab_rest_client-0.1.0.dist-info/RECORD +70 -0
  34. python_openhab_rest_client-0.1.0.dist-info/WHEEL +5 -0
  35. python_openhab_rest_client-0.1.0.dist-info/top_level.txt +2 -0
  36. tests/__init__.py +0 -0
  37. tests/actions.py +55 -0
  38. tests/addons.py +96 -0
  39. tests/audio.py +16 -0
  40. tests/auth.py +45 -0
  41. tests/channel_events.py +14 -0
  42. tests/channel_types.py +29 -0
  43. tests/config_descriptions.py +23 -0
  44. tests/discovery.py +23 -0
  45. tests/events.py +41 -0
  46. tests/iconsets.py +19 -0
  47. tests/inbox.py +53 -0
  48. tests/inbox_events.py +15 -0
  49. tests/item_events.py +38 -0
  50. tests/items.py +120 -0
  51. tests/link_events.py +14 -0
  52. tests/links.py +74 -0
  53. tests/logging_test.py +43 -0
  54. tests/module_types.py +14 -0
  55. tests/persistence.py +78 -0
  56. tests/profile_types.py +13 -0
  57. tests/rules.py +151 -0
  58. tests/services.py +52 -0
  59. tests/sitemaps.py +65 -0
  60. tests/systeminfo.py +14 -0
  61. tests/tags.py +53 -0
  62. tests/templates.py +28 -0
  63. tests/test.py +11 -0
  64. tests/thing_events.py +17 -0
  65. tests/thing_types.py +28 -0
  66. tests/things.py +75 -0
  67. tests/transformations.py +38 -0
  68. tests/ui.py +70 -0
  69. tests/uuid.py +18 -0
  70. tests/voice.py +119 -0
openhab/Links.py ADDED
@@ -0,0 +1,98 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+ from urllib.parse import quote
4
+
5
+ class Links:
6
+ def __init__(self, client: OpenHABClient):
7
+ """
8
+ Initializes the Links class with an OpenHABClient object.
9
+
10
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
11
+ """
12
+ self.client = client
13
+
14
+ def getAllLinks(self, channelUID: str = None, itemName: str = None) -> list:
15
+ """
16
+ Gets all available links.
17
+
18
+ :param channelUID: Optional; Filters by the Channel UID.
19
+ :param itemName: Optional; Filters by the Item Name.
20
+
21
+ :return: A list of links containing details such as ItemName, ChannelUID, and configuration.
22
+ """
23
+ params = {}
24
+ if channelUID:
25
+ params["channelUID"] = channelUID
26
+ if itemName:
27
+ params["itemName"] = itemName
28
+
29
+ return self.client.get("/links", params=params, header={"Content-Type": "application/json"})
30
+
31
+ def getIndividualLink(self, itemName: str, channelUID: str) -> dict:
32
+ """
33
+ Retrieves an individual link.
34
+
35
+ :param itemName: The name of the item.
36
+ :param channelUID: The UID of the channel.
37
+
38
+ :return: The link with details of the item, channel UID, and configuration.
39
+ """
40
+ itemName = quote(itemName, safe="")
41
+ channelUID = quote(channelUID, safe="")
42
+
43
+ return self.client.get(f"/links/{itemName}/{channelUID}", header={"Accept": "application/json"})
44
+
45
+ def linkItemToChannel(self, itemName: str, channelUID: str, configuration: dict) -> dict:
46
+ """
47
+ Links an item to a channel.
48
+
49
+ :param itemName: The name of the item.
50
+ :param channelUID: The UID of the channel.
51
+ :param configuration: The configuration for the link.
52
+
53
+ :return: The API response when the link is successfully created.
54
+ """
55
+ itemName = quote(itemName, safe="")
56
+ channelUID = quote(channelUID, safe="")
57
+
58
+ return self.client.put(f"/links/{itemName}/{channelUID}", data=json.dumps({"itemName": itemName, "channelUID": channelUID, "configuration": configuration}), header={"Content-Type": "application/json"})
59
+
60
+ def unlinkItemFromChannel(self, itemName: str, channelUID: str) -> dict:
61
+ """
62
+ Unlinks an item from a channel.
63
+
64
+ :param itemName: The name of the item.
65
+ :param channelUID: The UID of the channel.
66
+
67
+ :return: The API response when the link is successfully removed.
68
+ """
69
+ itemName = quote(itemName, safe="")
70
+ channelUID = quote(channelUID, safe="")
71
+
72
+ return self.client.delete(f"/links/{itemName}/{channelUID}", header={"Content-Type": "application/json"})
73
+
74
+ def deleteAllLinks(self, object: str) -> dict:
75
+ """
76
+ Delete all links that refer to an item or thing.
77
+
78
+ :param object: The name of the item or the UID of the thing.
79
+
80
+ :return: The API response when all links are successfully deleted.
81
+ """
82
+ return self.client.delete(f"/links/{object}")
83
+
84
+ def getOrphanLinks(self) -> list:
85
+ """
86
+ Get orphan links between items and broken/non-existent thing channels.
87
+
88
+ :return: A list of orphan links.
89
+ """
90
+ return self.client.get("/links/orphans", header={"Accept": "application/json"})
91
+
92
+ def purgeUnusedLinks(self) -> dict:
93
+ """
94
+ Remove unused/orphaned links.
95
+
96
+ :return: The API response when the links are successfully removed.
97
+ """
98
+ return self.client.post("/links/purge")
openhab/Logging.py ADDED
@@ -0,0 +1,55 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+
4
+ class Logging:
5
+ def __init__(self, client: OpenHABClient):
6
+ """
7
+ Initializes the Logging class with an OpenHABClient object.
8
+
9
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
10
+ """
11
+ self.client = client
12
+
13
+ def getAllLoggers(self) -> dict:
14
+ """
15
+ Get all loggers.
16
+
17
+ :return: A list of loggers with names and levels.
18
+ """
19
+ return self.client.get("/logging")
20
+
21
+ def getSingleLogger(self, loggerName: str) -> dict:
22
+ """
23
+ Get a single logger.
24
+
25
+ :param loggerName: The name of the logger.
26
+
27
+ :return: The logger with the specified name and level.
28
+ """
29
+ return self.client.get(f"/logging/{loggerName}")
30
+
31
+ def modifyOrAddLogger(self, loggerName: str, level: str) -> dict:
32
+ """
33
+ Modify or add a logger.
34
+
35
+ :param loggerName: The name of the logger.
36
+ :param level: The level of the logger.
37
+
38
+ :return: The API response after modification or addition.
39
+ """
40
+ data = {
41
+ "loggerName": loggerName,
42
+ "level": level
43
+ }
44
+
45
+ return self.client.put(f"/logging/{loggerName}", data=json.dumps(data), header={"Content-Type": "application/json"})
46
+
47
+ def removeLogger(self, loggerName: str) -> dict:
48
+ """
49
+ Remove a single logger.
50
+
51
+ :param loggerName: The name of the logger.
52
+
53
+ :return: The API response after removing the logger.
54
+ """
55
+ return self.client.delete(f"/logging/{loggerName}")
openhab/ModuleTypes.py ADDED
@@ -0,0 +1,47 @@
1
+ from .Client import OpenHABClient
2
+
3
+ class ModuleTypes:
4
+ def __init__(self, client: OpenHABClient):
5
+ """
6
+ Initializes the ModuleTypes class with an OpenHABClient object.
7
+
8
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
9
+ """
10
+ self.client = client
11
+
12
+ def getModuleTypes(self, tags=None, typeFilter=None, language: str = None):
13
+ """
14
+ Get all available module types.
15
+
16
+ :param tags: Optional filter for tags.
17
+ :param typeFilter: Optional filter for the type (action, condition, trigger).
18
+ :param language: (Optional) Language setting for the Accept-Language header.
19
+
20
+ :return: A list of module types.
21
+ """
22
+ header = {"Content-Type": "application/json"}
23
+ if language:
24
+ header["Accept-Language"] = language
25
+
26
+ params = {}
27
+ if tags:
28
+ params["tags"] = tags
29
+ if typeFilter:
30
+ params["type"] = typeFilter
31
+
32
+ return self.client.get("/module-types", params=params, header=header)
33
+
34
+ def getModuleType(self, moduleTypeUID, language: str = None):
35
+ """
36
+ Gets a module type corresponding to the given UID.
37
+
38
+ :param moduleTypeUID: The UID of the module type.
39
+ :param language: (Optional) Language setting for the Accept-Language header.
40
+
41
+ :return: A dictionary with the module type information.
42
+ """
43
+ header = {"Content-Type": "application/json"}
44
+ if language:
45
+ header["Accept-Language"] = language
46
+
47
+ return self.client.get(f"/module-types/{moduleTypeUID}", header=header)
openhab/Persistence.py ADDED
@@ -0,0 +1,103 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+
4
+ class Persistence:
5
+ def __init__(self, client: OpenHABClient):
6
+ """
7
+ Initializes the Persistence class with an OpenHABClient object.
8
+
9
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
10
+ """
11
+ self.client = client
12
+
13
+ def getAllServices(self) -> dict:
14
+ """
15
+ Gets a list of persistence services.
16
+
17
+ :return: A list of persistence services with IDs, labels, and types.
18
+ """
19
+ return self.client.get("/persistence")
20
+
21
+ def getServiceConfiguration(self, serviceId: str) -> dict:
22
+ """
23
+ Gets a persistence service configuration.
24
+
25
+ :param serviceId: The ID of the persistence service.
26
+
27
+ :return: The configuration of the service.
28
+ """
29
+ return self.client.get(f"/persistence/{serviceId}")
30
+
31
+ def setServiceConfiguration(self, serviceId: str, config: dict) -> dict:
32
+ """
33
+ Sets a persistence service configuration.
34
+
35
+ :param serviceId: The ID of the persistence service.
36
+ :param config: The configuration data.
37
+
38
+ :return: The response from the API after modification.
39
+ """
40
+ return self.client.put(f"/persistence/{serviceId}", data=json.dumps({'serviceId': serviceId}), header={"Content-Type": "application/json", "Accept": "application/json"})
41
+
42
+ def deleteServiceConfiguration(self, serviceId: str) -> dict:
43
+ """
44
+ Deletes a persistence service configuration.
45
+
46
+ :param serviceId: The ID of the persistence service.
47
+
48
+ :return: The response from the API after deleting the configuration.
49
+ """
50
+ return self.client.delete(f"/persistence/{serviceId}")
51
+
52
+ def getItemsForService(self, serviceId: str) -> dict:
53
+ """
54
+ Gets a list of items available via a specific persistence service.
55
+
56
+ :param serviceId: The ID of the persistence service.
57
+
58
+ :return: A list of items with their last and earliest timestamps.
59
+ """
60
+
61
+ return self.client.get(f"/persistence/items?serviceId={serviceId}")
62
+
63
+ def getItemPersistenceData(self, serviceId: str, itemName: str, startTime: str = None, endTime: str = None, page: int = 1, pageLength: int = 50) -> dict:
64
+ """
65
+ Gets item persistence data from the persistence service.
66
+
67
+ :param serviceId: The ID of the persistence service.
68
+ :param itemName: The name of the item.
69
+ :param startTime: The start time for the data. Defaults to 1 day before `endTime`.
70
+ :param endTime: The end time for the data. Defaults to the current time.
71
+ :param page: The page of data. Defaults to `1`.
72
+ :param pageLength: The number of data points per page. Defaults to `50`.
73
+
74
+ :return: The retrieved data points of the item.
75
+ """
76
+ return self.client.get(f"/persistence/items/{itemName}", params={"serviceId": serviceId, "starttime": startTime, "endtime": endTime, "page": page, "pagelength": pageLength})
77
+
78
+ def storeItemData(self, serviceId: str, itemName: str, time: str, state: str) -> dict:
79
+ """
80
+ Stores item persistence data into the persistence service.
81
+
82
+ :param serviceId: The ID of the persistence service.
83
+ :param itemName: The name of the item.
84
+ :param time: The time of the storage.
85
+ :param state: The state of the item to be stored.
86
+
87
+ :return: The response from the API after storing the data.
88
+ """
89
+ return self.client.put(f"/persistence/items/{itemName}", params={"serviceId": serviceId, "time": time, "state": state})
90
+
91
+ def deleteItemData(self, serviceId: str, itemName: str, startTime: str, endTime: str) -> dict:
92
+ """
93
+ Deletes item persistence data from a specific persistence service in a given time range.
94
+
95
+ :param serviceId: The ID of the persistence service.
96
+ :param itemName: The name of the item.
97
+ :param startTime: The start time of the data to be deleted.
98
+ :param endTime: The end time of the data to be deleted.
99
+
100
+ :return: The response from the API after deleting the data.
101
+ """
102
+
103
+ return self.client.delete(f"/persistence/items/{itemName}", params={"serviceId": serviceId, "starttime": startTime, "endtime": endTime})
@@ -0,0 +1,32 @@
1
+ from .Client import OpenHABClient
2
+
3
+ class ProfileTypes:
4
+ def __init__(self, client: OpenHABClient):
5
+ """
6
+ Initializes the ProfileTypes class with an OpenHABClient object.
7
+
8
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
9
+ """
10
+ self.client = client
11
+
12
+ def getProfileTypes(self, channelTypeUID=None, itemType=None, language: str = None):
13
+ """
14
+ Gets all available profile types.
15
+
16
+ :param channelTypeUID: Optional filter for the channel type.
17
+ :param itemType: Optional filter for the item type.
18
+ :param language: (Optional) Language setting for the Accept-Language header.
19
+
20
+ :return: A list of profile types.
21
+ """
22
+ header = {"Content-Type": "application/json"}
23
+ if language:
24
+ header["Accept-Language"] = language
25
+
26
+ params = {}
27
+ if channelTypeUID:
28
+ params["channelTypeUID"] = channelTypeUID
29
+ if itemType:
30
+ params["itemType"] = itemType
31
+
32
+ return self.client.get("/profile-types", params=params, header=header)
openhab/Rules.py ADDED
@@ -0,0 +1,206 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+
4
+ class Rules:
5
+ def __init__(self, client: OpenHABClient):
6
+ """
7
+ Initializes the Rules class with an OpenHABClient object.
8
+
9
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
10
+ """
11
+ self.client = client
12
+
13
+ def getRules(self, prefix=None, tags=None, summary=False, staticDataOnly=False):
14
+ """
15
+ Get available rules, optionally filtered by tags and/or prefix.
16
+
17
+ :param prefix: Optional prefix to filter the results.
18
+ :param tags: Optional tag array to filter the results.
19
+ :param summary: If true, only summary fields will be returned.
20
+ :param staticDataOnly: If true, only static data will be returned.
21
+
22
+ :return: A list of rules (JSON objects).
23
+ """
24
+ return self.client.get("/rules", params={"prefix": prefix, "tags": tags, "summary": summary, "staticDataOnly": staticDataOnly})
25
+
26
+ def createRule(self, ruleData: dict):
27
+ """
28
+ Creates a rule.
29
+
30
+ :param ruleData: The rule data to be created (as a dictionary).
31
+
32
+ :return: The created rule (JSON).
33
+ """
34
+ return self.client.post("/rules", data=json.dumps(ruleData), header={"Content-Type": "application/json"})
35
+
36
+ def getRule(self, ruleUID: str):
37
+ """
38
+ Gets the rule corresponding to the given UID.
39
+
40
+ :param ruleUID: The UID of the rule to retrieve.
41
+
42
+ :return: The rule object (JSON).
43
+ """
44
+ return self.client.get(f"/rules/{ruleUID}")
45
+
46
+ def updateRule(self, ruleUID: str, ruleData: dict):
47
+ """
48
+ Updates an existing rule corresponding to the given UID.
49
+
50
+ :param ruleUID: The UID of the rule to update.
51
+ :param ruleData: The new rule data (as a dictionary).
52
+
53
+ :return: The updated rule (JSON).
54
+ """
55
+ return self.client.put(f"/rules/{ruleUID}", data=json.dumps(ruleData), header={"Content-Type": "application/json"})
56
+
57
+ def deleteRule(self, ruleUID: str):
58
+ """
59
+ Removes an existing rule corresponding to the given UID.
60
+
61
+ :param ruleUID: The UID of the rule to delete.
62
+
63
+ :return: The API response (status code).
64
+ """
65
+ return self.client.delete(f"/rules/{ruleUID}", header={"Accept": "application/json"})
66
+
67
+ def getModule(self, ruleUID: str, moduleCategory: str, moduleId: str):
68
+ """
69
+ Gets the rule's module corresponding to the given category and ID.
70
+
71
+ :param ruleUID: The UID of the rule.
72
+ :param moduleCategory: The category of the module.
73
+ :param moduleId: The ID of the module.
74
+
75
+ :return: The module (JSON).
76
+ """
77
+ return self.client.get(f"/rules/{ruleUID}/{moduleCategory}/{moduleId}", header={"Accept": "application/json"})
78
+
79
+ def getModuleConfig(self, ruleUID: str, moduleCategory: str, moduleId: str):
80
+ """
81
+ Gets the module's configuration.
82
+
83
+ :param ruleUID: The UID of the rule.
84
+ :param moduleCategory: The category of the module.
85
+ :param moduleId: The ID of the module.
86
+
87
+ :return: The module configuration (JSON).
88
+ """
89
+ return self.client.get(f"/rules/{ruleUID}/{moduleCategory}/{moduleId}/config")
90
+
91
+ def getModuleConfigParam(self, ruleUID: str, moduleCategory: str, moduleId: str, param: str):
92
+ """
93
+ Gets the module's configuration parameter.
94
+
95
+ :param ruleUID: The UID of the rule.
96
+ :param moduleCategory: The category of the module.
97
+ :param moduleId: The ID of the module.
98
+ :param param: The name of the configuration parameter.
99
+
100
+ :return: The configuration parameter value (JSON).
101
+ """
102
+ return self.client.get(f"/rules/{ruleUID}/{moduleCategory}/{moduleId}/config/{param}", header={'Accept': 'text/plain'})
103
+
104
+ def setModuleConfigParam(self, ruleUID: str, moduleCategory: str, moduleId: str, param: str, value: str):
105
+ """
106
+ Sets the module's configuration parameter value.
107
+
108
+ :param ruleUID: The UID of the rule.
109
+ :param moduleCategory: The category of the module.
110
+ :param moduleId: The ID of the module.
111
+ :param param: The name of the configuration parameter.
112
+ :param value: The value to set for the configuration parameter.
113
+
114
+ :return: The API response (status code).
115
+ """
116
+ return self.client.put(f"/rules/{ruleUID}/{moduleCategory}/{moduleId}/config/{param}", data=json.dumps(value), header={'Content-Type': 'text/plain'})
117
+
118
+ def getActions(self, ruleUID: str):
119
+ """
120
+ Gets the rule actions.
121
+
122
+ :param ruleUID: The UID of the rule.
123
+
124
+ :return: A list of actions (JSON).
125
+ """
126
+ return self.client.get(f"/rules/{ruleUID}/actions")
127
+
128
+ def getConditions(self, ruleUID: str):
129
+ """
130
+ Gets the rule conditions.
131
+
132
+ :param ruleUID: The UID of the rule.
133
+
134
+ :return: A list of conditions (JSON).
135
+ """
136
+ return self.client.get(f"/rules/{ruleUID}/conditions")
137
+
138
+ def getConfiguration(self, ruleUID: str):
139
+ """
140
+ Gets the rule configuration values.
141
+
142
+ :param ruleUID: The UID of the rule.
143
+
144
+ :return: The configuration of the rule (JSON).
145
+ """
146
+ return self.client.get(f"/rules/{ruleUID}/config")
147
+
148
+ def updateConfiguration(self, ruleUID: str, configData: dict):
149
+ """
150
+ Sets the rule configuration values.
151
+
152
+ :param ruleUID: The UID of the rule.
153
+ :param configData: The new configuration data (as a dictionary).
154
+
155
+ :return: The updated configuration (JSON).
156
+ """
157
+ return self.client.put(f"/rules/{ruleUID}/config", data=json.dumps(configData), header={"Content-Type": "application/json"})
158
+
159
+ def setRuleState(self, ruleUID: str, enable: bool):
160
+ """
161
+ Sets the rule configuration values. Activates or deactivates the rule.
162
+
163
+ :param ruleUID: The UID of the rule.
164
+ :param enable: If true, the rule will be activated. If false, the rule will be deactivated.
165
+
166
+ :return: The API response (status code).
167
+ """
168
+ return self.client.post(f"/rules/{ruleUID}/enable", data="true" if enable else "false", header={"Content-type": "text/plain; charset=utf-8", "Accept": "text/plain"})
169
+
170
+ def enableRule(self, ruleUID: str):
171
+ return self.setRuleState(ruleUID, True)
172
+
173
+ def disableRule(self, ruleUID: str):
174
+ return self.setRuleState(ruleUID, False)
175
+
176
+ def runNow(self, ruleUID: str, contextData: dict = None):
177
+ """
178
+ Executes the rule's actions immediately.
179
+
180
+ :param ruleUID: The UID of the rule.
181
+ :param contextData: Optional context data for executing the rule.
182
+
183
+ :return: The API response (status code).
184
+ """
185
+ return self.client.post(f"/rules/{ruleUID}/runnow", data=json.dumps(contextData) or {})
186
+
187
+ def getTriggers(self, ruleUID: str):
188
+ """
189
+ Gets the rule triggers.
190
+
191
+ :param ruleUID: The UID of the rule.
192
+
193
+ :return: A list of triggers (JSON).
194
+ """
195
+ return self.client.get(f"/rules/{ruleUID}/triggers")
196
+
197
+ def simulateSchedule(self, fromTime: str, untilTime: str):
198
+ """
199
+ Simulates the executions of rules filtered by tag 'Schedule' within the given times.
200
+
201
+ :param fromTime: Simulates the executions of rules filtered by tag 'Schedule' within the given times.
202
+ :param untilTime: Simulates the executions of rules filtered by tag 'Schedule' within the given times.
203
+
204
+ :return: The simulation results (JSON).
205
+ """
206
+ return self.client.get("/rules/schedule/simulations", params={"from": fromTime, "until": untilTime}, header={'Accept': 'application/json'})
openhab/Services.py ADDED
@@ -0,0 +1,78 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+
4
+ class Services:
5
+ def __init__(self, client: OpenHABClient):
6
+ """
7
+ Initializes the Services class with an OpenHABClient object.
8
+
9
+ :param client: An instance of OpenHABClient that is used for REST-API communication.
10
+ """
11
+ self.client = client
12
+
13
+ def getServices(self, language=None):
14
+ """
15
+ Get all configurable services.
16
+
17
+ :param language: Optional language setting (as header).
18
+
19
+ :return: A list of services (JSON).
20
+ """
21
+ return self.client.get("/services", header={"Accept-Language": language} if language else {})
22
+
23
+ def getService(self, serviceID: str, language=None):
24
+ """
25
+ Get configurable service for the given service ID.
26
+
27
+ :param serviceID: The ID of the service to retrieve.
28
+ :param language: Optional language setting (as header).
29
+
30
+ :return: The service object (JSON).
31
+ """
32
+ return self.client.get(f"/services/{serviceID}", header={"Accept-Language": language} if language else {})
33
+
34
+ def getServiceConfig(self, serviceID: str):
35
+ """
36
+ Get service configuration for the given service ID.
37
+
38
+ :param serviceID: The ID of the service.
39
+
40
+ :return: The configuration of the service (JSON).
41
+ """
42
+ return self.client.get(f"/services/{serviceID}/config")
43
+
44
+ def updateServiceConfig(self, serviceID: str, configData: dict):
45
+ """
46
+ Updates a service configuration for the given service ID and returns the old configuration.
47
+
48
+ :param serviceID: The ID of the service.
49
+ :param configData: The new configuration data (as a dictionary).
50
+
51
+ :return: The old configuration of the service (JSON).
52
+ """
53
+ return self.client.put(f"/services/{serviceID}/config", data=json.dumps(configData), header={"Content-type": "application/json", "Accept": "application/json"})
54
+
55
+ def deleteServiceConfig(self, serviceID: str):
56
+ """
57
+ Deletes a service configuration for the given service ID and returns the old configuration.
58
+
59
+ :param serviceID: The ID of the service.
60
+
61
+ :return: The old configuration of the service (JSON).
62
+ """
63
+ return self.client.delete(f"/services/{serviceID}/config", header={"Accept": "application/json"})
64
+
65
+ def getServiceContexts(self, serviceID: str, language=None):
66
+ """
67
+ Get existing multiple context service configurations for the given factory PID.
68
+
69
+ :param serviceID: The ID of the service.
70
+ :param language: Optional language setting (as header).
71
+
72
+ :return: A list of contexts (JSON).
73
+ """
74
+ header = {"Accept": "application/json"} # Default to application/json
75
+ if language:
76
+ header["Accept-Language"] = language
77
+
78
+ return self.client.get(f"/services/{serviceID}/contexts", header=header)