Merge pull request #7 from confirm/invalid-parameter-check

FIX: Decline parameters on registration for certain tags
This commit is contained in:
Dominique Barton 2019-03-26 21:46:01 +01:00 committed by GitHub
commit c9a11d04ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,6 +35,7 @@ class Tag(object):
Base RFID tag class, which will implement the factory pattern in Python's
own :py:meth:`__new__` method.
'''
parameter_allowed = True
def __new__(cls, uid):
'''
@ -149,7 +150,9 @@ class Tag(object):
'or use register() method of explicit tag classes.'
raise InvalidTagType(error)
if hasattr(real_cls, 'validate_parameter'):
if not real_cls.parameter_allowed and parameter:
raise ValueError('No parameter allowed for this tag')
elif hasattr(real_cls, 'validate_parameter'):
real_cls.validate_parameter(parameter)
REGISTRY[uid] = {
@ -229,18 +232,21 @@ class PlayPauseTag(Tag):
'''
Pauses or resumes the playback, based on the current state.
'''
action = 'play_pause'
action = 'play_pause'
parameter_allowed = False
class StopTag(Tag):
'''
Stops the playback.
'''
action = 'stop'
action = 'stop'
parameter_allowed = False
class ShutdownTag(Tag):
'''
Shutting down the system.
'''
action = 'shutdown'
action = 'shutdown'
parameter_allowed = False