FIX: Fix repeated reading of same tag
This commit is contained in:
parent
11091a9f37
commit
f4d10cb703
|
@ -94,7 +94,7 @@ class RegistryDict(dict):
|
|||
os.makedirs(directory)
|
||||
|
||||
with open(config, 'w') as f:
|
||||
json.dump([tag.dict for tag in self.values()], f, indent=4)
|
||||
json.dump([tag.as_dict() for tag in self.values()], f, indent=4)
|
||||
|
||||
def register(self, tag_class, uid, alias=None, parameter=None):
|
||||
'''
|
||||
|
|
|
@ -25,6 +25,7 @@ class Tag:
|
|||
self.uid = uid
|
||||
self.alias = alias
|
||||
self.parameter = parameter
|
||||
self.scanned = None
|
||||
|
||||
def __str__(self):
|
||||
'''
|
||||
|
@ -57,18 +58,6 @@ class Tag:
|
|||
args.append(self.parameter)
|
||||
self.action.__func__(*args)
|
||||
|
||||
@property
|
||||
def dict(self):
|
||||
'''
|
||||
Dict representation of the tag.
|
||||
'''
|
||||
return {
|
||||
'tag_class': self.__class__.__name__,
|
||||
'uid': self.uid,
|
||||
'alias': self.alias or '',
|
||||
'parameter': self.parameter or ''
|
||||
}
|
||||
|
||||
@property
|
||||
def action(self):
|
||||
'''
|
||||
|
@ -84,6 +73,22 @@ class Tag:
|
|||
LOGGER.error(error, cls)
|
||||
raise NotImplementedError(error % cls)
|
||||
|
||||
def as_dict(self, include_scanned=False):
|
||||
'''
|
||||
Dict representation of the tag.
|
||||
'''
|
||||
data = {
|
||||
'tag_class': self.__class__.__name__,
|
||||
'uid': self.uid,
|
||||
'alias': self.alias or '',
|
||||
'parameter': self.parameter or '',
|
||||
}
|
||||
|
||||
if include_scanned:
|
||||
data['scanned'] = self.scanned
|
||||
|
||||
return data
|
||||
|
||||
def validate(self):
|
||||
'''
|
||||
Validate parameter.
|
||||
|
|
|
@ -114,4 +114,5 @@ class TagReader(Thread):
|
|||
play_sound('fail.wav')
|
||||
tag = Tag(uid=uid)
|
||||
|
||||
tag.scanned = time()
|
||||
TagReader.latest = tag
|
||||
|
|
|
@ -54,7 +54,7 @@ class LatestHandler(RequestHandler): # pylint: disable=abstract-method
|
|||
'message': 'Scanned tag found',
|
||||
}
|
||||
|
||||
data.update(tag.dict)
|
||||
data.update(tag.as_dict(include_scanned=True))
|
||||
|
||||
self.set_header('Content-type', 'application/json')
|
||||
self.write(dumps(data))
|
||||
|
@ -80,7 +80,7 @@ class RegistryHandler(RequestHandler): # pylint: disable=abstract-method
|
|||
tags_list = []
|
||||
|
||||
for tag in REGISTRY.values():
|
||||
tags_list.append(tag.dict)
|
||||
tags_list.append(tag.as_dict())
|
||||
|
||||
data = {
|
||||
'success': True,
|
||||
|
@ -122,7 +122,7 @@ class RegisterHandler(RequestHandler): # pylint: disable=abstract-method
|
|||
'message': 'Tag successfully registered',
|
||||
}
|
||||
|
||||
data.update(tag.dict)
|
||||
data.update(tag.as_dict())
|
||||
|
||||
except ValueError as ex:
|
||||
self.set_status(400)
|
||||
|
|
Loading…
Reference in a new issue