forked from escalate/python-loxone-ws-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
executable file
·38 lines (29 loc) · 1.18 KB
/
run.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import logging
from os import environ
from autobahn.asyncio.websocket import WebSocketClientFactory
from loxone_websocket_client import ClientProtocol
from loxone_websocket_client import LoxProtocol
_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
MINISERVER_HOST = environ.get('MINISERVER_HOST', '127.0.0.1')
MINISERVER_PORT = environ.get('MINISERVER_PORT', 80)
MINISERVER_USERNAME = environ.get('MINISERVER_USERNAME', 'admin')
MINISERVER_PASSWORD = environ.get('MINISERVER_PASSWORD', 'admin')
if __name__ == '__main__':
_LOGGER.info('Start WebSocket connection')
ws_factory = WebSocketClientFactory('ws://{host}:{port}/ws/rfc6455'.format(
host=MINISERVER_HOST,
port=MINISERVER_PORT),
protocols=['remotecontrol'])
#ws_factory.protocol = ClientProtocol
ws_factory.protocol = LoxProtocol
ws_factory.username = MINISERVER_USERNAME
ws_factory.password = MINISERVER_PASSWORD
loop = asyncio.get_event_loop()
coro = loop.create_connection(ws_factory, MINISERVER_HOST, MINISERVER_PORT)
loop.run_until_complete(coro)
loop.run_forever()
loop.close()