Docstrings for mapid.py

This commit is contained in:
Malte Bublitz 2023-10-26 15:32:53 +02:00
parent c4f3d29be0
commit 23195805be
Signed by: malte70
GPG Key ID: 605DA5C729F9C184
1 changed files with 24 additions and 0 deletions

View File

@ -1,3 +1,8 @@
"""MAPID utility library.
This module contains an utility class to control MAPID/CP using pyserial.
"""
import os
import time
import dotenv #
@ -5,8 +10,15 @@ import serial
DOTENV_LOADED = False
"""bool: Is .env loaded?
Prevents loading .env multiple times for speed.
"""
def load_dotenv():
"""Load .env file
"""
basedir = os.path.abspath(os.path.dirname(__file__))
dotenv.load_dotenv(os.path.join(basedir, ".env"))
global DOTENV_LOADED
@ -14,6 +26,12 @@ def load_dotenv():
def get_serial_dev():
"""Get SERIAL_DEV setting from dotenv.
Returns:
str: The device file.
"""
global DOTENV_LOADED
if not DOTENV_LOADED:
load_dotenv()
@ -21,6 +39,12 @@ def get_serial_dev():
def get_serial_speed():
"""Get SERIAL_SPEED setting from dotenv.
Returns:
int: Serial speed in baud.
"""
global DOTENV_LOADED
if not DOTENV_LOADED:
load_dotenv()