python-openhab-rest-client 0.2.1__tar.gz → 0.2.3__tar.gz

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 (108) hide show
  1. {python_openhab_rest_client-0.2.1/python_openhab_rest_client.egg-info → python_openhab_rest_client-0.2.3}/PKG-INFO +1 -1
  2. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Client.py +17 -9
  3. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Rules.py +6 -7
  4. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ItemEvents.py +1 -0
  5. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Rules.py +2 -2
  6. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3/python_openhab_rest_client.egg-info}/PKG-INFO +1 -1
  7. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/setup.py +1 -1
  8. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Rules.py +5 -2
  9. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/LICENSE +0 -0
  10. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/README.md +0 -0
  11. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Actions.py +0 -0
  12. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Addons.py +0 -0
  13. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Audio.py +0 -0
  14. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Auth.py +0 -0
  15. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/ChannelTypes.py +0 -0
  16. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/ConfigDescriptions.py +0 -0
  17. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Discovery.py +0 -0
  18. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Events.py +0 -0
  19. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Iconsets.py +0 -0
  20. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Inbox.py +0 -0
  21. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Items.py +0 -0
  22. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Links.py +0 -0
  23. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Logging.py +0 -0
  24. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/ModuleTypes.py +0 -0
  25. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Persistence.py +0 -0
  26. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/ProfileTypes.py +0 -0
  27. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Services.py +0 -0
  28. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Sitemaps.py +0 -0
  29. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Systeminfo.py +0 -0
  30. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Tags.py +0 -0
  31. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Templates.py +0 -0
  32. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/ThingTypes.py +0 -0
  33. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Things.py +0 -0
  34. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Transformations.py +0 -0
  35. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/UI.py +0 -0
  36. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/UUID.py +0 -0
  37. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/Voice.py +0 -0
  38. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/__init__.py +0 -0
  39. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Actions.py +0 -0
  40. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Addons.py +0 -0
  41. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Audio.py +0 -0
  42. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Auth.py +0 -0
  43. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ChannelEvents.py +0 -0
  44. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ChannelTypes.py +0 -0
  45. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ConfigDescriptions.py +0 -0
  46. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Discovery.py +0 -0
  47. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Events.py +0 -0
  48. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Iconsets.py +0 -0
  49. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Inbox.py +0 -0
  50. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/InboxEvents.py +0 -0
  51. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Items.py +0 -0
  52. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/LinkEvents.py +0 -0
  53. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Links.py +0 -0
  54. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Logging.py +0 -0
  55. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ModuleTypes.py +0 -0
  56. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Persistence.py +0 -0
  57. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ProfileTypes.py +0 -0
  58. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Services.py +0 -0
  59. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Sitemaps.py +0 -0
  60. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Systeminfo.py +0 -0
  61. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Tags.py +0 -0
  62. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Templates.py +0 -0
  63. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ThingEvents.py +0 -0
  64. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/ThingTypes.py +0 -0
  65. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Things.py +0 -0
  66. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Transformations.py +0 -0
  67. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/UI.py +0 -0
  68. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/UUID.py +0 -0
  69. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/Voice.py +0 -0
  70. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/openhab/tests/__init__.py +0 -0
  71. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/python_openhab_rest_client.egg-info/SOURCES.txt +0 -0
  72. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/python_openhab_rest_client.egg-info/dependency_links.txt +0 -0
  73. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/python_openhab_rest_client.egg-info/requires.txt +0 -0
  74. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/python_openhab_rest_client.egg-info/top_level.txt +0 -0
  75. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/setup.cfg +0 -0
  76. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Actions.py +0 -0
  77. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Addons.py +0 -0
  78. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Audio.py +0 -0
  79. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Auth.py +0 -0
  80. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ChannelEvents.py +0 -0
  81. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ChannelTypes.py +0 -0
  82. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ConfigDescriptions.py +0 -0
  83. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Discovery.py +0 -0
  84. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Events.py +0 -0
  85. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Iconsets.py +0 -0
  86. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Inbox.py +0 -0
  87. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/InboxEvents.py +0 -0
  88. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ItemEvents.py +0 -0
  89. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Items.py +0 -0
  90. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/LinkEvents.py +0 -0
  91. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Links.py +0 -0
  92. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Logging.py +0 -0
  93. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ModuleTypes.py +0 -0
  94. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Persistence.py +0 -0
  95. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ProfileTypes.py +0 -0
  96. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Services.py +0 -0
  97. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Sitemaps.py +0 -0
  98. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Systeminfo.py +0 -0
  99. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Tags.py +0 -0
  100. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Templates.py +0 -0
  101. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ThingEvents.py +0 -0
  102. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/ThingTypes.py +0 -0
  103. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Things.py +0 -0
  104. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Transformations.py +0 -0
  105. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/UI.py +0 -0
  106. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/UUID.py +0 -0
  107. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/Voice.py +0 -0
  108. {python_openhab_rest_client-0.2.1 → python_openhab_rest_client-0.2.3}/tests/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-openhab-rest-client
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A Python client for the openHAB REST API. This library enables easy interaction with the openHAB REST API to control smart home devices, retrieve status information, and process events.
5
5
  Home-page: https://github.com/Michdo93/python-openhab-rest-client
6
6
  Author: Michael Christian Dörflinger
@@ -1,6 +1,4 @@
1
1
  import requests
2
- import json
3
-
4
2
 
5
3
  class OpenHABClient:
6
4
  def __init__(self, url: str, username: str = None, password: str = None, token: str = None):
@@ -136,18 +134,23 @@ class OpenHABClient:
136
134
  response = self.session.delete(url, data=data, params=params, headers=header, timeout=5)
137
135
  else:
