oin/oin_thermostat/__main__.py

41 lines
844 B
Python

import logging
import sys
import tomllib
from .mqtt import HAClient
logger = logging.getLogger(__name__)
config_path = "config.toml"
def main() -> int:
with open(config_path, "rb") as config_file:
config = tomllib.load(config_file)
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}")
return 1
client = HAClient(
ha_config.get("entity"),
ha_config.get("secondary_entities"),
mqtt_config=ha_config.get("mqtt"),
)
code = client.connect()
if code != 0:
return 1
code = client.loop()
if code != 0:
return 1
return 0
if __name__ == "__main__":
sys.exit(main())