diff --git a/mirobo/__init__.py b/mirobo/__init__.py index d467a4eac..2f5eb6f36 100644 --- a/mirobo/__init__.py +++ b/mirobo/__init__.py @@ -1,4 +1,4 @@ # flake8: noqa from .protocol import Message, Utils from .containers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer -from .vacuum import Vacuum \ No newline at end of file +from .vacuum import Vacuum, VacuumException \ No newline at end of file diff --git a/mirobo/vacuum.py b/mirobo/vacuum.py index 472914b38..fb36e8196 100644 --- a/mirobo/vacuum.py +++ b/mirobo/vacuum.py @@ -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): @@ -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) @@ -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")