More robust handling of card removed events

This commit is contained in:
Fabio Manganiello 2018-05-27 11:47:57 +02:00
parent b04a355cc0
commit c73905d35d
2 changed files with 3 additions and 3 deletions

View file

@ -3,7 +3,7 @@ import json
from smartcard.CardType import AnyCardType, ATRCardType
from smartcard.CardRequest import CardRequest
from smartcard.Exceptions import NoCardException
from smartcard.Exceptions import NoCardException, CardConnectionException
from smartcard.util import toHexString
from platypush.backend import Backend
@ -71,7 +71,7 @@ class ScardBackend(Backend):
self.bus.post(SmartCardDetectedEvent(atr=atr, reader=reader))
prev_atr = atr
except Exception as e:
if isinstance(e, NoCardException):
if isinstance(e, NoCardException) or isinstance(e, CardConnectionException):
self.bus.post(SmartCardRemovedEvent(atr=prev_atr, reader=reader))
else:
logging.exception(e)

View file

@ -8,7 +8,7 @@ class SmartCardDetectedEvent(Event):
class SmartCardRemovedEvent(Event):
def __init__(self, atr=None, reader=None, *args, **kwargs):
super().__init__(*args, **kwargs)
super().__init__(atr=atr, reader=reader, *args, **kwargs)
# vim:sw=4:ts=4:et: