FEATURE: Add beep when RFID card is touched

This commit is contained in:
Dominique Barton 2019-02-26 23:44:12 +01:00
parent efcd187219
commit 1dddf38513
3 changed files with 14 additions and 2 deletions

View file

@ -5,6 +5,7 @@ Python module for Mopidy Pummeluff frontend.
from __future__ import absolute_import, unicode_literals, print_function
from os import path, system
from threading import Thread, Event
from time import time
from logging import getLogger
@ -17,8 +18,6 @@ from .cards import Card
LOGGER = getLogger(__name__)
LAST_UID = ''
class CardReader(Thread):
'''
@ -26,6 +25,16 @@ class CardReader(Thread):
'''
latest = None
@staticmethod
def play_sound(sound):
'''
Play sound via aplay.
:param str sound: The name of the sound file
'''
file_path = path.join(path.dirname(__file__), 'sounds', sound)
system('aplay -q {}'.format(file_path))
def __init__(self, core, stop_event):
'''
Class constructor.
@ -73,9 +82,12 @@ class CardReader(Thread):
if card.registered:
LOGGER.info('Triggering action of registered card')
self.play_sound('success.wav')
card.action(mopidy_core=self.core)
else:
LOGGER.info('Card is not registered, thus doing nothing')
self.play_sound('fail.wav')
card.scanned = time()
CardReader.latest = card

Binary file not shown.

Binary file not shown.