Added support for multiple codes executed in a row ()

* 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
pull/6360/head
martinfrancois 2017-03-02 09:10:49 +01:00 committed by Paulus Schoutsen
parent bf7aecce90
commit a08539d88d
1 changed files with 10 additions and 9 deletions
homeassistant/components/switch

View File

@ -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."""