From 13dd17b2abf84d6b89e58e31582c0834dfd9bfbc Mon Sep 17 00:00:00 2001 From: Martin Hjelmare Date: Sat, 11 Mar 2017 03:30:23 +0100 Subject: [PATCH] Fix mysensors gateway windows setup (#6500) --- homeassistant/components/mysensors.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/mysensors.py b/homeassistant/components/mysensors.py index 14ef4f10864..7051dc732c8 100644 --- a/homeassistant/components/mysensors.py +++ b/homeassistant/components/mysensors.py @@ -165,18 +165,22 @@ def setup(hass, config): out_prefix=out_prefix, retain=retain) else: try: - socket.getaddrinfo(device, None) - # valid ip address - gateway = mysensors.TCPGateway( - device, event_callback=None, persistence=persistence, - persistence_file=persistence_file, - protocol_version=version, port=tcp_port) - except OSError: - # invalid ip address + is_serial_port(device) gateway = mysensors.SerialGateway( device, event_callback=None, persistence=persistence, persistence_file=persistence_file, protocol_version=version, baud=baud_rate) + except vol.Invalid: + try: + socket.getaddrinfo(device, None) + # valid ip address + gateway = mysensors.TCPGateway( + device, event_callback=None, persistence=persistence, + persistence_file=persistence_file, + protocol_version=version, port=tcp_port) + except OSError: + # invalid ip address + return gateway.metric = hass.config.units.is_metric gateway.debug = config[DOMAIN].get(CONF_DEBUG) optimistic = config[DOMAIN].get(CONF_OPTIMISTIC)