Refactor configuration file loading to check multiple paths and raise error if not found
This commit is contained in:
parent
2042c413c7
commit
98e1e970c1
1 changed files with 13 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import tomllib
|
import tomllib
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from hasspy.mqtt import HassClient
|
from hasspy.mqtt import HassClient
|
||||||
|
|
||||||
|
@ -7,7 +8,18 @@ from hasspy.mqtt import HassClient
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
with open("/etc/hasspy/config.toml", "rb") as file:
|
config_file = next(
|
||||||
|
(
|
||||||
|
x
|
||||||
|
for x in (Path("/etc/hasspy.toml"), Path("/etc/hasspy/config.toml"))
|
||||||
|
if x.exists()
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
if not config_file:
|
||||||
|
raise FileNotFoundError("No configuration file found")
|
||||||
|
|
||||||
|
with open(config_file, "rb") as file:
|
||||||
config = tomllib.load(file)
|
config = tomllib.load(file)
|
||||||
|
|
||||||
ha = HassClient(
|
ha = HassClient(
|
||||||
|
|
Loading…
Add table
Reference in a new issue