Skip to content

Commit

Permalink
Show error icon if an exception occurs during event handling (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfink committed May 10, 2018
1 parent dc2b3b0 commit 35174e4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ openhab_slider_null_command: 0 # Command that should be sent
rotation_icon: 2-digit-angular # Accepted values: 2-digit-angular, 2-digit-curved, circle
rotation_icon_leading_zero: false # Only valid for digit rotation icons: Defines whether there is a leading zero for 1-digit numbers.
rotation_sensitivity: 1.0 # Defines the number revolutions the wheel needs to reach 100%.
error_icon: "errorExclamationMark" # The icon shown on the Nuimo if an error occurs during event handling. Recommended values: errorExclamationMark, errorX, errorSmiley

log_file: "nuimo-openhab.log"
log_level: INFO
Expand Down
2 changes: 1 addition & 1 deletion led_icons
Submodule led_icons updated from 69fb54 to e2eda4
11 changes: 9 additions & 2 deletions nuimo_menue/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def __init__(self, nuimoMenue: NuimoMenue):
self.rawEventHandler = ButtonRawEventHandler()

def received_gesture_event(self, event):
self.handle_gesture_event(event)
self.handle_extra_events(event)
try:
self.handle_gesture_event(event)
self.handle_extra_events(event)
except Exception as error:
self.show_error_icon()
raise error

def handle_extra_events(self, event):
extra_event = self.rawEventHandler.get_highlevel_event(event.gesture)
Expand Down Expand Up @@ -72,6 +76,9 @@ def show_command_icon(self, fqCommand: str):
else: logging.warning("Icon '"+config["command_icon_mapping"][fqCommand]+"' mapped to command '"+fqCommand+"' does not exist")
else: logging.warning("No icon mapped to'"+fqCommand+"'")

def show_error_icon(self):
self.nuimoMenue.controller.display_matrix(nuimo.LedMatrix(icons[config["error_icon"]]))

def started_connecting(self):
logging.info("Connecting...")

Expand Down
5 changes: 1 addition & 4 deletions nuimo_openhab/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,11 @@ def handleSliders(self, rotationOffset):
self.lastSliderSentTimestamp = currentTimestamp

self.openhab.req_post("/items/" + widget["item"]["name"], str(newState))
except Exception:
newState = 0
logging.error(sys.exc_info())
finally:
self.reminder = 0
if widget["sendFrequency"] != 0:
threading.Timer(widget["sendFrequency"]/1000, self.handleSliders, [0]).start()
return self.lastSliderState
return self.lastSliderState

return self.calculateNewSliderState(self.lastSliderState, self.reminder)

Expand Down

0 comments on commit 35174e4

Please sign in to comment.