-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial support for multiple printers
- Loading branch information
1 parent
5221bab
commit fbac3ef
Showing
4 changed files
with
314 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
|
||
from dotenv import dotenv_values | ||
|
||
# List of valid config options | ||
options = [ | ||
"PHOMEMO_BT_MAC", | ||
"PHOMEMO_PAPER_SIZE" | ||
] | ||
|
||
# Load config values from .env and environment variables | ||
# Note: This reads all environment variables | ||
config = { | ||
**dotenv_values(".env"), | ||
**os.environ | ||
} | ||
|
||
# Set None as default for unset options | ||
for key in options: | ||
if key not in config: | ||
config[key] = None | ||
|
||
# Filter only desired config options | ||
config = {key: config[key] for key in options if key in config} | ||
|
||
printers = [] | ||
|
||
if config["PHOMEMO_BT_MAC"]: | ||
for printer in config["PHOMEMO_BT_MAC"].split(","): | ||
printer_kv = printer.split("=", 1) | ||
|
||
if len(printer_kv) == 1: | ||
printer_name = printer | ||
printer_value = printer | ||
else: | ||
printer_name = printer_kv[0] | ||
printer_value = printer_kv[1] | ||
|
||
printers.append({"name": printer_name, "address": printer_value}) | ||
|
||
# Store config in globals | ||
globals().update(**config) |
Oops, something went wrong.