138
136
  raise ValueError("Invalid HTTP method provided!")
137
+
138
+ location = response.headers.get("Location")
139
139
 
140
- # Pass on mistakes directly instead of catching them here!
140
+ if location:
141
+ return response
142
+
143
+ # Pass on mistakes directly instead of catching them here!
141
144
  response.raise_for_status()
142
145
 
143
146
  # If the response is empty, but there was still no error, we return the status code
144
147
  if not response.text.strip():
145
148
  return {"status": response.status_code}
146
-
149
+
147
150
  # Return JSON response, if available
148
151
  if "application/json" in response.headers.get("Content-Type", ""):
149
152
  return response.json()
150
-
153
+
151
154
  return response.text # Fallback: Return text response
152
155
 
153
156
  def __executeSSE(self, url: str):
@@ -158,10 +161,11 @@ class OpenHABClient:
158
161
 
159
162
  :return: The response object with the SSE stream.
160
163
  """
164
+ self.session.headers.update({})
161
165
  if self.username is not None and self.password is not None:
162
- return self.session.get(url, auth=self.auth, stream=True)
166
+ return requests.get(url, auth=self.auth, headers={}, stream=True)
163
167
  else:
164
- return self.session.get(url, stream=True)
168
+ return requests.get(url, headers={}, stream=True)
165
169
 
166
170
  def __executeSSE(self, url: str, header: dict = {}):
167
171
  """
@@ -172,10 +176,14 @@ class OpenHABClient:
172
176
 
173
177
  :return: The response object with the SSE stream.
174
178
  """
179
+ if header is None:
180
+ header = {}
181
+
182
+ self.session.headers.update(header)
175
183
  if self.username is not None and self.password is not None:
176
- return self.session.get(url, auth=self.auth, headers=header, stream=True)
184
+ return requests.get(url, auth=self.auth, headers=header, stream=True)
177
185
  else:
178
- return self.session.get(url, headers=header, stream=True)
186
+ return requests.get(url, headers=header, stream=True)
179
187
 
180
188
  def get(self, endpoint: str, header: dict = None, params: dict = None):
181
189
  """
@@ -56,13 +56,11 @@ class Rules:
56
56
  try:
57
57
  response = self.client.post(
58
58
  "/rules", data=json.dumps(ruleData), header={"Content-Type": "application/json"})
59
-
60
- if isinstance(response, dict) and "status" in response:
61
- status_code = response["status"]
62
- else:
63
- return response
59
+
60
+ status_code = response.status_code
64
61
 
65
62
  except requests.exceptions.HTTPError as err:
63
+ # Fehlerbehandlung
66
64
  status_code = err.response.status_code
67
65
  if status_code == 400:
68
66
  return {"error": "Creation refused: Missing required parameter."}
@@ -73,18 +71,19 @@ class Rules:
73
71
 
74
72
  except requests.exceptions.RequestException as err:
75
73
  return {"error": f"Request error: {str(err)}"}
76
-
74
+
77
75
  if status_code == 201:
78
76
  location = response.headers.get("Location")
79
77
  return {
80
78
  "message": "Rule successfully created.",
81
79
  "location": location if location else "No Location header provided."
82
- }
80
+ }
83
81
  elif status_code == 400:
84
82
  return {"error": "Creation refused: Missing required parameter."}
85
83
  elif status_code == 409:
86
84
  return {"error": "Creation refused: Rule with the same UID already exists."}
87
85
 
86
+ # Falls der Statuscode nicht erkannt wird, gib eine generische Fehlermeldung zurück
88
87
  return {"error": f"Unexpected response: {status_code}"}
89
88
 
90
89
  def getRule(self, ruleUID: str):
@@ -106,6 +106,7 @@ class ItemEventsTest:
106
106
 
107
107
  try:
108
108
  response = self.itemEventsAPI.ItemStateChangedEvent()
109
+ print("Response ItemStateChangedEvent():", response)
109
110
  with response as events:
110
111
  for line in events.iter_lines():
111
112
  line = line.decode()
@@ -36,8 +36,8 @@ class RulesTest:
36
36
  print("\n~~~~ Test #3 createRule(ruleData) ~~~~\n")
37
37
 
38
38
  try:
39
- self.rulesAPI.createRule(ruleData)
40
- print("New Rule created successfully.")
39
+ rule = self.rulesAPI.createRule(ruleData)
40
+ print(json.dumps(rule, indent=4))
41
41
  except Exception as e:
42
42
  print(f"Error creating rule: {e}")
43
43
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-openhab-rest-client
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: A Python client for the openHAB REST API. This library enables easy interaction with the openHAB REST API to control smart home devices, retrieve status information, and process events.
5
5
  Home-page: https://github.com/Michdo93/python-openhab-rest-client
6
6
  Author: Michael Christian Dörflinger
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="python-openhab-rest-client",
5
- version="0.2.1",
5
+ version="0.2.3",
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  "requests"
@@ -1,5 +1,6 @@
1
1
  import sys
2
2
  import os
3
+ import random
3
4
 
4
5
  # Add the project root path (one level up) to the Python search path
5
6
  sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
@@ -12,10 +13,12 @@ if __name__ == "__main__":
12
13
  client = OpenHABClient(url="http://127.0.0.1:8080", username="openhab", password="habopen")
13
14
  rulesTest = RulesTest(client)
14
15
 
16
+ random_number = random.randint(0, 100)
17
+
15
18
  # Example rule data
16
- ruleID = "test_color-1"
19
+ ruleID = "test_color-4"
17
20
  newRuleData = {
18
- "uid": "newRule",
21
+ "uid": "newRule" + random_number,
19
22
  "name": "New Rule",
20
23
  "description": "This is a new rule",
21
24
  "triggers": [],