python-openhab-rest-client 0.2.2__tar.gz → 0.2.4__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.2/python_openhab_rest_client.egg-info → python_openhab_rest_client-0.2.4}/PKG-INFO +1 -1
  2. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Client.py +8 -3
  3. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Rules.py +8 -9
  4. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Rules.py +10 -10
  5. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4/python_openhab_rest_client.egg-info}/PKG-INFO +1 -1
  6. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/setup.py +1 -1
  7. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Rules.py +5 -2
  8. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/LICENSE +0 -0
  9. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/README.md +0 -0
  10. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Actions.py +0 -0
  11. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Addons.py +0 -0
  12. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Audio.py +0 -0
  13. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Auth.py +0 -0
  14. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/ChannelTypes.py +0 -0
  15. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/ConfigDescriptions.py +0 -0
  16. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Discovery.py +0 -0
  17. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Events.py +0 -0
  18. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Iconsets.py +0 -0
  19. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Inbox.py +0 -0
  20. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Items.py +0 -0
  21. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Links.py +0 -0
  22. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Logging.py +0 -0
  23. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/ModuleTypes.py +0 -0
  24. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Persistence.py +0 -0
  25. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/ProfileTypes.py +0 -0
  26. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Services.py +0 -0
  27. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Sitemaps.py +0 -0
  28. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Systeminfo.py +0 -0
  29. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Tags.py +0 -0
  30. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Templates.py +0 -0
  31. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/ThingTypes.py +0 -0
  32. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Things.py +0 -0
  33. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Transformations.py +0 -0
  34. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/UI.py +0 -0
  35. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/UUID.py +0 -0
  36. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/Voice.py +0 -0
  37. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/__init__.py +0 -0
  38. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Actions.py +0 -0
  39. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Addons.py +0 -0
  40. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Audio.py +0 -0
  41. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Auth.py +0 -0
  42. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ChannelEvents.py +0 -0
  43. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ChannelTypes.py +0 -0
  44. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ConfigDescriptions.py +0 -0
  45. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Discovery.py +0 -0
  46. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Events.py +0 -0
  47. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Iconsets.py +0 -0
  48. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Inbox.py +0 -0
  49. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/InboxEvents.py +0 -0
  50. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ItemEvents.py +0 -0
  51. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Items.py +0 -0
  52. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/LinkEvents.py +0 -0
  53. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Links.py +0 -0
  54. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Logging.py +0 -0
  55. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ModuleTypes.py +0 -0
  56. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Persistence.py +0 -0
  57. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ProfileTypes.py +0 -0
  58. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Services.py +0 -0
  59. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Sitemaps.py +0 -0
  60. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Systeminfo.py +0 -0
  61. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Tags.py +0 -0
  62. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Templates.py +0 -0
  63. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ThingEvents.py +0 -0
  64. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/ThingTypes.py +0 -0
  65. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Things.py +0 -0
  66. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Transformations.py +0 -0
  67. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/UI.py +0 -0
  68. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/UUID.py +0 -0
  69. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/Voice.py +0 -0
  70. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/openhab/tests/__init__.py +0 -0
  71. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/python_openhab_rest_client.egg-info/SOURCES.txt +0 -0
  72. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/python_openhab_rest_client.egg-info/dependency_links.txt +0 -0
  73. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/python_openhab_rest_client.egg-info/requires.txt +0 -0
  74. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/python_openhab_rest_client.egg-info/top_level.txt +0 -0
  75. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/setup.cfg +0 -0
  76. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Actions.py +0 -0
  77. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Addons.py +0 -0
  78. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Audio.py +0 -0
  79. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Auth.py +0 -0
  80. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ChannelEvents.py +0 -0
  81. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ChannelTypes.py +0 -0
  82. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ConfigDescriptions.py +0 -0
  83. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Discovery.py +0 -0
  84. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Events.py +0 -0
  85. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Iconsets.py +0 -0
  86. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Inbox.py +0 -0
  87. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/InboxEvents.py +0 -0
  88. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ItemEvents.py +0 -0
  89. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Items.py +0 -0
  90. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/LinkEvents.py +0 -0
  91. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Links.py +0 -0
  92. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Logging.py +0 -0
  93. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ModuleTypes.py +0 -0
  94. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Persistence.py +0 -0
  95. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ProfileTypes.py +0 -0
  96. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Services.py +0 -0
  97. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Sitemaps.py +0 -0
  98. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Systeminfo.py +0 -0
  99. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Tags.py +0 -0
  100. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Templates.py +0 -0
  101. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ThingEvents.py +0 -0
  102. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/ThingTypes.py +0 -0
  103. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Things.py +0 -0
  104. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Transformations.py +0 -0
  105. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/UI.py +0 -0
  106. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/UUID.py +0 -0
  107. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/tests/Voice.py +0 -0
  108. {python_openhab_rest_client-0.2.2 → python_openhab_rest_client-0.2.4}/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.2
