Skip to content

Commit

Permalink
Fix bot error message handling (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mib1185 committed Feb 12, 2024
1 parent 758978e commit 2915b06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion sucks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@
'dust_case_heap': COMPONENT_FILTER
}

ERROR_CODES = {
"100": "Robot is operational",
"101": "Low battery",
"102": "Robot is stuck",
"103": "Wheels are not moving as expected",
"104": "Down sensor is getting abnormal values",
"110": "Dust Bin Not installed",
}

class EcoVacsAPI:
CLIENT_KEY = "eJUWrzRv34qFSaYk"
SECRET = "Cyu5jcR4zyK6QEPn1hdIGXB5QIDAQABMA0GC"
Expand Down Expand Up @@ -289,7 +298,9 @@ def _handle_ctl(self, ctl):
getattr(self, method)(ctl)

def _handle_error(self, event):
error = event['error']
errno = event.get('errno')
if not errno or (error := ERROR_CODES.get(errno)) is None:
error = event.get('error', 'unknown')
self.errorEvents.notify(error)
_LOGGER.debug("*** error = " + error)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_vacbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ def test_error_event_subscription():
v._handle_ctl({"event": "error", "error": "an_error_name"})
mock.assert_called_once_with("an_error_name")

for err_code, err_msg in ERROR_CODES.items():
v._handle_ctl({"event": "error", "errno": err_code})
mock.assert_called_with(err_msg)

v._handle_ctl({"event": "error", "errno": "999"})
mock.assert_called_with("unknown")

v._handle_ctl({"event": "error"})
mock.assert_called_with("unknown")

# Test unsubscribe
mock = Mock()
subscription = v.errorEvents.subscribe(mock)
Expand Down

0 comments on commit 2915b06

Please sign in to comment.