Generating SmartCardRemoveEvent as well when a scard is removed

This commit is contained in:
Fabio Manganiello 2018-05-27 11:11:05 +02:00
parent 0a71e73cf0
commit 8a6dcdbf5f
2 changed files with 9 additions and 1 deletions

View file

@ -3,6 +3,7 @@ import json
from smartcard.CardType import AnyCardType, ATRCardType
from smartcard.CardRequest import CardRequest
from smartcard.Exceptions import NoCardException
from smartcard.util import toHexString
from platypush.backend import Backend
@ -68,8 +69,10 @@ class ScardBackend(Backend):
self.bus.post(SmartCardDetectedEvent(atr=atr, reader=reader))
prev_atr = atr
except Exception as e:
if isinstance(e, NoCardException):
prev_atr = None
self.bus.post(SmartCardRemovedEvent())
logging.exception(e)
prev_atr = None
# vim:sw=4:ts=4:et:

View file

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