Skip to content

Commit

Permalink
rebased to 0.11, configuration and HA component for proxy_ip
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Jul 4, 2019
1 parent fed7b8e commit b254062
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The configuration file can contain three sections.
- `gateway_ip` (required) sets the ip address of the KNX tunneling interface
- `gateway_port` (optional) sets the port the KNX tunneling interface is listening on
- `local_ip` (optional) sets the ip address that is used by xknx
- `proxy_ip` (optional) for a connection routed through a proxy (eg. NAT or Docker)
- `routing` for a UDP multicast connection
- `local_ip` (optional) sets the ip address that is used by xknx
- Within the `groups` sections all devices are defined. For each type of device more then one section might be specified. You need to append numbers or strings to differentiate the entries, as in the example below. The appended number or string must be unique.
Expand Down
1 change: 1 addition & 0 deletions examples/example_tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def main():
xknx,
src_address,
local_ip=gateway.local_ip,
local_port=0,
gateway_ip=gateway.ip_addr,
gateway_port=gateway.port)

Expand Down
6 changes: 5 additions & 1 deletion home-assistant-plugin/custom_components/xknx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
CONF_XKNX_ROUTING = "routing"
CONF_XKNX_TUNNELING = "tunneling"
CONF_XKNX_LOCAL_IP = "local_ip"
CONF_XKNX_PROXY_IP = "proxy_ip"
CONF_XKNX_FIRE_EVENT = "fire_event"
CONF_XKNX_FIRE_EVENT_FILTER = "fire_event_filter"
CONF_XKNX_STATE_UPDATER = "state_updater"
Expand All @@ -38,6 +39,7 @@
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_XKNX_LOCAL_IP): cv.string,
vol.Optional(CONF_PORT): cv.port,
vol.Optional(CONF_XKNX_PROXY_IP): cv.string,
})

ROUTING_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -191,11 +193,13 @@ def connection_config_tunneling(self):
self.config[DOMAIN][CONF_XKNX_TUNNELING].get(CONF_PORT)
local_ip = \
self.config[DOMAIN][CONF_XKNX_TUNNELING].get(CONF_XKNX_LOCAL_IP)
proxy_ip = \
self.config[DOMAIN][CONF_XKNX_TUNNELING].get(CONF_XKNX_PROXY_IP)
if gateway_port is None:
gateway_port = DEFAULT_MCAST_PORT
return ConnectionConfig(
connection_type=ConnectionType.TUNNELING, gateway_ip=gateway_ip,
gateway_port=gateway_port, local_ip=local_ip)
gateway_port=gateway_port, local_ip=local_ip, proxy_ip=proxy_ip)

def connection_config_auto(self):
"""Return the connection_config if auto is configured."""
Expand Down
4 changes: 1 addition & 3 deletions home-assistant-plugin/custom_components/xknx/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"domain": "xknx",
"name": "Knx",
"documentation": "https://www.home-assistant.io/components/knx",
"requirements": [
"xknx==0.10.0"
],
"requirements": [],
"dependencies": [],
"codeowners": [
"@Julius2342"
Expand Down
9 changes: 6 additions & 3 deletions test/io_tests/connect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def test_connect(self):
def test_proxy_connect(self):
"""Test connecting to KNX bus via proxy."""
xknx = XKNX(loop=self.loop)
udp_client = UDPClient(xknx, ("172.20.0.2", 0), ("192.168.1.5", 1234))
proxy_ip = "192.168.1.10"
connect = Connect(xknx, udp_client, proxy_ip)
udp_client = UDPClient(
xknx,
("172.20.0.2", 0),
("192.168.1.5", 1234),
proxy_addr=("192.168.1.10", 4321))
connect = Connect(xknx, udp_client)
connect.timeout_in_seconds = 0

self.assertEqual(connect.awaited_response_class, ConnectResponse)
Expand Down
2 changes: 2 additions & 0 deletions xknx/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def _parse_connection_prefs(self, conn_type: ConnectionType, prefs) -> None:
connection_config.gateway_port = value
elif pref == "local_ip":
connection_config.local_ip = value
elif pref == "proxy_ip":
connection_config.proxy_ip = value
self.xknx.connection_config = connection_config

def parse_groups(self, doc):
Expand Down
7 changes: 5 additions & 2 deletions xknx/io/knxip_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ConnectionConfig:
* local_port: Local port the interface should listen to.
* gateway_ip: IP of KNX/IP tunneling device.
* gateway_port: Port of KNX/IP tunneling device.
* proxy_ip: For TUNNELING connection through a proxy (eg. NAT).
* auto_reconnect: Auto reconnect to KNX/IP tunneling device if connection cannot be established.
* auto_reconnect_wait: Wait n seconds before trying to reconnect to KNX/IP tunneling device.
* scan_filter: For AUTOMATIC connection, limit scan with the given filter
Expand Down Expand Up @@ -142,9 +143,11 @@ async def start_tunnelling(self, local_ip, local_port, gateway_ip, gateway_port,
validate_ip(local_ip, address_name="Local IP address")
if proxy_ip is not None:
validate_ip(proxy_ip, address_name="Proxy IP address")
self.xknx.logger.debug("Starting tunnel from %s:%s over %s to %s:%s", local_ip, local_port, proxy_ip, gateway_ip, gateway_port)
self.xknx.logger.debug("Starting tunnel from %s:%s over %s to %s:%s",
local_ip, local_port, proxy_ip, gateway_ip, gateway_port)
else:
self.xknx.logger.debug("Starting tunnel from %s:%s to %s:%s", local_ip, local_port, gateway_ip, gateway_port)
self.xknx.logger.debug("Starting tunnel from %s:%s to %s:%s",
local_ip, local_port, gateway_ip, gateway_port)
self.interface = Tunnel(
self.xknx,
self.xknx.own_address,
Expand Down
2 changes: 1 addition & 1 deletion xknx/io/tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Tunnel():
# pylint: disable=too-many-instance-attributes

def __init__(self, xknx, src_address, local_ip, local_port, gateway_ip, gateway_port,
proxy_ip, telegram_received_callback=None, auto_reconnect=False,
proxy_ip=None, telegram_received_callback=None, auto_reconnect=False,
auto_reconnect_wait=3):
"""Initialize Tunnel class."""
# pylint: disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion xknx/io/udp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class UDPClient:
"""Class for handling (sending and receiving) UDP packets."""

# pylint: disable=too-few-public-methods
# pylint: disable=too-few-public-methods, too-many-instance-attributes

class Callback:
"""Callback class for handling callbacks for different 'KNX service types' of received packets."""
Expand Down

0 comments on commit b254062

Please sign in to comment.