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/Actions.py ADDED
@@ -0,0 +1,43 @@
1
+ from .Client import OpenHABClient
2
+ import json
3
+
4
+ class Actions:
5
+ def __init__(self, client: OpenHABClient):
6
+ """
7
+ Initializes the Actions 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 getAllActions(self, thingUID: str, language: str = None) -> list:
14
+ """
15
+ Get all available actions for provided thing UID.
16
+
17
+ :param thingUID: The UID of the thing for which actions are to be retrieved.
18
+ :param language: (Optional) Language setting for the Accept-Language header.
19
+
20
+ :return: A list of actions.
21
+ """
22
+ header = {"Content-Type": "application/json"}
23
+ if language:
24
+ header["Accept-Language"] = language
25
+
26
+ return self.client.get(f"/actions/{thingUID}", header=header)
27
+
28
+ def executeAction(self, thingUID: str, actionUID: str, actionInputs: dict, language: str = None) -> str:
29
+ """
30
+ Executes a thing action.
31
+
32
+ :param thingUID: The UID of the thing on which the action is to be executed.
33
+ :param actionUID: The UID of the action to be executed.
34
+ :param actionInputs: The inputs for the action as a dictionary.
35
+ :param language: (Optional) Language setting for the Accept-Language header.
36
+
37
+ :return: A response from the server.
38
+ """
39
+ header = {"Content-Type": "application/json"}
40
+ if language:
41
+ header["Accept-Language"] = language
42
+
43
+ return self.client.post(f"/actions/{thingUID}/{actionUID}", header=header, data=json.dumps(actionInputs))
openhab/Addons.py ADDED
@@ -0,0 +1,163 @@
1
+ import json
2
+ from .Client import OpenHABClient
3
+ import urllib.parse
4
+
5
+ class Addons:
6
+ def __init__(self, client: OpenHABClient):
7
+ """
8
+ Initializes the Addons class with an OpenHABClient instance.
9
+
10
+ :param client: An instance of OpenHABClient used for REST API communication.
11
+ """
12
+ self.client = client
13
+
14
+ def getAddons(self, serviceID: str = None, language: str = None) -> dict:
15
+ """
16
+ Retrieves a list of all available add-ons.
17
+
18
+ :param serviceID: Optional service ID to filter the results.
19
+ :param language: Optional language preference for the response.
20
+
21
+ :return: A dictionary containing the add-ons data.
22
+ """
23
+ params = {"serviceId": serviceID} if serviceID else {}
24
+ header = {"Content-Type": "application/json"}
25
+ if language:
26
+ header["Accept-Language"] = language
27
+
28
+ return self.client.get("/addons", header=header, params=params)
29
+
30
+ def getAddon(self, addonID: str, serviceID: str = None, language: str = None) -> dict:
31
+ """
32
+ Retrieves details of a specific add-on by its ID.
33
+
34
+ :param addonID: The unique identifier of the add-on.
35
+ :param serviceID: Optional service ID to filter the results.
36
+ :param language: Optional language preference for the response.
37
+
38
+ :return: A dictionary containing details of the specified add-on.
39
+ """
40
+ params = {"serviceId": serviceID} if serviceID else {}
41
+ header = {"Content-Type": "application/json"}
42
+ if language:
43
+ header["Accept-Language"] = language
44
+
45
+ return self.client.get(f"/addons/{addonID}", header=header, params=params)
46
+
47
+ def getAddonConfig(self, addonID: str, serviceID: str = None) -> dict:
48
+ """
49
+ Retrieves the configuration of a specific add-on.
50
+
51
+ :param addonID: The unique identifier of the add-on.
52
+ :param serviceID: Optional service ID to filter the results.
53
+
54
+ :return: A dictionary containing the configuration of the specified add-on.
55
+ """
56
+ params = {"serviceId": serviceID} if serviceID else {}
57
+
58
+ return self.client.get(f"/addons/{addonID}/config", header={"Content-Type": "application/json"}, params=params)
59
+
60
+ def updateAddonConfig(self, addonID: str, configData: dict, serviceID: str = None) -> dict:
61
+ """
62
+ Updates the configuration of a specific add-on and returns the updated configuration.
63
+
64
+ :param addonID: The unique identifier of the add-on.
65
+ :param configData: A dictionary containing the new configuration settings.
66
+ :param serviceID: Optional service ID to specify the target service.
67
+
68
+ :return: A dictionary containing the updated configuration.
69
+ """
70
+ data = {**configData} # Create a copy to avoid modifying the original dictionary
71
+ if serviceID:
72
+ data["serviceId"] = serviceID
73
+
74
+ return self.client.put(f"/addons/{addonID}/config", header={"Content-Type": "application/json"}, data=json.dumps(data))
75
+
76
+ def installAddon(self, addonID: str, serviceID: str = None, language: str = None) -> dict:
77
+ """
78
+ Installs an add-on by its ID.
79
+
80
+ :param addonID: The unique identifier of the add-on.
81
+ :param serviceID: Optional service ID to specify the target service.
82
+ :param language: Optional language preference for the response.
83
+
84
+ :return: A dictionary containing the installation status.
85
+ """
86
+ data = {"serviceId": serviceID} if serviceID else {}
87
+ header = {"Content-Type": "application/json"}
88
+ if language:
89
+ header["Accept-Language"] = language
90
+
91
+ return self.client.post(f"/addons/{addonID}/install", header=header, data=data)
92
+
93
+ def uninstallAddon(self, addonID: str, serviceID: str = None, language: str = None) -> dict:
94
+ """
95
+ Uninstalls an add-on by its ID.
96
+
97
+ :param addonID: The unique identifier of the add-on.
98
+ :param serviceID: Optional service ID to specify the target service.
99
+ :param language: Optional language preference for the response.
100
+
101
+ :return: A dictionary containing the uninstallation status.
102
+ """
103
+ data = {"serviceId": serviceID} if serviceID else {}
104
+ header = {"Content-Type": "application/json"}
105
+ if language:
106
+ header["Accept-Language"] = language
107
+
108
+ return self.client.post(f"/addons/{addonID}/uninstall", header=header, data=data)
109
+
110
+ def getAddonServices(self, language: str = None) -> dict:
111
+ """
112
+ Retrieves a list of all available add-on services.
113
+
114
+ :param language: Optional language preference for the response.
115
+
116
+ :return: A dictionary containing the available add-on services.
117
+ """
118
+ header = {"Content-Type": "application/json"}
119
+ if language:
120
+ header["Accept-Language"] = language
121
+
122
+ return self.client.get("/addons/services", header=header, params=None)
123
+
124
+ def getAddonSuggestions(self, language: str = None) -> dict:
125
+ """
126
+ Retrieves a list of suggested add-ons for installation.
127
+
128
+ :param language: Optional language preference for the response.
129
+
130
+ :return: A dictionary containing suggested add-ons.
131
+ """
132
+ header = {"Content-Type": "application/json"}
133
+ if language:
134
+ header["Accept-Language"] = language
135
+
136
+ return self.client.get("/addons/suggestions", header=header, params=None)
137
+
138
+ def getAddonTypes(self, language: str = None) -> dict:
139
+ """
140
+ Retrieves a list of all available add-on types.
141
+
142
+ :param language: Optional language preference for the response.
143
+
144
+ :return: A dictionary containing available add-on types.
145
+ """
146
+ header = {"Content-Type": "application/json"}
147
+ if language:
148
+ header["Accept-Language"] = language
149
+
150
+ return self.client.get("/addons/types", header=header, params=None)
151
+
152
+ def installAddonFromUrl(self, url: str) -> dict:
153
+ """
154
+ Installs an add-on from a given URL.
155
+
156
+ :param url: The URL of the add-on to install.
157
+
158
+ :return: A dictionary containing the installation status.
159
+ """
160
+ encoded_url = urllib.parse.quote(url, safe='') # Encode the URL
161
+ endpoint = f"/addons/url/{encoded_url}/install"
162
+
163
+ return self.client.post(endpoint, header={"Content-Type": "text/plain"}, data=None)
openhab/Audio.py ADDED
@@ -0,0 +1,66 @@
1
+ from .Client import OpenHABClient
2
+
3
+ class Audio:
4
+ def __init__(self, client: OpenHABClient):
5
+ """
6
+ Initializes the Audio class with an OpenHABClient object.
7
+
8
+ :param client: An instance of OpenHABClient used for REST API communication.
9
+ """
10
+ self.client = client
11
+
12
+ def getDefaultSink(self, language: str = None):
13
+ """
14
+ Retrieves the default sink if defined, or the first available sink.
15
+
16
+ :param language: (Optional) Language setting for the Accept-Language header.
17
+
18
+ :return: A dictionary containing information about the default sink.
19
+ """
20
+ header = {"Content-Type": "application/json"}
21
+ if language:
22
+ header["Accept-Language"] = language
23
+
24
+ return self.client.get("/audio/defaultsink", header=header)
25
+
26
+ def getDefaultSource(self, language: str = None):
27
+ """
28
+ Retrieves the default source if defined, or the first available source.
29
+
30
+ :param language: (Optional) Language setting for the Accept-Language header.
31
+
32
+ :return: A dictionary containing information about the default source.
33
+ """
34
+ header = {"Content-Type": "application/json"}
35
+ if language:
36
+ header["Accept-Language"] = language
37
+
38
+ return self.client.get("/audio/defaultsource", header=header)
39
+
40
+ def getSinks(self, language: str = None):
41
+ """
42
+ Retrieves a list of all available sinks.
43
+
44
+ :param language: (Optional) Language setting for the Accept-Language header.
45
+
46
+ :return: A list of available sinks.
47
+ """
48
+ header = {"Content-Type": "application/json"}
49
+ if language:
50
+ header["Accept-Language"] = language
51
+
52
+ return self.client.get("/audio/sinks", header=header)
53
+
54
+ def getSources(self, language: str = None):
55
+ """
56
+ Retrieves a list of all available sources.
57
+
58
+ :param language: (Optional) Language setting for the Accept-Language header.
59
+
60
+ :return: A list of available sources.
61
+ """
62
+ header = {"Content-Type": "application/json"}
63
+ if language:
64
+ header["Accept-Language"] = language
65
+
66
+ return self.client.get("/audio/sources", header=header)
openhab/Auth.py ADDED
@@ -0,0 +1,105 @@
1
+ from urllib.parse import urlencode
2
+ from .Client import OpenHABClient
3
+ import json
4
+
5
+ class Auth:
6
+ def __init__(self, client: OpenHABClient):
7
+ """
8
+ Initializes the Auth class with an OpenHABClient instance.
9
+
10
+ :param client: An instance of OpenHABClient used for REST API communication.
11
+ """
12
+ self.client = client
13
+
14
+ def getApiTokens(self, language: str = None) -> dict:
15
+ """
16
+ Retrieve the API tokens associated with the authenticated user.
17
+
18
+ :param language: (Optional) Language setting for the API request.
19
+
20
+ :return: JSON response from the server.
21
+ """
22
+ header = {"Content-Type": "application/json"}
23
+ if language:
24
+ header["Accept-Language"] = language
25
+
26
+ return self.client.get("/auth/apitokens", header=header)
27
+
28
+ def revokeApiToken(self, tokenName: str, language: str = None) -> dict:
29
+ """
30
+ Revoke a specific API token associated with the authenticated user.
31
+
32
+ :param tokenName: Name of the API token to be revoked.
33
+ :param language: (Optional) Language setting for the API request.
34
+
35
+ :return: JSON response from the server.
36
+ """
37
+ header = {"Content-Type": "application/json"}
38
+ if language:
39
+ header["Accept-Language"] = language
40
+
41
+ return self.client.delete(f"/auth/apitokens/{tokenName}", header=header)
42
+
43
+ def logout(self, refreshToken: str, language: str = None) -> dict:
44
+ """
45
+ Terminate the session associated with a refresh token.
46
+
47
+ :param refreshToken: The refresh token used to delete the session.
48
+ :param language: (Optional) Language setting for the API request.
49
+
50
+ :return: JSON response from the server.
51
+ """
52
+ header = {"Content-Type": "application/x-www-form-urlencoded"}
53
+ if language:
54
+ header["Accept-Language"] = language
55
+
56
+ return self.client.post("/auth/logout", header=header, data=json.dumps({"refresh_token": refreshToken}))
57
+
58
+ def getSessions(self, language: str = None) -> dict:
59
+ """
60
+ Retrieve the sessions associated with the authenticated user.
61
+
62
+ :param language: (Optional) Language setting for the API request.
63
+
64
+ :return: JSON response from the server.
65
+ """
66
+ header = {"Content-Type": "application/json"}
67
+ if language:
68
+ header["Accept-Language"] = language
69
+
70
+ return self.client.get("/auth/sessions", header=header)
71
+
72
+ def getToken(self, grantType: str, code: str = None, redirectUri: str = None, clientID: str = None, refreshToken: str = None, codeVerifier: str = None, language: str = None) -> dict:
73
+ """
74
+ Obtain access and refresh tokens.
75
+
76
+ :param grantType: The type of grant being requested.
77
+ :param code: (Optional) Authorization code for authentication.
78
+ :param redirectUri: (Optional) Redirect URI for OAuth authentication.
79
+ :param clientID: (Optional) Client ID for authentication.
80
+ :param refreshToken: (Optional) Refresh token for token renewal.
81
+ :param codeVerifier: (Optional) Code verifier for PKCE authentication.
82
+ :param language: (Optional) Language setting for the API request.
83
+
84
+ :return: JSON response from the server.
85
+ """
86
+ header = {
87
+ "Content-Type": "application/x-www-form-urlencoded",
88
+ "Accept": "application/json"
89
+ }
90
+
91
+ body = {
92
+ "grant_type": grantType,
93
+ "code": code,
94
+ "redirect_uri": redirectUri,
95
+ "client_id": clientID,
96
+ "refresh_token": refreshToken,
97
+ "code_verifier": codeVerifier
98
+ }
99
+ # Remove all None values
100
+ body = {k: v for k, v in body.items() if v is not None}
101
+
102
+ # Encode as application/x-www-form-urlencoded
103
+ encodedBody = urlencode(body)
104
+
105
+ return self.client.post("/auth/token", header=header, data=encodedBody)
@@ -0,0 +1,54 @@
1
+ from .Client import OpenHABClient
2
+
3
+ class ChannelTypes:
4
+ def __init__(self, client: OpenHABClient):
5
+ """
6
+ Initializes the ChannelTypes class with an OpenHABClient instance.
7
+
8
+ :param client: An instance of OpenHABClient used for REST API communication.
9
+ """
10
+ self.client = client
11
+
12
+ def getAllChannelTypes(self, language: str = None, prefixes: str = None) -> list:
13
+ """
14
+ Retrieves all available channel types.
15
+
16
+ :param language: Optional header 'Accept-Language' to specify the preferred language.
17
+ :param prefixes: Optional query parameter to filter channel types by prefix.
18
+
19
+ :return: A list of channel types.
20
+ """
21
+ header = {}
22
+ if language:
23
+ header["Accept-Language"] = language
24
+
25
+ params = {}
26
+ if prefixes:
27
+ params["prefixes"] = prefixes
28
+
29
+ return self.client.get("/channel-types", header=header, params=params)
30
+
31
+ def getChannelTypeByUid(self, channelTypeUid: str, language: str = None) -> dict:
32
+ """
33
+ Retrieves the item types the given trigger channel type UID can be linked to.
34
+
35
+ :param channelTypeUid: The unique UID of the channel type.
36
+ :param language: Optional header 'Accept-Language' to specify the preferred language.
37
+
38
+ :return: Details of the specific channel type.
39
+ """
40
+ header = {}
41
+ if language:
42
+ header["Accept-Language"] = language
43
+
44
+ return self.client.get(f"/channel-types/{channelTypeUid}", header=header)
45
+
46
+ def getLinkableItemTypes(self, channelTypeUid: str) -> list:
47
+ """
48
+ Retrieves the item types that can be linked to the specified trigger channel type.
49
+
50
+ :param channelTypeUid: The unique UID of the channel type.
51
+
52
+ :return: A list of item types.
53
+ """
54
+ return self.client.get(f"/channel-types/{channelTypeUid}/linkableItemTypes")
openhab/Client.py ADDED
@@ -0,0 +1,197 @@
1
+ import requests
2
+ import json
3
+
4
+ class OpenHABClient:
5
+ def __init__(self, url: str, username: str = None, password: str = None, token: str = None):
6
+ """
7
+ Initializes the OpenHABClient instance.
8
+
9
+ :param url: The base URL of the OpenHAB server (e.g., "http://127.0.0.1:8080").
10
+ :param username: Optional; The username for Basic Authentication (default is None).
11
+ :param password: Optional; The password for Basic Authentication (default is None).
12
+ :param token: Optional; The Bearer Token for Token-based Authentication (default is None).
13
+ """
14
+ self.url = url.rstrip("/") # Remove trailing slash if present
15
+ self.username = username
16
+ self.password = password
17
+ self.token = token
18
+ self.isCloud = False
19
+ self.isLoggedIn = False
20
+
21
+ self.session = requests.Session()
22
+
23
+ if self.token:
24
+ # Use Token-based authentication
25
+ self.session.headers.update({
26
+ "Authorization": f"Bearer {self.token}",
27
+ "Content-Type": "application/json"
28
+ })
29
+ elif self.username and self.password:
30
+ # Use Basic Authentication
31
+ self.auth = (self.username, self.password)
32
+ self.session.auth = self.auth
33
+ else:
34
+ self.auth = None
35
+
36
+ self.__login()
37
+
38
+ def __login(self):
39
+ """
40
+ Attempts to log in to the openHAB server.
41
+
42
+ If the server is "myopenhab.org", it sets the connection to the cloud service.
43
+ Otherwise, it prepares a local connection and verifies login credentials.
44
+ """
45
+ if self.url == "https://myopenhab.org":
46
+ self.isCloud = True
47
+ else:
48
+ self.isCloud = False
49
+
50
+ # Check connection and authentication
51
+ try:
52
+ loginResponse = self.session.get(self.url + "/rest", timeout=8)
53
+ loginResponse.raise_for_status()
54
+
55
+ if loginResponse.ok or loginResponse.status_code == 200:
56
+ self.isLoggedIn = True
57
+ except requests.exceptions.HTTPError as errh:
58
+ print(f"HTTP error occurred: {errh}")
59
+ except requests.exceptions.ConnectionError as errc:
60
+ print(f"Connection error occurred: {errc}")
61
+ except requests.exceptions.Timeout as errt:
62
+ print(f"Timeout occurred: {errt}")
63
+ except requests.exceptions.RequestException as err:
64
+ print(f"Request exception occurred: {err}")
65
+
66
+ def __executeRequest(self, header: dict = None, resourcePath: str = None, method: str = None, data=None, params=None):
67
+ """
68
+ Executes an HTTP request to the openHAB server.
69
+
70
+ :param header: Optional; A dictionary of headers to be sent with the request.
71
+ :param resourcePath: The path of the resource to interact with.
72
+ :param method: The HTTP method (GET, POST, PUT, DELETE).
73
+ :param data: Optional; The data to send in the request (for POST and PUT requests).
74
+ :return: The response of the request, either as JSON or plain text.
75
+
76
+ :raises ValueError: If the method is invalid or if the resource path is not provided.
77
+ """
78
+ if not resourcePath or not method:
79
+ raise ValueError('You must specify a valid resource path and HTTP method!')
80
+
81
+ method = method.lower()
82
+ header = header or {}
83
+
84
+ if resourcePath[0] != "/":
85
+ resourcePath = "/" + resourcePath
86
+
87
+ # Ensure resource path starts with "/rest"
88
+ if not resourcePath.startswith("/rest"):
89
+ resourcePath = f"/rest{resourcePath}"
90
+
91
+ # Update session headers
92
+ self.session.headers.update(header)
93
+
94
+ try:
95
+ url = f"{self.url}{resourcePath}"
96
+ if method == "get":
97
+ response = self.session.get(url, params=params, timeout=5)
98
+ elif method == "post":
99
+ response = self.session.post(url, data=data, params=params, timeout=5)
100
+ elif method == "put":
101
+ response = self.session.put(url, data=data, params=params, timeout=5)
102
+ elif method == "delete":
103
+ response = self.session.delete(url, data=data, params=params, timeout=5)
104
+ else:
105
+ raise ValueError("Invalid HTTP method provided!")
106
+
107
+ response.raise_for_status()
108
+
109
+ # Prüfen, ob die Antwort JSON enthält
110
+ if response.text.strip(): # Wenn die Antwort nicht leer ist
111
+ if "application/json" in response.headers.get("Content-Type", ""):
112
+ return response.json() # JSON dekodieren
113
+ else:
114
+ return response.text # Anderen Text zurückgeben
115
+
116
+ return {"status": response.status_code} # Nur Status zurückgeben, wenn keine Antwort vorhanden ist
117
+ except requests.exceptions.RequestException as err:
118
+ print(f"Request error occurred: {err}")
119
+ raise
120
+
121
+ def __executeSSE(self, url: str):
122
+ """
123
+ Executes a Server-Sent Events (SSE) request.
124
+
125
+ :param url: The URL to connect to for the SSE stream.
126
+
127
+ :return: The response object with the SSE stream.
128
+ """
129
+ if self.username is not None and self.password is not None:
130
+ return self.session.get(url, auth=self.auth, stream=True)
131
+ else:
132
+ return self.session.get(url, stream=True)
133
+
134
+ def __executeSSE(self, url: str, header: dict = {}):
135
+ """
136
+ Executes a Server-Sent Events (SSE) request with custom headers.
137
+
138
+ :param url: The URL to connect to for the SSE stream.
139
+ :param header: A dictionary of headers to include in the request.
140
+
141
+ :return: The response object with the SSE stream.
142
+ """
143
+ if self.username is not None and self.password is not None:
144
+ return self.session.get(url, auth=self.auth, headers=header, stream=True)
145
+ else:
146
+ return self.session.get(url, headers=header, stream=True)
147
+
148
+ def get(self, endpoint: str, header: dict = None, params: dict = None):
149
+ """
150
+ Sends a GET request to the openHAB server.
151
+
152
+ :param endpoint: The endpoint for the GET request (e.g., "/items").
153
+ :param header: Optional; Headers to be sent with the request.
154
+ :param params: Optional; Query parameters for the GET request.
155
+
156
+ :return: The response from the GET request, either as JSON or plain text.
157
+ """
158
+ return self.__executeRequest(header, endpoint, "get", params=params)
159
+
160
+ def post(self, endpoint: str, header: dict = None, data=None, params: dict = None):
161
+ """
162
+ Sends a POST request to the openHAB server.
163
+
164
+ :param endpoint: The endpoint for the POST request (e.g., "/items").
165
+ :param header: Optional; Headers to be sent with the request.
166
+ :param data: Optional; The data to send in the POST request.
167
+ :param params: Optional; Query parameters for the request.
168
+
169
+ :return: The response from the POST request.
170
+ """
171
+ return self.__executeRequest(header, endpoint, "post", data=data, params=params)
172
+
173
+ def put(self, endpoint: str, header: dict = None, data=None, params: dict = None):
174
+ """
175
+ Sends a PUT request to the openHAB server.
176
+
177
+ :param endpoint: The endpoint for the PUT request (e.g., "/items").
178
+ :param header: Optional; Headers to be sent with the request.
179
+ :param data: Optional; The data to send in the PUT request.
180
+ :param params: Optional; Query parameters for the request.
181
+
182
+ :return: The response from the PUT request.
183
+ """
184
+ return self.__executeRequest(header, endpoint, "put", data=data)
185
+
186
+ def delete(self, endpoint: str, header: dict = None, data=None, params: dict = None):
187
+ """
188
+ Sends a DELETE request to the openHAB server.
189
+
190
+ :param endpoint: The endpoint for the DELETE request (e.g., "/items").
191
+ :param header: Optional; Headers to be sent with the request.
192
+ :param data: Optional; The data to send in the DELETE request.
193
+ :param params: Optional; Query parameters for the request.
194
+
195
+ :return: The response from the DELETE request.
196
+ """
197
+ return self.__executeRequest(header, endpoint, "delete", data=data, params=params)
@@ -0,0 +1,44 @@
1
+ from .Client import OpenHABClient
2
+
3
+ class ConfigDescriptions:
4
+ def __init__(self, client: OpenHABClient):
5
+ """
6
+ Initializes the ConfigDescriptions class with an OpenHABClient instance.
7
+
8
+ :param client: An instance of OpenHABClient used for REST API communication.
9
+ """
10
+ self.client = client
11
+
12
+ def getAllConfigDescriptions(self, language: str = None, scheme: str = None) -> list:
13
+ """
14
+ Retrieves all available config descriptions.
15
+
16
+ :param language: Optional header 'Accept-Language' to specify the preferred language.
17
+ :param scheme: Optional query parameter to filter results by a specific scheme.
18
+
19
+ :return: A list of configuration descriptions.
20
+ """
21
+ header = {}
22
+ if language:
23
+ header["Accept-Language"] = language
24
+
25
+ params = {}
26
+ if scheme:
27
+ params["scheme"] = scheme
28
+
29
+ return self.client.get("/config-descriptions", header=header, params=params)
30
+
31
+ def getConfigDescriptionByUri(self, uri: str, language: str = None) -> dict:
32
+ """
33
+ Retrieves a config description by URI.
34
+
35
+ :param uri: The URI of the requested configuration description.
36
+ :param language: Optional header 'Accept-Language' to specify the preferred language.
37
+
38
+ :return: Details of the specific configuration description.
39
+ """
40
+ header = {}
41
+ if language:
42
+ header["Accept-Language"] = language
43
+
44
+ return self.client.get(f"/config-descriptions/{uri}", header=header)