Expose baud rate config for mysensors component

pull/1197/head
Riccardo Massari 2016-02-10 21:24:18 +01:00 committed by Riccardo Massari
parent 70a528c04b
commit c705ca4288
1 changed files with 7 additions and 3 deletions

View File

@ -24,7 +24,9 @@ CONF_DEBUG = 'debug'
CONF_PERSISTENCE = 'persistence' CONF_PERSISTENCE = 'persistence'
CONF_PERSISTENCE_FILE = 'persistence_file' CONF_PERSISTENCE_FILE = 'persistence_file'
CONF_VERSION = 'version' CONF_VERSION = 'version'
CONF_BAUD_RATE = 'baud_rate'
DEFAULT_VERSION = '1.4' DEFAULT_VERSION = '1.4'
DEFAULT_BAUD_RATE = 115200
DOMAIN = 'mysensors' DOMAIN = 'mysensors'
DEPENDENCIES = [] DEPENDENCIES = []
@ -60,12 +62,13 @@ def setup(hass, config):
version = str(config[DOMAIN].get(CONF_VERSION, DEFAULT_VERSION)) version = str(config[DOMAIN].get(CONF_VERSION, DEFAULT_VERSION))
is_metric = (hass.config.temperature_unit == TEMP_CELCIUS) is_metric = (hass.config.temperature_unit == TEMP_CELCIUS)
def setup_gateway(port, persistence, persistence_file, version): def setup_gateway(port, persistence, persistence_file, version, baud_rate):
"""Return gateway after setup of the gateway.""" """Return gateway after setup of the gateway."""
gateway = mysensors.SerialGateway(port, event_callback=None, gateway = mysensors.SerialGateway(port, event_callback=None,
persistence=persistence, persistence=persistence,
persistence_file=persistence_file, persistence_file=persistence_file,
protocol_version=version) protocol_version=version,
baud=baud_rate)
gateway.metric = is_metric gateway.metric = is_metric
gateway.debug = config[DOMAIN].get(CONF_DEBUG, False) gateway.debug = config[DOMAIN].get(CONF_DEBUG, False)
gateway = GatewayWrapper(gateway, version) gateway = GatewayWrapper(gateway, version)
@ -98,8 +101,9 @@ def setup(hass, config):
persistence_file = gway.get( persistence_file = gway.get(
CONF_PERSISTENCE_FILE, CONF_PERSISTENCE_FILE,
hass.config.path('mysensors{}.pickle'.format(index + 1))) hass.config.path('mysensors{}.pickle'.format(index + 1)))
baud_rate = gway.get(CONF_BAUD_RATE, DEFAULT_BAUD_RATE)
GATEWAYS[port] = setup_gateway( GATEWAYS[port] = setup_gateway(
port, persistence, persistence_file, version) port, persistence, persistence_file, version, baud_rate)
for (component, discovery_service) in DISCOVERY_COMPONENTS: for (component, discovery_service) in DISCOVERY_COMPONENTS:
# Ensure component is loaded # Ensure component is loaded