3
+ Version: 0.2.4
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
@@ -134,18 +134,23 @@ class OpenHABClient:
134
134
  response = self.session.delete(url, data=data, params=params, headers=header, timeout=5)
135
135
  else:
136
136
  raise ValueError("Invalid HTTP method provided!")
137
+
138
+ location = response.headers.get("Location")
137
139
 
138
- # 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!
139
144
  response.raise_for_status()
140
145
 
141
146
  # If the response is empty, but there was still no error, we return the status code
142
147
  if not response.text.strip():
143
148
  return {"status": response.status_code}
144
-
149
+
145
150
  # Return JSON response, if available
146
151
  if "application/json" in response.headers.get("Content-Type", ""):
147
152
  return response.json()
148
-
153
+
149
154
  return response.text # Fallback: Return text response
150
155
 
151
156
  def __executeSSE(self, url: str):
@@ -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):
@@ -504,10 +503,10 @@ class Rules:
504
503
 
505
504
  return {"error": f"Unexpected response: {status_code}"}
506
505
 
507
- def enableRule(self, ruleUID: str):
506
+ def enable(self, ruleUID: str):
508
507
  return self.setRuleState(ruleUID, True)
509
508
 
510
- def disableRule(self, ruleUID: str):
509
+ def disable(self, ruleUID: str):
511
510
  return self.setRuleState(ruleUID, False)
512
511
 
513
512
  def runNow(self, ruleUID: str, contextData: dict = None):
@@ -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
 
@@ -46,8 +46,8 @@ class RulesTest:
46
46
  print("\n~~~~ Test #4 updateRule(ruleID, ruleData) ~~~~\n")
47
47
 
48
48
  try:
49
- self.rulesAPI.updateRule(ruleID, ruleData)
50
- print("Rule updated successfully.")
49
+ rule = self.rulesAPI.updateRule(ruleID, ruleData)
50
+ print(json.dumps(rule, indent=4))
51
51
  except Exception as e:
52
52
  print(f"Error updating rule {ruleID}: {e}")
53
53
 
@@ -57,8 +57,8 @@ class RulesTest:
57
57
  print("\n~~~~ Test #5 setRuleState(ruleID, state) ~~~~\n")
58
58
 
59
59
  try:
60
- self.rulesAPI.setRuleState(ruleID, state)
61
- print(f"Rule {ruleID} {action}.")
60
+ rule = self.rulesAPI.setRuleState(ruleID, state)
61
+ print(json.dumps(rule, indent=4))
62
62
  except Exception as e:
63
63
  print(f"Error setting rule state for {ruleID}: {e}")
64
64
 
@@ -67,8 +67,8 @@ class RulesTest:
67
67
  print("\n~~~~ Test #6 deleteRule(ruleID) ~~~~\n")
68
68
 
69
69
  try:
70
- self.rulesAPI.deleteRule(ruleID)
71
- print("Rule deleted successfully.")
70
+ rule = self.rulesAPI.deleteRule(ruleID)
71
+ print(json.dumps(rule, indent=4))
72
72
  except Exception as e:
73
73
  print(f"Error deleting rule {ruleID}: {e}")
74
74
 
@@ -77,7 +77,7 @@ class RulesTest:
77
77
  print("\n~~~~ Test #7 runNow(ruleID) ~~~~\n")
78
78
 
79
79
  try:
80
- self.rulesAPI.runNow(ruleID, contextData)
81
- print("Rule executed successfully.")
80
+ rule = self.rulesAPI.runNow(ruleID, contextData)
81
+ print(json.dumps(rule, indent=4))
82
82
  except Exception as e:
83
83
  print(f"Error executing rule {ruleID}: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-openhab-rest-client
3
- Version: 0.2.2
3
+ Version: 0.2.4
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.2",
5
+ version="0.2.4",
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" + str(random_number),
19
22
  "name": "New Rule",
20
23
  "description": "This is a new rule",
21
24
  "triggers": [],