Skip to content

Commit 391a2e8

Browse files
authored
Add support got signum ip to velbus gateway (#68)
* Add support for tls connection to signum * Update with port formats * update README * Black format * More format fixes * More format fixes * More format fixes * Add 3.9 to pytest * More formatting
1 parent 9ede698 commit 391a2e8

File tree

4 files changed

+23
-35
lines changed

4 files changed

+23
-35
lines changed

.github/workflows/pythonTest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: [ '2.7', '3.6', '3.7', '3.8' ]
16+
python-version: [ '2.7', '3.6', '3.7', '3.8', '3.9' ]
1717
name: Python ${{ matrix.python-version }} test
1818
steps:
1919
- name: Checkout

README.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,12 @@ I would like to extend this module to support all Velbus modules, so feel free t
1010

1111
API documentation is available [here](http://python-velbus.readthedocs.io/en/latest/)
1212

13-
# Example usage
13+
# Port format
1414

15-
The library currently only supports a serial connection to the Velbus controller (either through USB module or through RS-232 interface). In order to use the library, you need to first initialize the controller and can then send and receive messages on the Velbus. The library currently does not validate if a message is supported by a certain module (e.g., you can send a blind up message to a relay)
16-
17-
```python
18-
import velbus
19-
import time
20-
21-
# serial (or USB over serial) device connected to Velbus controller
22-
port = "/dev/ttyACM0"
23-
24-
connection = velbus.VelbusUSBConnection(port)
25-
controller = velbus.Controller(connection)
26-
controller.subscribe(_on_message)
27-
28-
# set module address
29-
module_address = 0xdc
30-
message = velbus.SwitchRelayOnMessage(module_address)
31-
32-
channel_number = 1
33-
34-
message.relay_channels = [channel_number]
35-
36-
controller.send(message)
37-
38-
def _on_message(received_message):
39-
print("Velbus message received")
40-
print(received_message.address)
41-
42-
time.sleep(5)
43-
44-
connection.stop()
45-
```
15+
There are 3 possible port formats:
16+
- /dev/ttyACME0 = A direct connection to a serial device (for vmbusb for example)
17+
- ip:port = A connection to a TCP/IP port
18+
- tls://signum ip:27015 = A connection to a signum ip
4619

4720
# Installation
4821

velbus/connections/socket.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import time
55
import threading
66
import logging
7+
import ssl
78
from queue import Queue
89
import socket
910
from velbus.connections.connection import VelbusConnection
@@ -18,7 +19,7 @@ class SocketConnection(VelbusConnection):
1819
:author: Maikel Punie <maikel.punie@gmail.com>
1920
"""
2021

21-
def __init__(self, device, controller=None):
22+
def __init__(self, device, controller=None, tls=False):
2223
VelbusConnection.__init__(self)
2324
self.logger = logging.getLogger("velbus")
2425
self._device = device
@@ -28,6 +29,12 @@ def __init__(self, device, controller=None):
2829
addr = (addr[0], int(addr[1]))
2930
try:
3031
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32+
if tls:
33+
ctx = ssl._create_unverified_context()
34+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
35+
self._socket = ctx.wrap_socket(sock)
36+
else:
37+
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3138
self._socket.connect(addr)
3239
except Exception:
3340
self.logger.error(

velbus/controller.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def __init__(self, port):
3838
self._modules = {}
3939
self._loadModuleData()
4040
if ":" in port:
41-
self.connection = SocketConnection(port, self)
41+
print(port)
42+
if port.startswith("tls://"):
43+
print("tls")
44+
print(port.replace("tls://", ""))
45+
self.connection = SocketConnection(
46+
port.replace("tls://", ""), self, True
47+
)
48+
else:
49+
self.connection = SocketConnection(port, self, False)
4250
else:
4351
self.connection = VelbusUSBConnection(port, self)
4452

0 commit comments

Comments
 (0)