Skip to content

Commit

Permalink
Report broken i2c status in front-end
Browse files Browse the repository at this point in the history
Major:

- Add a new Error message in the front end: i2c broken
- Only show 1 error at a time - the one with highest priority
- Fan handler does not time out as long as some data comes regularly
-

Refactor:

- docstrings
- var = foo[bar] => foo.get(bar, var) # when bar is not a mandatory key
- Add comments in some obscure code places
- foo == False => not foo
- magic number => constant
- mutate constant => copy constant as private var
- Simplify Threads (un-nesting)
- except: => except Exception: (does not catch SIGTERM)
- Remove superflous try / except
- logger.error(my_exception) => logger.exception(my_exception)
- def foo(): pass => foo = do_nothing_func
  - saves lines
  - highlights that foo() is not important
- complex if / elif key in foo: bar(foo[key]) => use lookup map
  - better readability
  - saves a bunch of lines (see _handle_fan_dynamic)
- foo.get("bar", None) == "barbar" => foo.get("bar") == "barbar"
- Repeated foo[bar] => var = foo[bar]
- Avoid basic classes as var names (str)
- Remove unused functions

Minor :

- Handles partial fan dynamic datasets as an update (refresh) for the dynamic dataset

Known bug: If iobeam reports partial operational data (new default), the laser temperature gets "out of date" and stops the laser job
  • Loading branch information
amrsoll committed Nov 17, 2021
1 parent 9fe80cc commit a6b748e
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 325 deletions.
40 changes: 19 additions & 21 deletions octoprint_mrbeam/iobeam/dust_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,37 +143,35 @@ def _subscribe(self):
self._event_bus.subscribe(OctoPrintEvents.SHUTDOWN, self._onEvent)

def _handle_fan_data(self, args):
err = False
if args["state"] is not None:
self._state = args["state"]
else:
err = True
if args["dust"] is not None:
self._dust = args["dust"]

if self._printer.is_printing():
self._job_dust_values.append(self._dust)
else:
err = True
if args["rpm"] is not None:
self._rpm = args["rpm"]
else:
err = True
self._state = args.get("state", self._state)
self._dust = args.get("dust", self._dust)
if args.get("dust") and self._printer.is_printing():
self._job_dust_values.append(self._dust)
self._rpm = args.get("rpm", self._rpm)

self._connected = args["connected"]
self._connected = args.get("connected", self._connected)

if self._connected is not None:
self._unboost_timer_interval()

if not err:
if self._connected:
# as long as iobeam does not report the fan missing,
# the latest data is good.
# This will not trigger if the data didn't change, even if the fan is connected.
# However, the values should constantly change during a laserjob. If they don't,
# then this is a safeguard to stop the laser job as we don't detect exhaust
self._logger.warning("UPDATING")
self._data_ts = time.time()

self._validate_values()
self._send_dust_to_analytics(self._dust)
if args.get("dust"):
self._send_dust_to_analytics(self._dust)

self._last_rpm_values.append(self._rpm)
if args.get("rpm"):
self._last_rpm_values.append(self._rpm)

def _on_command_response(self, args):
# This does not seem to be helpful... - Axel
self._logger.debug("Fan command response: %s", args)
if args["success"]:
if (
Expand Down Expand Up @@ -474,7 +472,7 @@ def _validate_values(self):
trigger=msg, analytics="invalid-old-fan-data", log_message=msg
)

elif self._connected == False:
elif not self._connected:
result = False
msg = "Air filter is not connected: state:{state}, rpm:{rpm}, dust:{dust}, connected:{connected}, age:{age:.2f}s".format(
state=self._state,
Expand Down
14 changes: 12 additions & 2 deletions octoprint_mrbeam/iobeam/hw_malfunction_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ def show_hw_malfunction_notification(self):
)

for malfunction_id, data in messages_sorted:
if malfunction_id == self.MALFUNCTION_ID_BOTTOM_OPEN:
if malfunction_id == "i2c_bus_malfunction":
notifications.append(
self._user_notification_system.get_notification(
notification_id=malfunction_id,
err_msg=data.get("msg", None),
replay=True,
)
)

elif malfunction_id == self.MALFUNCTION_ID_BOTTOM_OPEN:
notifications.append(
self._user_notification_system.get_notification(
notification_id="err_bottom_open", replay=True
Expand All @@ -117,7 +126,8 @@ def show_hw_malfunction_notification(self):
)
)

self._user_notification_system.show_notifications(notifications)
# Only send a single error message at a time
self._user_notification_system.show_notifications(notifications[0])

def get_messages_to_show(self):
return self._messages_to_show
Loading

0 comments on commit a6b748e

Please sign in to comment.