Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ python3 -m pip install Twisted
python3 -m pip install autobahn[twisted]
```

### Install optional dependencies
For connecting via SSL
```
python3 -m pip install pyOpenSSL
```

### Configure Kivy
Edit file `/home/pi/.kivy/config.ini`

Expand Down
14 changes: 11 additions & 3 deletions core/connectors/homeassistant.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
import json
import time
from kivy.support import install_twisted_reactor

install_twisted_reactor()
from autobahn.twisted.websocket import WebSocketClientProtocol, \
WebSocketClientFactory
WebSocketClientFactory, \
connectWS
from twisted.internet import reactor


Expand Down Expand Up @@ -43,7 +45,8 @@ class HAClientFactory(WebSocketClientFactory):
protocol = HAClientProtocol

def __init__(self, config, handler):
url = 'ws://' + config['host'] + ':' + str(config['port']) + '/api/websocket'
use_ssl = config.get('use_ssl', False)
url = ('wss://' if use_ssl else 'ws://') + config['host'] + ':' + str(config['port']) + '/api/websocket'
WebSocketClientFactory.__init__(self, url)

self.handler = handler
Expand All @@ -61,7 +64,12 @@ def __init__(self, app, config):

def connect_to_server(self):
self._factory = HAClientFactory(self.config, self)
reactor.connectTCP(self.config['host'], self.config['port'], self._factory)
ctxFactory = None
if self._factory.isSecure:
from twisted.internet import ssl
ctxFactory = ssl.ClientContextFactory()

connectWS(self._factory, ctxFactory)

def send_message(self, msg):
proto = self._factory._proto
Expand Down