python-openhab-rest-client 0.2.2__py3-none-any.whl → 0.2.4__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.
openhab/Client.py CHANGED
@@ -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):
openhab/Rules.py CHANGED
@@ -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):
openhab/tests/Rules.py CHANGED
@@ -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
@@ -3,7 +3,7 @@ openhab/Addons.py,sha256=9-VH7MFMDbmpt92iUfHsyYNob5sN_6e21sR8gS4v6JQ,14463
3
3
  openhab/Audio.py,sha256=UJbaOHFaZ_zOZ2-tz3aRxQ0RsyVS8_YouaoWrjsnkp0,5140
4
4
  openhab/Auth.py,sha256=BhlTVTX2RgLHv4CVzri_aDrYZYvapGVNzEMpAppTR3o,8660
5
5
  openhab/ChannelTypes.py,sha256=n5UmjnTfoJAYExD3mhtbLN34sWCepuw5982ODY-FWME,4745
6
- openhab/Client.py,sha256=vRZ6rFC5xpwBYDvweOTOPGmqfxc3fIXIM-zmQ9lP2I4,9665
6
+ openhab/Client.py,sha256=AgTV_5jw0_njVPRDax95t7Sw_3-pofspvyNAGRO0xuY,9816
7
7
  openhab/ConfigDescriptions.py,sha256=YUUblEmwTWBMToHR2GBTh1Jut0Nc3LMnZQVY6z_2GRU,3278
8
8
  openhab/Discovery.py,sha256=nxMivvzKHcNwPvryNf_qvHFyf7UCEpf3uDtOugAk5EU,3959
9
9
  openhab/Events.py,sha256=CcJGtepJT810hkH3drTM1Cn1J3PhMJwy2-kRuuUzGM0,27756
@@ -15,7 +15,7 @@ openhab/Logging.py,sha256=iM3Cd8ygqrhO4JLC42kF2nhVVXDYcXf8NXSroL0ekBo,4490
15
15
  openhab/ModuleTypes.py,sha256=FoLti9DZiVfZE6aF4wVW_ANeiRWG1ldRy5btz2EK-r0,3218
16
16
  openhab/Persistence.py,sha256=n4JuP2mnNnZwBbngLvV-ItoTg-drBYcrB_povaJrBqU,12068
17
17
  openhab/ProfileTypes.py,sha256=JIExcNouoqDHQSJPXHyO4fcj2cN4tii8tUL0I-R50SY,1790
18
- openhab/Rules.py,sha256=Q3Nh8U6K8ZWMnSNd5BXoz-qrL3vMI4s_WO0hqZEfkNs,23704
18
+ openhab/Rules.py,sha256=ucf5ySwNrESU33-hjJJnQbL3PDPRCCJgst5qRInQeOI,23724
19
19
  openhab/Services.py,sha256=Oh9eZRe-RRR7zNHW8xbAcSYvdMmIMR9V2mRIQXwOBVU,8230
20
20
  openhab/Sitemaps.py,sha256=uaqgY6l6lEq1WpxnovLB6jnPi0x_iLBaA9X_PJmAgFg,11323
21
21
  openhab/Systeminfo.py,sha256=4jh9-Lx3qVKl4wdauPb7KaJ8NDB5IPHLo2FyUweTXaw,2143
@@ -48,7 +48,7 @@ openhab/tests/Logging.py,sha256=zaiTbhgdg-_nFoBapcsGuNIJ4rlfGb1SaGrb2qKHJhc,1857
48
48
  openhab/tests/ModuleTypes.py,sha256=_8NXTBgl4DahlHN27GhqFujm2m64WG6ec9CwL4_bqOU,1240
49
49
  openhab/tests/Persistence.py,sha256=-xbOLuOJ15viwGP11duEHmNnFreCQZ63zvhY1QfJrHI,4263
50
50
  openhab/tests/ProfileTypes.py,sha256=APNR-uWUril3orD8dfWO72HacrRQASctlEt0zBxLei8,819
51
- openhab/tests/Rules.py,sha256=_wMplTkTZhvtw7s-d1F8IbM6RG6lGAvFdFeXHelYoZM,2903
51
+ openhab/tests/Rules.py,sha256=BsRCklXbXTpvWigf-hx4Jfj3AHM12_Me-uISUQwAkvw,2925
52
52
  openhab/tests/Services.py,sha256=Mxu7xp08ozL7KtmDZRCjRasJMnPrhnwJhQ2qJULaeNM,2913
