2024-12-07 15:22:08 +01:00
|
|
|
import logging
|
2024-12-08 11:17:25 +01:00
|
|
|
import sys
|
2024-12-08 10:43:31 +01:00
|
|
|
import tomllib
|
2024-12-07 15:22:08 +01:00
|
|
|
|
|
|
|
from .mqtt import HAClient
|
|
|
|
|
2024-12-08 11:17:25 +01:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
config_path = "config.toml"
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
with open(config_path, "rb") as config_file:
|
2024-12-08 10:43:31 +01:00
|
|
|
config = tomllib.load(config_file)
|
|
|
|
|
2024-12-08 11:17:25 +01:00
|
|
|
logging.basicConfig(**config.get("logging", dict()))
|
|
|
|
|
|
|
|
ha_config = config.get("homeassistant")
|
|
|
|
if ha_config is None:
|
|
|
|
logger.error(f"Missing home assistant config in <{config_path}>")
|
|
|
|
logger.error(f"\t{config}")
|
|
|
|
sys.exit(1)
|
2024-12-07 15:22:08 +01:00
|
|
|
|
|
|
|
client = HAClient(
|
2024-12-08 11:17:25 +01:00
|
|
|
ha_config.get("entity"),
|
|
|
|
ha_config.get("secondary_entities"),
|
|
|
|
mqtt_config=ha_config.get("mqtt"),
|
2024-12-07 15:22:08 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
client.connect()
|
|
|
|
|
|
|
|
client.loop()
|
2024-12-08 11:17:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|