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
This commit is contained in:
martinfrancois 2017-03-02 09:10:49 +01:00 committed by Paulus Schoutsen
parent bf7aecce90
commit a08539d88d

View file

@ -27,8 +27,10 @@ DEFAULT_PROTOCOL = 1
DEFAULT_SIGNAL_REPETITIONS = 10 DEFAULT_SIGNAL_REPETITIONS = 10
SWITCH_SCHEMA = vol.Schema({ SWITCH_SCHEMA = vol.Schema({
vol.Required(CONF_CODE_OFF): cv.positive_int, vol.Required(CONF_CODE_OFF):
vol.Required(CONF_CODE_ON): cv.positive_int, 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_PULSELENGTH): cv.positive_int,
vol.Optional(CONF_SIGNAL_REPETITIONS, vol.Optional(CONF_SIGNAL_REPETITIONS,
default=DEFAULT_SIGNAL_REPETITIONS): cv.positive_int, default=DEFAULT_SIGNAL_REPETITIONS): cv.positive_int,
@ -101,13 +103,12 @@ class RPiRFSwitch(SwitchDevice):
"""Return true if device is on.""" """Return true if device is on."""
return self._state return self._state
def _send_code(self, code, protocol, pulselength): def _send_code(self, code_list, protocol, pulselength):
"""Send the code with a specified pulselength.""" """Send the code(s) with a specified pulselength."""
_LOGGER.info("Sending code: %s", code) _LOGGER.info("Sending code(s): %s", code_list)
res = self._rfdevice.tx_code(code, protocol, pulselength) for code in code_list:
if not res: self._rfdevice.tx_code(code, protocol, pulselength)
_LOGGER.error("Sending code %s failed", code) return True
return res
def turn_on(self): def turn_on(self):
"""Turn the switch on.""" """Turn the switch on."""