Better exception handling
This commit is contained in:
parent
d708d1eb21
commit
d17552a644
|
@ -34,7 +34,7 @@ class Value:
|
|||
elif callable(translate):
|
||||
self.translate = translate
|
||||
else:
|
||||
self.translate = lambda x: translate[x]
|
||||
self.translate = lambda x: translate.get(x, "None")
|
||||
|
||||
if start_value is not None:
|
||||
self.update(start_value)
|
||||
|
|
|
@ -10,7 +10,7 @@ from .util import timestamp
|
|||
from .door.constants import state_names
|
||||
|
||||
class DoorControlSocket(util.Loggable):
|
||||
class LineBuffer(object):
|
||||
class LineBuffer(util.Loggable):
|
||||
def __init__(self, f, handler):
|
||||
self.data = b''
|
||||
self.f = f
|
||||
|
@ -20,14 +20,17 @@ class DoorControlSocket(util.Loggable):
|
|||
data = self.f.recv(1024)
|
||||
print(repr(data))
|
||||
if not data:
|
||||
print("Eep")
|
||||
self._logger().info("Socket closed")
|
||||
return False
|
||||
self.data += data
|
||||
d = self.data.split(b'\n')
|
||||
d, self.data = d[:-1], d[-1]
|
||||
for i in d:
|
||||
print("Handling", repr(i))
|
||||
self._logger().debug(f"Handling {repr(i)}")
|
||||
try:
|
||||
self.handler(self.f, i)
|
||||
except:
|
||||
self._logger().exception("Error while handling command")
|
||||
return True
|
||||
|
||||
def __init__(self, config, control, nfc):
|
||||
|
@ -114,10 +117,7 @@ class DoorControlSocket(util.Loggable):
|
|||
send("Reloading tokens")
|
||||
self._nfc._read_valid_tokens()
|
||||
elif cmd == 'stat':
|
||||
send("Door status is %s, position is %d. Current action: %s\n" % (
|
||||
self._control.state.str(),
|
||||
self._control.position(),
|
||||
self._control.target.str()))
|
||||
send(f"Door status is {self._control.state.str()}, position is {self._control.position()}. Current action: {self._control.target.str()}\n")
|
||||
|
||||
|
||||
def start(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user