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 stringspull/6360/head
parent
bf7aecce90
commit
a08539d88d
homeassistant/components/switch
|
@ -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."""
|
||||
|
|
Loading…
Reference in New Issue