Skip to content

Latest commit

 

History

History
59 lines (50 loc) · 4.5 KB

commented_code_map.md

File metadata and controls

59 lines (50 loc) · 4.5 KB

Code and command map

Python3-MQTT-To-HomeAssistant.py

Function or value What it does and why
__version__ Declares the current app version; argparse and the build recipe use the same value.
CustomLogger.__init__ Sets up console logging and optional file logging so messages remain visible when file logging is disabled.
setup_logger Creates separate normal/error loggers and timestamped file paths, respecting LogDestination=No.
mqtt_connect Handles the MQTT connection result, publishes the configured retained message after connection, and disconnects.
get_newest_files Finds the latest normal/error log files for optional email attachments.
send_mail Invokes the system mail program with a subject, recipient, body, and optional attachment paths; returns its status and stderr.
MailTo Collects enabled log contents and attachments and sends the success/error notification.
WasMailSent Reports the external mail program's success or failure through the configured loggers.
SystemAction Runs the explicitly configured post-run shell command; delays when mail is enabled. Keep the setting No to disable it.
print_separator Makes log sections readable through the normal or error logger.
main Parses CLI flags, reads all 12 config settings, prepares logging and MQTT, optionally sends email/runs a system action, and removes an empty error log. The MQTT client explicitly selects the legacy callback API supported by the pinned Paho 2.x package.
Main guard Runs main() only when this file or its frozen executable is the entry point.

The existing MQTT flow publishes configured retained data before entering the network loop and again from its connection callback. The packaging change preserves this behavior. It does not add a dry-run mode or change delivery/error semantics.

build.py

Function or value What it does and why
PROJECT_ROOT, SOURCE_NAME Locate the project and entry point independent of the caller's working directory.
application_version Reads the version assignment with AST parsing without running application code or connecting to services.
file_sha256 Hashes source and output files for integrity checks and provenance.
build Requires Linux, a venv and compatible Python, reads installed dependency versions, stages application source and upstream notices, runs one-file PyInstaller in temporary storage, verifies help/version, and writes the binary checksum and a manifest without personal build paths.
main Provides --help, --version, and --output-dir; reports a nonzero result if packaging or checks fail.
Main guard Calls the build CLI only when the file is run directly.

Commands

Command Purpose
python3 -m venv .venv Creates an isolated build/runtime Python environment.
source .venv/bin/activate Selects that environment for subsequent Python and pip commands.
python -m pip install -r dependencies.txt Installs the pinned runtime and PyInstaller build dependencies.
python -m pip check Checks installed dependency compatibility.
python build.py [--output-dir DIRECTORY] Builds the native Linux executable and checks its informational flags.
python build.py --help / --version Shows the build options or matching application version without building.
python Python3-MQTT-To-HomeAssistant.py --help / --version Shows application flags or version without reading config or running actions.
python Python3-MQTT-To-HomeAssistant.py -c Message.cfg Runs the source entry point using the external configuration.
./bin/Python3-MQTT-To-HomeAssistant-0.0.1-linux-x86_64 --config Message.cfg Runs the bundled app without a separate Python/venv installation.
sha256sum -c NAME.sha256 Checks an executable against its checksum from the containing directory.
deactivate Leaves the activated venv.

Configuration and other files

Message-Example.cfg retains all 12 supported keys, documented in README. HomeAssistant-Configuration-For-MQTT.yaml defines the matching example sensor, state/availability topics, and payloads. .gitignore protects local configs/logs and excludes temporary build/venv files while allowing final bin/ artifacts. dependencies.txt pins runtime/build packages; versioning.md records changes. licenses/ preserves third-party package/system-library notices and is embedded as data in the executable; it does not change this project's license.