Allow connection to rfxtrx using tcp (#28297)

This commit is contained in:
foxy82 2019-11-20 02:11:17 +00:00 committed by Charles Garwood
parent 6db4e975e3
commit 9fd6afc5fb
4 changed files with 30 additions and 14 deletions

View file

@ -12,6 +12,8 @@ from homeassistant.const import (
ATTR_STATE,
CONF_DEVICE,
CONF_DEVICES,
CONF_HOST,
CONF_PORT,
EVENT_HOMEASSISTANT_START,
EVENT_HOMEASSISTANT_STOP,
POWER_WATT,
@ -80,17 +82,21 @@ RFX_DEVICES = {}
_LOGGER = logging.getLogger(__name__)
DATA_RFXOBJECT = "rfxobject"
CONFIG_SCHEMA = vol.Schema(
BASE_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
{
vol.Required(CONF_DEVICE): cv.string,
vol.Optional(CONF_DEBUG, default=False): cv.boolean,
vol.Optional(CONF_DUMMY, default=False): cv.boolean,
}
)
},
extra=vol.ALLOW_EXTRA,
vol.Optional(CONF_DEBUG, default=False): cv.boolean,
vol.Optional(CONF_DUMMY, default=False): cv.boolean,
}
)
DEVICE_SCHEMA = BASE_SCHEMA.extend({vol.Required(CONF_DEVICE): cv.string})
PORT_SCHEMA = BASE_SCHEMA.extend(
{vol.Required(CONF_PORT): cv.port, vol.Optional(CONF_HOST): cv.string}
)
CONFIG_SCHEMA = vol.Schema(
{DOMAIN: vol.Any(DEVICE_SCHEMA, PORT_SCHEMA)}, extra=vol.ALLOW_EXTRA
)
@ -115,7 +121,9 @@ def setup(hass, config):
for subscriber in RECEIVED_EVT_SUBSCRIBERS:
subscriber(event)
device = config[DOMAIN][ATTR_DEVICE]
device = config[DOMAIN].get(ATTR_DEVICE)
host = config[DOMAIN].get(CONF_HOST)
port = config[DOMAIN].get(CONF_PORT)
debug = config[DOMAIN][ATTR_DEBUG]
dummy_connection = config[DOMAIN][ATTR_DUMMY]
@ -123,6 +131,14 @@ def setup(hass, config):
rfx_object = rfxtrxmod.Connect(
device, None, debug=debug, transport_protocol=rfxtrxmod.DummyTransport2
)
elif port is not None:
# If port is set then we create a TCP connection
rfx_object = rfxtrxmod.Connect(
(host, port),
None,
debug=debug,
transport_protocol=rfxtrxmod.PyNetworkTransport,
)
else:
rfx_object = rfxtrxmod.Connect(device, None, debug=debug)

View file

@ -3,7 +3,7 @@
"name": "Rfxtrx",
"documentation": "https://www.home-assistant.io/integrations/rfxtrx",
"requirements": [
"pyRFXtrx==0.23"
"pyRFXtrx==0.24"
],
"dependencies": [],
"codeowners": [

View file

@ -1073,7 +1073,7 @@ pyHS100==0.3.5
pyMetno==0.4.6
# homeassistant.components.rfxtrx
pyRFXtrx==0.23
pyRFXtrx==0.24
# homeassistant.components.switchmate
# pySwitchmate==0.4.6

View file

@ -371,7 +371,7 @@ pyHS100==0.3.5
pyMetno==0.4.6
# homeassistant.components.rfxtrx
pyRFXtrx==0.23
pyRFXtrx==0.24
# homeassistant.components.nextbus
py_nextbusnext==0.1.4