janet/janet/app.py

38 lines
866 B
Python
Raw Permalink Normal View History

2021-02-14 17:31:28 +01:00
import threading
import time
from typing import Optional
2021-02-14 17:31:28 +01:00
import click
import prometheus_client
2021-02-14 17:31:28 +01:00
2021-02-26 16:46:54 +01:00
from . import bravia, mqtt, prometheus, ssdp
2021-02-14 17:31:28 +01:00
2021-02-21 13:39:50 +01:00
@click.command()
@click.option('--mqtt-host', type=str, help='MQTT host name', required=True)
@click.option('--prometheus-port', type=int, help='Prometheus metrics port')
2021-03-21 13:42:25 +01:00
def main(mqtt_host: str, prometheus_port: Optional[int]):
if prometheus_port:
prometheus_client.start_http_server(prometheus_port)
2021-02-14 17:31:28 +01:00
prom = prometheus.Client()
2021-02-21 13:39:50 +01:00
mq = mqtt.Client(mqtt_host)
2021-02-14 17:31:28 +01:00
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()