lightrix/lightrix.py

35 lines
970 B
Python
Raw Permalink Normal View History

2016-03-13 00:54:23 -08:00
import lightrix.matrix as mc
import lightrix.patterns as lightrix
import lightrix.strip as strip
import click
2015-09-12 22:00:18 -07:00
import os
2016-03-13 00:54:23 -08:00
import sys
import yaml
2015-09-12 22:00:18 -07:00
2016-03-13 00:54:23 -08:00
@click.command()
@click.option('--config', '-c', default="~/.mcatrc", type=click.Path(exists=True))
@click.option('--room-id', '-r')
def start(config, room_id):
if room_id is None:
2015-09-12 22:00:18 -07:00
print("Require --room argument")
sys.exit(1)
2016-03-13 00:54:23 -08:00
if not os.path.exists(config):
2015-09-12 22:00:18 -07:00
print("Configuration file doesn't exist, please create one")
sys.exit(1)
2016-03-13 17:59:05 -07:00
led_count = 150
2016-03-13 00:54:23 -08:00
with open(config) as f:
conf = yaml.safe_load(f)
s = strip.Strip(count=led_count)
lx = lightrix.Lightrix(s)
client = mc.Client(conf['homeserver_uri'],
conf['username'], conf['password'],
room_id, strip=s)
lx.matrix = client
client.add_listener(lx.handler)
client.listen()
if __name__ == '__main__':
start()