Skip to content

Commit 3e1ce04

Browse files
committed
Avoid usage of openhab.base_url as it changed in python-openhab lib and causes errors on newer version
1 parent 3019c7b commit 3e1ce04

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

nuimo_openhab/listener.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def handleCommonGesture(self, event):
6868

6969
# Special handling for TOGGLE: Resolve state first to be able showing the correct action icon
7070
if command == "TOGGLE":
71-
state = requests.get(self.openhab.base_url + "/items/" + widget["item"]["name"] + "/state").text
71+
state = self.openhab.get_item(widget["item"]["name"]).state
7272
if state in config["toggle_mapping"]:
7373
command = str(config["toggle_mapping"][state])
7474
elif state == "NULL" and widget["item"]["type"] in config["initial_command"]:
@@ -119,17 +119,18 @@ def handleSliders(self, rotationOffset):
119119
# Take care that the slider status shown on the LED matrix
120120
# and used for calculating the new slider state is not older than 3s
121121
self.openhab.req_post("/items/" + widget["item"]["name"], "REFRESH")
122-
logging.debug(self.openhab.base_url + widget["item"]["name"] + "/state")
123-
itemStateRaw = requests.get(self.openhab.base_url + "/items/" + widget["item"]["name"] + "/state").text
124-
if(itemStateRaw == "NULL"):
125-
itemStateRaw = config["initial_command"]["Dimmer"]
126-
currentState = float(itemStateRaw)
122+
logging.debug("New Rotation Action" + widget["item"]["name"] + "/state")
123+
item = self.openhab.get_item(widget["item"]["name"])
124+
if(item.is_state_null() or item.is_state_undef()):
125+
currentState = config["initial_command"]["Dimmer"]
126+
else:
127+
currentState = float(item.state)
127128
if currentState <= 0:
128129
currentState = 0
129130
elif currentState < 1:
130131
currentState *= 100
131132
self.lastSliderState = int(currentState)
132-
logging.debug("Raw item state: "+itemStateRaw)
133+
logging.debug("Item State: "+ str(item.state))
133134

134135
if abs(self.reminder) >= 1:
135136
logging.debug("Old state: " + str(self.lastSliderState))

0 commit comments

Comments
 (0)