38 lines
866 B
Python
38 lines
866 B
Python
import threading
|
|
import time
|
|
from typing import Optional
|
|
|
|
import click
|
|
import prometheus_client
|
|
|
|
from . import bravia, mqtt, prometheus, ssdp
|
|
|
|
|
|
@click.command()
|
|
@click.option('--mqtt-host', type=str, help='MQTT host name', required=True)
|
|
@click.option('--prometheus-port', type=int, help='Prometheus metrics port')
|
|
def main(mqtt_host: str, prometheus_port: Optional[int]):
|
|
if prometheus_port:
|
|
prometheus_client.start_http_server(prometheus_port)
|
|
prom = prometheus.Client()
|
|
mq = mqtt.Client(mqtt_host)
|
|
clients = (prom.publish, mq.publish)
|
|
|
|
s = ssdp.Discoverer()
|
|
for client in clients:
|
|
s.listen(client)
|
|
|
|
b = bravia.Discoverer()
|
|
s.listen(b.ssdp)
|
|
for client in clients:
|
|
b.listen(client)
|
|
|
|
threading.Thread(target=s.run).start()
|
|
|
|
while True:
|
|
time.sleep(1)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|