53
53
  openhab/tests/Sitemaps.py,sha256=sTy9gMKiGx7uIFsQf78KenScMNHW4vV3ZraelJARi68,3673
54
54
  openhab/tests/Systeminfo.py,sha256=uSHacWmTePMoVsbZq0kkPAlcopu_XH65otfBfyJofpI,1055
@@ -82,7 +82,7 @@ tests/Logging.py,sha256=MharW6exJO1Hr2oaBkzOlIJU9-YPPKr6rT0t6CRC_no,824
82
82
  tests/ModuleTypes.py,sha256=e8HADgeoFH8PIYoHDh8yVFSLUDC_QU3iobmx0-ExhN0,633
83
83
  tests/Persistence.py,sha256=3chXTs9DUETDZc7qFIRhcDI-7AR_986QIgRmZ-wKwQY,1526
84
84
  tests/ProfileTypes.py,sha256=4gqloYanEI3F-rx-QIH7IH3rCvUY0kBWPaZ_htd26UI,528
85
- tests/Rules.py,sha256=vILslSpA1msak-4xlKzsBb1IA_nB8u2EE16rcVyR60k,1232
85
+ tests/Rules.py,sha256=3UyQ9YBXdvts2ZNVaEVFqdoWschpjyWtJq1Rs70PPJ4,1311
86
86
  tests/Services.py,sha256=fI21FFvLq_xqEyBbrBcRivhlKKtiYbIoG1VCO3kxjFQ,1096
87
87
  tests/Sitemaps.py,sha256=moRcnelOzU--i6Qh_pzstPbNvN4b5tEtE09HDXjHK9k,1101
88
88
  tests/Systeminfo.py,sha256=khe5t8ox1D-BsxntyikxzaH5NO06Xmu4uMLXUaRfUtY,580
@@ -96,8 +96,8 @@ tests/UI.py,sha256=0RWgqZXUrJN4bL-e_n4bQquBDh9CctnsQIVE0AsrFiI,1764
96
96
  tests/UUID.py,sha256=CetUDQ0rDSq6n1dmRAbh5VW10N8GLKoxW9imkdea8n4,520
97
97
  tests/Voice.py,sha256=zFA-R_22560uIWKHU2mV14B3OnbQx3d2qiwRKXJrTKY,2057
98
98
  tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
99
- python_openhab_rest_client-0.2.2.dist-info/LICENSE,sha256=69QhqD8S8OPNY1BAzQIPayy_M-A5ltuK0v5kRvS75ZI,1086
100
- python_openhab_rest_client-0.2.2.dist-info/METADATA,sha256=mK2zUAYH1-POYVnM_Tp3WSHQbo-yXw4ci1M36Y4bLeo,68512
101
- python_openhab_rest_client-0.2.2.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
102
- python_openhab_rest_client-0.2.2.dist-info/top_level.txt,sha256=m5d0ZGvuMBPyd81BONJW6I-kWCeHagriOKWruLGt1u8,14
103
- python_openhab_rest_client-0.2.2.dist-info/RECORD,,
99
+ python_openhab_rest_client-0.2.4.dist-info/LICENSE,sha256=69QhqD8S8OPNY1BAzQIPayy_M-A5ltuK0v5kRvS75ZI,1086
100
+ python_openhab_rest_client-0.2.4.dist-info/METADATA,sha256=OkSt5krlZb51Em0J3J65f3bJ5FKTJnF-cMASm6heJ30,68512
101
+ python_openhab_rest_client-0.2.4.dist-info/WHEEL,sha256=iAkIy5fosb7FzIOwONchHf19Qu7_1wCWyFNR5gu9nU0,91
102
+ python_openhab_rest_client-0.2.4.dist-info/top_level.txt,sha256=m5d0ZGvuMBPyd81BONJW6I-kWCeHagriOKWruLGt1u8,14
103
+ python_openhab_rest_client-0.2.4.dist-info/RECORD,,
tests/Rules.py CHANGED
@@ -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": [],