mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-29 12:10:08 +02:00
included librouteros library to avoid conflicts with other integrations #2
This commit is contained in:
parent
c58184b0f7
commit
b70bb9db92
9 changed files with 590 additions and 4 deletions
52
custom_components/mikrotik_router/librouteros/exceptions.py
Normal file
52
custom_components/mikrotik_router/librouteros/exceptions.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
|
||||
|
||||
class LibRouterosError(Exception):
|
||||
"""Base exception for all other."""
|
||||
|
||||
|
||||
class ConnectionClosed(LibRouterosError):
|
||||
"""Raised when connection have been closed."""
|
||||
|
||||
|
||||
class ProtocolError(LibRouterosError):
|
||||
"""Raised when e.g. encoding/decoding fails."""
|
||||
|
||||
|
||||
class FatalError(ProtocolError):
|
||||
"""Exception raised when !fatal is received."""
|
||||
|
||||
|
||||
class TrapError(ProtocolError):
|
||||
"""
|
||||
Exception raised when !trap is received.
|
||||
|
||||
:param int category: Optional integer representing category.
|
||||
:param str message: Error message.
|
||||
"""
|
||||
|
||||
def __init__(self, message, category=None):
|
||||
self.category = category
|
||||
self.message = message
|
||||
super().__init__()
|
||||
|
||||
def __str__(self):
|
||||
return str(self.message.replace('\r\n', ','))
|
||||
|
||||
def __repr__(self):
|
||||
return '{}({!r})'.format(self.__class__.__name__, str(self))
|
||||
|
||||
|
||||
class MultiTrapError(ProtocolError):
|
||||
"""
|
||||
Exception raised when multiple !trap words have been received in one response.
|
||||
|
||||
:param traps: TrapError instances.
|
||||
"""
|
||||
|
||||
def __init__(self, *traps):
|
||||
self.traps = traps
|
||||
super().__init__()
|
||||
|
||||
def __str__(self):
|
||||
return ', '.join(str(trap) for trap in self.traps)
|
Loading…
Add table
Add a link
Reference in a new issue