oin/oin_thermostat/__main__.py

42 lines
844 B
Python
Raw Permalink Normal View History

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"
2024-12-09 12:16:26 +01:00
def main() -> int:
2024-12-08 11:17:25 +01:00
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}")
2024-12-09 12:16:26 +01:00
return 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
)
2024-12-09 12:16:26 +01:00
code = client.connect()
if code != 0:
return 1
2024-12-07 15:22:08 +01:00
2024-12-09 12:16:26 +01:00
code = client.loop()
if code != 0:
return 1
return 0
2024-12-08 11:17:25 +01:00
if __name__ == "__main__":
2024-12-09 12:16:26 +01:00
sys.exit(main())