mirror of
https://github.com/acatoire/bipbipzizik.git
synced 2026-03-10 08:01:18 +00:00
Change docstring to Epytext and minor pylint
This commit is contained in:
4
box.py
4
box.py
@@ -12,7 +12,7 @@ from time import time, sleep
|
||||
from card_launcher import CardLauncher
|
||||
from sys import platform
|
||||
|
||||
if platform == "linux" or platform == "linux2" or platform == "darwin":
|
||||
if platform in ("linux", "linux2", "darwin"):
|
||||
# linux or OS X
|
||||
from modules.tools import get_linux_serial as get_serial
|
||||
from modules.rfid_reader.linux_reader import Reader
|
||||
@@ -28,7 +28,7 @@ UPDATE_PERIOD = 60
|
||||
def main():
|
||||
"""
|
||||
Application main function
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
reader = Reader()
|
||||
|
||||
@@ -29,15 +29,15 @@ class CardLauncher:
|
||||
def database_update(self):
|
||||
"""
|
||||
Update the database
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
self.database.update()
|
||||
|
||||
def config_update(self, config_id):
|
||||
"""
|
||||
Update used config
|
||||
:param config_id: id of the config to be used
|
||||
:return: None
|
||||
@return config_id: id of the config to be used
|
||||
@return: None
|
||||
"""
|
||||
self.config = self.database.get_config(config_id)
|
||||
|
||||
@@ -52,8 +52,8 @@ class CardLauncher:
|
||||
def execute_card(self, card_id):
|
||||
"""
|
||||
Execute a card command
|
||||
:param card_id: card to be run
|
||||
:return: error code
|
||||
@return card_id: card to be run
|
||||
@return: error code
|
||||
- 0 if all OK
|
||||
- 1 if card is not found
|
||||
- 2 if card is canceled by the memory
|
||||
|
||||
@@ -20,7 +20,7 @@ class CardsWrite(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Setup for all unit test
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
cls.launcher = CardLauncher('https://bipbipzizik.firebaseio.com/', 'prod')
|
||||
@@ -32,21 +32,21 @@ class CardsWrite(unittest.TestCase):
|
||||
def test_playpause(self):
|
||||
"""
|
||||
Test card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
self.launcher.execute_card('0013397903')
|
||||
|
||||
def test_mathieu_shedid(self):
|
||||
"""
|
||||
Test card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
self.launcher.execute_card('0013365376')
|
||||
|
||||
def test_gorillaz(self):
|
||||
"""
|
||||
Test card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
self.launcher.execute_card('0005585628')
|
||||
|
||||
|
||||
@@ -15,14 +15,14 @@ class AppConfig:
|
||||
room_name, multi_read_mode, card_timeout):
|
||||
"""
|
||||
Constructor
|
||||
:param app_name:
|
||||
:param app_owner:
|
||||
:param app_id:
|
||||
:param sonos_server_ip:
|
||||
:param sonos_server_port:
|
||||
:param room_name:
|
||||
:param multi_read_mode:
|
||||
:param card_timeout:
|
||||
@return app_name:
|
||||
@return app_owner:
|
||||
@return app_id:
|
||||
@return sonos_server_ip:
|
||||
@return sonos_server_port:
|
||||
@return room_name:
|
||||
@return multi_read_mode:
|
||||
@return card_timeout:
|
||||
"""
|
||||
|
||||
# Application owner info
|
||||
@@ -67,8 +67,8 @@ class AppConfig:
|
||||
def get_sonos_cmd(self, card_command):
|
||||
"""
|
||||
Get the sonos command from the card command
|
||||
:param card_command:
|
||||
:return:
|
||||
@return card_command:
|
||||
@return:
|
||||
"""
|
||||
|
||||
# Create address path
|
||||
@@ -87,7 +87,7 @@ class AppConfig:
|
||||
def print(self):
|
||||
"""
|
||||
Function that print the application config
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
|
||||
print("Application config:")
|
||||
|
||||
@@ -17,7 +17,7 @@ class Card:
|
||||
def print(self):
|
||||
"""
|
||||
Function that print a card parameters found from its id
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
|
||||
if self.parameters is not None:
|
||||
@@ -30,7 +30,7 @@ class Card:
|
||||
def get_command(self):
|
||||
"""
|
||||
Function that create the command from card parameters found from its id
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
|
||||
# This dict can be easily completed with more command
|
||||
@@ -57,7 +57,7 @@ class Card:
|
||||
def get_mode(self):
|
||||
"""
|
||||
Get the card mode or None if not found
|
||||
:return: the mode
|
||||
@return: the mode
|
||||
"""
|
||||
if self.parameters is not None:
|
||||
# Card found create the command line
|
||||
@@ -74,8 +74,8 @@ class Card:
|
||||
def has_mode(self, mode):
|
||||
"""
|
||||
Check if the card mode is the expected one
|
||||
:param mode: expected mode
|
||||
:return: True if exist, else otherwise
|
||||
@return mode: expected mode
|
||||
@return: True if exist, else otherwise
|
||||
"""
|
||||
|
||||
mode_exist = self.parameters.get("mode") == mode
|
||||
@@ -85,7 +85,7 @@ class Card:
|
||||
def is_command(self):
|
||||
"""
|
||||
Check if the card is a command card
|
||||
:return: True if the card is a command, else otherwise
|
||||
@return: True if the card is a command, else otherwise
|
||||
"""
|
||||
|
||||
return self.parameters.get("action") == "command"
|
||||
@@ -95,7 +95,7 @@ def main():
|
||||
"""
|
||||
For test purpose
|
||||
Quick card test
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
card_dict = dict(
|
||||
|
||||
@@ -22,9 +22,9 @@ class DbManager:
|
||||
def __init__(self, bdd_addr, bdd_name, path_to_key_file):
|
||||
"""
|
||||
Card reader constructor.
|
||||
:param bdd_addr:
|
||||
:param bdd_name:
|
||||
:param path_to_key_file:
|
||||
@return bdd_addr:
|
||||
@return bdd_name:
|
||||
@return path_to_key_file:
|
||||
"""
|
||||
|
||||
self.config_bdd_name = "config_" + bdd_name
|
||||
@@ -54,7 +54,7 @@ class DbManager:
|
||||
def update(self):
|
||||
"""
|
||||
Function that update the bdd from the cloud
|
||||
:return: nothing
|
||||
@return: nothing
|
||||
"""
|
||||
|
||||
self.config_db_python = self.config_db.get()
|
||||
@@ -63,7 +63,7 @@ class DbManager:
|
||||
def count_cards(self):
|
||||
"""
|
||||
Function that return the number of cards in th bdd
|
||||
:return: the number of cards
|
||||
@return: the number of cards
|
||||
"""
|
||||
|
||||
return self.cards_db_python.__len__()
|
||||
@@ -71,7 +71,7 @@ class DbManager:
|
||||
def count_configs(self):
|
||||
"""
|
||||
Function that return the number of configs in th bdd
|
||||
:return: the number of configs
|
||||
@return: the number of configs
|
||||
"""
|
||||
|
||||
return self.config_db_python.__len__()
|
||||
@@ -79,8 +79,8 @@ class DbManager:
|
||||
def get_card(self, card_id):
|
||||
"""
|
||||
Function that get a dict of a searched card
|
||||
:param card_id: searched card id
|
||||
:return: the searched Card or None
|
||||
@return card_id: searched card id
|
||||
@return: the searched Card or None
|
||||
"""
|
||||
|
||||
for _, card in self.cards_db_python.items():
|
||||
@@ -93,14 +93,14 @@ class DbManager:
|
||||
def write_card(self, ids, user, name, action, data, comment, mode):
|
||||
"""
|
||||
Function thar write a new card in the bdd
|
||||
:param ids:
|
||||
:param user:
|
||||
:param name:
|
||||
:param action:
|
||||
:param data:
|
||||
:param comment:
|
||||
:param mode:
|
||||
:return:
|
||||
@return ids:
|
||||
@return user:
|
||||
@return name:
|
||||
@return action:
|
||||
@return data:
|
||||
@return comment:
|
||||
@return mode:
|
||||
@return:
|
||||
"""
|
||||
|
||||
# TODO check if card already exist
|
||||
@@ -120,8 +120,8 @@ class DbManager:
|
||||
def get_config(self, application_id):
|
||||
"""
|
||||
Function that get searched configuration
|
||||
:param application_id: searched application id
|
||||
:return: the searched AppConfig or None
|
||||
@return application_id: searched application id
|
||||
@return: the searched AppConfig or None
|
||||
"""
|
||||
|
||||
for _, config in self.config_db_python.items():
|
||||
@@ -145,15 +145,15 @@ class DbManager:
|
||||
sonos_server_port, room_name, multi_read_mode, card_timeout):
|
||||
"""
|
||||
Function thar write a new card in the bdd
|
||||
:param app_name:
|
||||
:param app_id:
|
||||
:param app_owner:
|
||||
:param sonos_server_ip:
|
||||
:param sonos_server_port:
|
||||
:param room_name:
|
||||
:param multi_read_mode:
|
||||
:param card_timeout:
|
||||
:return:
|
||||
@return app_name:
|
||||
@return app_id:
|
||||
@return app_owner:
|
||||
@return sonos_server_ip:
|
||||
@return sonos_server_port:
|
||||
@return room_name:
|
||||
@return multi_read_mode:
|
||||
@return card_timeout:
|
||||
@return:
|
||||
"""
|
||||
|
||||
self.config_db.push({
|
||||
@@ -171,7 +171,7 @@ class DbManager:
|
||||
"""
|
||||
Function that clear the whole bdd given in argument
|
||||
DANGEROUS: for safety only matching bdd name can be deleted
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
if bdd_name == self.card_bdd_name:
|
||||
print("Delete database: " + bdd_name)
|
||||
@@ -186,7 +186,7 @@ class DbManager:
|
||||
"""
|
||||
Function that print the whole card bdd
|
||||
# todo make a print card ans print config
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
|
||||
for key, card in self.cards_db_python.items():
|
||||
|
||||
@@ -19,7 +19,7 @@ class DbReader:
|
||||
def __init__(self, bdd_addr, bdd_name):
|
||||
"""
|
||||
Card reader constructor.
|
||||
:param bdd_name:
|
||||
@return bdd_name:
|
||||
"""
|
||||
|
||||
self.config_bdd_name = "config_" + bdd_name
|
||||
@@ -37,7 +37,7 @@ class DbReader:
|
||||
def update(self):
|
||||
"""
|
||||
Function that update the bdd from the cloud
|
||||
:return: nothing
|
||||
@return: nothing
|
||||
"""
|
||||
|
||||
self.config_db_python = self.database.get('/' + self.config_bdd_name, None)
|
||||
@@ -46,7 +46,7 @@ class DbReader:
|
||||
def count_cards(self):
|
||||
"""
|
||||
Function that return the number of cards in th bdd
|
||||
:return: the number of cards
|
||||
@return: the number of cards
|
||||
"""
|
||||
|
||||
return self.cards_db_python.__len__()
|
||||
@@ -54,7 +54,7 @@ class DbReader:
|
||||
def count_configs(self):
|
||||
"""
|
||||
Function that return the number of configs in th bdd
|
||||
:return: the number of configs
|
||||
@return: the number of configs
|
||||
"""
|
||||
|
||||
return self.config_db_python.__len__()
|
||||
@@ -62,8 +62,8 @@ class DbReader:
|
||||
def get_card(self, card_id):
|
||||
"""
|
||||
Function that get a dict of a searched card
|
||||
:param card_id: searched card id
|
||||
:return: the searched Card or None
|
||||
@return card_id: searched card id
|
||||
@return: the searched Card or None
|
||||
"""
|
||||
|
||||
for _, card in self.cards_db_python.items():
|
||||
@@ -76,8 +76,8 @@ class DbReader:
|
||||
def get_config(self, application_id):
|
||||
"""
|
||||
Function that get searched configuration
|
||||
:param application_id: searched application id
|
||||
:return: the searched AppConfig or None
|
||||
@return application_id: searched application id
|
||||
@return: the searched AppConfig or None
|
||||
"""
|
||||
|
||||
for _, config in self.config_db_python.items():
|
||||
@@ -101,7 +101,7 @@ class DbReader:
|
||||
"""
|
||||
Function that print the whole card bdd
|
||||
# todo make a print card ans print config
|
||||
:return:
|
||||
@return:
|
||||
"""
|
||||
|
||||
for key, card in self.cards_db_python.items():
|
||||
|
||||
@@ -21,7 +21,7 @@ class CardsWrite(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Setup for all unit test
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
# Create real file path
|
||||
@@ -78,7 +78,7 @@ class CardsWrite(unittest.TestCase):
|
||||
def test_read_card(self):
|
||||
"""
|
||||
Test card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
|
||||
card_expected = {"user": "user5",
|
||||
@@ -96,7 +96,7 @@ class CardsWrite(unittest.TestCase):
|
||||
def test_read_card_command(self):
|
||||
"""
|
||||
Test all command card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
|
||||
command_expected = "data1"
|
||||
|
||||
@@ -20,7 +20,7 @@ class DatabaseReadTest(unittest.TestCase):
|
||||
def setUpClass(cls):
|
||||
"""
|
||||
Setup for all unit test
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
# Create the database handler
|
||||
@@ -32,7 +32,7 @@ class DatabaseReadTest(unittest.TestCase):
|
||||
def test_read_card(self):
|
||||
"""
|
||||
Test card read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
|
||||
card_expected = {"user": "user",
|
||||
@@ -50,7 +50,7 @@ class DatabaseReadTest(unittest.TestCase):
|
||||
def test_read_config(self):
|
||||
"""
|
||||
Test config read on production database
|
||||
:return
|
||||
@return
|
||||
"""
|
||||
|
||||
card_expected = {"app_name": "For test purpose",
|
||||
|
||||
@@ -48,7 +48,7 @@ class Reader:
|
||||
Function to read the cards.
|
||||
It concatenate all characters until finding 'KEY_ENTER'
|
||||
The final word is returned
|
||||
:return: card key as string
|
||||
@return: card key as string
|
||||
"""
|
||||
keys_input = ''
|
||||
key = ''
|
||||
|
||||
@@ -28,4 +28,3 @@ with open(FILE_PATH, 'w') as file_handler:
|
||||
file_handler.close()
|
||||
|
||||
print("Device name saved in: " + FILE_PATH)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class Reader:
|
||||
Function to read the cards.
|
||||
It concatenate all characters until finding 'KEY_ENTER'
|
||||
The final word is returned
|
||||
:return: card key as string
|
||||
@return: card key as string
|
||||
"""
|
||||
|
||||
keys_input = input('Card id: ')
|
||||
|
||||
@@ -8,7 +8,7 @@ Module containing useful tools
|
||||
def print_my_path():
|
||||
"""
|
||||
For debug purpose, print path
|
||||
:return: None
|
||||
@return: None
|
||||
"""
|
||||
from os import path, getcwd
|
||||
print('DEBUG: cwd: {}'.format(getcwd()))
|
||||
@@ -19,7 +19,7 @@ def print_my_path():
|
||||
def get_linux_serial() -> str:
|
||||
"""
|
||||
Extract serial from raspberry pi cpuinfo file
|
||||
:return: serial as string
|
||||
@return: serial as string
|
||||
"""
|
||||
serial = "0000000000000000"
|
||||
try:
|
||||
@@ -37,7 +37,7 @@ def get_win_serial() -> str:
|
||||
"""
|
||||
Extract serial from windows pc
|
||||
TODO not doing anything for now, for test purpose allowing to run on personal computer.
|
||||
:return: serial as string
|
||||
@return: serial as string
|
||||
"""
|
||||
# serial = "000000TEST000000"
|
||||
serial = "000000008e3c2b91"
|
||||
|
||||
Reference in New Issue
Block a user