-
Notifications
You must be signed in to change notification settings - Fork 22
/
connector.py
executable file
·53 lines (41 loc) · 1.48 KB
/
connector.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
import logging
import os
from handler.event import EventHandler
from helper.config import Config
from helper.discovery import ChromecastDiscovery
from time import sleep
from helper.mqtt import MqttConnection
logging.basicConfig(level=logging.DEBUG)
logging.getLogger("pychromecast").setLevel(logging.DEBUG)
logging.getLogger("pychromecast.socket_client").setLevel(logging.INFO)
logger = logging.getLogger(__name__)
logger.debug("~ reading config")
config_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'config.ini')
config = Config(config_path)
event_handler = EventHandler()
logger.debug("~ connecting to mqtt")
username = None
password = None
if config.get_mqtt_broker_use_auth():
logger.debug("~ using username and password to connect to mqtt")
username = config.get_mqtt_broker_username()
password = config.get_mqtt_broker_password()
mqtt = MqttConnection(config.get_mqtt_broker_address(), config.get_mqtt_broker_port(), username, password,
event_handler)
if not mqtt.start_connection():
exit(1)
logger.debug("~ starting chromecast discovery")
discovery = ChromecastDiscovery(event_handler)
discovery.start_discovery()
logger.debug("~ initialization finished")
is_running = True
while is_running:
try:
sleep(1)
except KeyboardInterrupt:
is_running = False
logger.debug("~ stop signal received, shutting down")
discovery.stop_discovery()
mqtt.stop_connection()
logger.debug("~ shutdown completed")