diff --git a/platypush/backend/scard/__init__.py b/platypush/backend/scard/__init__.py index 039eebfa1..f5b944a9f 100644 --- a/platypush/backend/scard/__init__.py +++ b/platypush/backend/scard/__init__.py @@ -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: diff --git a/platypush/message/event/scard.py b/platypush/message/event/scard.py index 4bf1809dc..9b887b72e 100644 --- a/platypush/message/event/scard.py +++ b/platypush/message/event/scard.py @@ -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: