From a08539d88d7f15ecc9a0435ecd84d1c2861b83dd Mon Sep 17 00:00:00 2001 From: martinfrancois Date: Thu, 2 Mar 2017 09:10:49 +0100 Subject: [PATCH] Added support for multiple codes executed in a row (#5908) * Added support for multiple codes executed in a row now codes can be specified either by simply providing a single code, which will then be sent like usual, or multiple codes can be executed in a row, specified in a comma delimited format in the configuration.yaml. For example: 111111,222222,333333,444444 would mean 111111 would be sent first, followed by 222222 and 333333 and 444444. * rpi_rf: added line breaks to not exceed 79 characters per line * include validation for correct formatting of codes added regex which only allows either a single number (like 1252456245) or a sequence of commas followed by another number. * added line breaks to not exceed 79 characters per line * fix for 'continuation line under-indented for visual indent' * another try at 'continuation line under-indented for visual indent' * changed from regex to list for easier maintainability * removed unnecessary splitting of strings --- homeassistant/components/switch/rpi_rf.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/switch/rpi_rf.py b/homeassistant/components/switch/rpi_rf.py index 866fea0df0b..0a6d487c331 100644 --- a/homeassistant/components/switch/rpi_rf.py +++ b/homeassistant/components/switch/rpi_rf.py @@ -27,8 +27,10 @@ DEFAULT_PROTOCOL = 1 DEFAULT_SIGNAL_REPETITIONS = 10 SWITCH_SCHEMA = vol.Schema({ - vol.Required(CONF_CODE_OFF): cv.positive_int, - vol.Required(CONF_CODE_ON): cv.positive_int, + vol.Required(CONF_CODE_OFF): + vol.All(cv.ensure_list_csv, [cv.positive_int]), + vol.Required(CONF_CODE_ON): + vol.All(cv.ensure_list_csv, [cv.positive_int]), vol.Optional(CONF_PULSELENGTH): cv.positive_int, vol.Optional(CONF_SIGNAL_REPETITIONS, default=DEFAULT_SIGNAL_REPETITIONS): cv.positive_int, @@ -101,13 +103,12 @@ class RPiRFSwitch(SwitchDevice): """Return true if device is on.""" return self._state - def _send_code(self, code, protocol, pulselength): - """Send the code with a specified pulselength.""" - _LOGGER.info("Sending code: %s", code) - res = self._rfdevice.tx_code(code, protocol, pulselength) - if not res: - _LOGGER.error("Sending code %s failed", code) - return res + def _send_code(self, code_list, protocol, pulselength): + """Send the code(s) with a specified pulselength.""" + _LOGGER.info("Sending code(s): %s", code_list) + for code in code_list: + self._rfdevice.tx_code(code, protocol, pulselength) + return True def turn_on(self): """Turn the switch on."""