Skip to content

Commit

Permalink
Avoid usage of openhab.base_url as it changed in python-openhab lib a…
Browse files Browse the repository at this point in the history
…nd causes errors on newer version
  • Loading branch information
pfink committed Aug 13, 2023
1 parent 3019c7b commit 3e1ce04
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions nuimo_openhab/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def handleCommonGesture(self, event):

# Special handling for TOGGLE: Resolve state first to be able showing the correct action icon
if command == "TOGGLE":
state = requests.get(self.openhab.base_url + "/items/" + widget["item"]["name"] + "/state").text
state = self.openhab.get_item(widget["item"]["name"]).state
if state in config["toggle_mapping"]:
command = str(config["toggle_mapping"][state])
elif state == "NULL" and widget["item"]["type"] in config["initial_command"]:
Expand Down Expand Up @@ -119,17 +119,18 @@ def handleSliders(self, rotationOffset):
# Take care that the slider status shown on the LED matrix
# and used for calculating the new slider state is not older than 3s
self.openhab.req_post("/items/" + widget["item"]["name"], "REFRESH")
logging.debug(self.openhab.base_url + widget["item"]["name"] + "/state")
itemStateRaw = requests.get(self.openhab.base_url + "/items/" + widget["item"]["name"] + "/state").text
if(itemStateRaw == "NULL"):
itemStateRaw = config["initial_command"]["Dimmer"]
currentState = float(itemStateRaw)
logging.debug("New Rotation Action" + widget["item"]["name"] + "/state")
item = self.openhab.get_item(widget["item"]["name"])
if(item.is_state_null() or item.is_state_undef()):
currentState = config["initial_command"]["Dimmer"]
else:
currentState = float(item.state)
if currentState <= 0:
currentState = 0
elif currentState < 1:
currentState *= 100
self.lastSliderState = int(currentState)
logging.debug("Raw item state: "+itemStateRaw)
logging.debug("Item State: "+ str(item.state))

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

0 comments on commit 3e1ce04

Please sign in to comment.