lightrix/test-client.py

35 lines
982 B
Python
Raw Permalink Normal View History

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