Skip to content

Commit

Permalink
raise exceptions as VacuumExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
rytilahti committed Jun 5, 2017
1 parent efdb8be commit 3f5e5a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mirobo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# flake8: noqa
from .protocol import Message, Utils
from .containers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer
from .vacuum import Vacuum
from .vacuum import Vacuum, VacuumException
13 changes: 9 additions & 4 deletions mirobo/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
_LOGGER = logging.getLogger(__name__)


class VacuumException(Exception):
pass


class Vacuum:
"""Main class representing the vacuum."""
def __init__(self, ip, token, debug=0):
Expand Down Expand Up @@ -114,8 +118,9 @@ def send(self, command, parameters=None):

try:
s.sendto(m, (self.ip, self.port))
except Exception as ex:
except OSError as ex:
_LOGGER.error("failed to send msg: %s" % ex)
raise VacuumException from ex

try:
data, addr = s.recvfrom(1024)
Expand All @@ -126,9 +131,9 @@ def send(self, command, parameters=None):
m.header.value.ts,
m.data.value))
return m.data.value["result"]
except Exception as ex:
_LOGGER.error("got error when receiving: %s" % ex)
raise
except OSError as ex:
_LOGGER.error("got error when receiving: %s", ex)
raise VacuumException from ex

def start(self):
return self.send("app_start")
Expand Down

0 comments on commit 3f5e5a8

Please sign in to comment.