From 52c0b45f41696e2e2fd9b72a27c5976a05bc5cfb Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 16 Feb 2019 15:30:59 +0100 Subject: [PATCH] Add RC5 IR code support (#432) --- esphome/components/binary_sensor/remote_receiver.py | 11 +++++++++-- esphome/components/remote_receiver.py | 1 + esphome/components/switch/remote_transmitter.py | 11 +++++++++-- esphome/const.py | 1 + tests/test1.yaml | 5 +++++ 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/esphome/components/binary_sensor/remote_receiver.py b/esphome/components/binary_sensor/remote_receiver.py index d8a0e9cc9b..1089eb4da4 100644 --- a/esphome/components/binary_sensor/remote_receiver.py +++ b/esphome/components/binary_sensor/remote_receiver.py @@ -10,7 +10,7 @@ from esphome.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, C CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_ID, CONF_JVC, CONF_LG, CONF_NAME, CONF_NBITS, \ CONF_NEC, CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, \ CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_SAMSUNG, CONF_SONY, \ - CONF_STATE + CONF_STATE, CONF_RC5 from esphome.cpp_generator import Pvariable, get_variable, progmem_array from esphome.cpp_types import int32 @@ -18,7 +18,7 @@ DEPENDENCIES = ['remote_receiver'] REMOTE_KEYS = [CONF_JVC, CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_SAMSUNG, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, - CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D] + CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_RC5] CONF_REMOTE_RECEIVER_ID = 'remote_receiver_id' CONF_RECEIVER_ID = 'receiver_id' @@ -31,6 +31,7 @@ PanasonicReceiver = remote_ns.class_('PanasonicReceiver', RemoteReceiver) RawReceiver = remote_ns.class_('RawReceiver', RemoteReceiver) SamsungReceiver = remote_ns.class_('SamsungReceiver', RemoteReceiver) SonyReceiver = remote_ns.class_('SonyReceiver', RemoteReceiver) +RC5Receiver = remote_ns.class_('RC5Receiver', RemoteReceiver) RCSwitchRawReceiver = remote_ns.class_('RCSwitchRawReceiver', RemoteReceiver) RCSwitchTypeAReceiver = remote_ns.class_('RCSwitchTypeAReceiver', RCSwitchRawReceiver) RCSwitchTypeBReceiver = remote_ns.class_('RCSwitchTypeBReceiver', RCSwitchRawReceiver) @@ -73,6 +74,10 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend vol.Required(CONF_ADDRESS): cv.hex_uint16_t, vol.Required(CONF_COMMAND): cv.hex_uint32_t, }), + vol.Optional(CONF_RC5): vol.Schema({ + vol.Required(CONF_ADDRESS): vol.All(cv.hex_int, vol.Range(min=0, max=0x1F)), + vol.Required(CONF_COMMAND): vol.All(cv.hex_int, vol.Range(min=0, max=0x3F)), + }), vol.Optional(CONF_RAW): validate_raw, vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA, @@ -100,6 +105,8 @@ def receiver_base(full_config): return SamsungReceiver.new(name, config[CONF_DATA]) if key == CONF_SONY: return SonyReceiver.new(name, config[CONF_DATA], config[CONF_NBITS]) + if key == CONF_RC5: + return RC5Receiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) if key == CONF_RAW: arr = progmem_array(config[CONF_ID], config[CONF_DATA]) return RawReceiver.new(name, arr, len(config[CONF_DATA])) diff --git a/esphome/components/remote_receiver.py b/esphome/components/remote_receiver.py index c571b1ced0..cb909ef72f 100644 --- a/esphome/components/remote_receiver.py +++ b/esphome/components/remote_receiver.py @@ -28,6 +28,7 @@ DUMPERS = { 'samsung': remote_ns.class_('SamsungDumper', RemoteReceiveDumper), 'sony': remote_ns.class_('SonyDumper', RemoteReceiveDumper), 'rc_switch': remote_ns.class_('RCSwitchDumper', RemoteReceiveDumper), + 'rc5': remote_ns.class_('RC5Dumper', RemoteReceiveDumper), } diff --git a/esphome/components/switch/remote_transmitter.py b/esphome/components/switch/remote_transmitter.py index 4cdf4c7d8e..217eec0c00 100644 --- a/esphome/components/switch/remote_transmitter.py +++ b/esphome/components/switch/remote_transmitter.py @@ -12,7 +12,7 @@ from esphome.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_CHANNEL, CO CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, \ CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, \ CONF_RC_SWITCH_TYPE_D, CONF_REPEAT, CONF_SAMSUNG, CONF_SONY, CONF_STATE, CONF_TIMES, \ - CONF_WAIT_TIME + CONF_WAIT_TIME, CONF_RC5 from esphome.cpp_generator import Pvariable, add, get_variable, progmem_array from esphome.cpp_types import int32 @@ -20,7 +20,7 @@ DEPENDENCIES = ['remote_transmitter'] REMOTE_KEYS = [CONF_JVC, CONF_NEC, CONF_LG, CONF_SAMSUNG, CONF_SONY, CONF_PANASONIC, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, - CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D] + CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_RC5] CONF_REMOTE_TRANSMITTER_ID = 'remote_transmitter_id' CONF_TRANSMITTER_ID = 'transmitter_id' @@ -31,6 +31,7 @@ LGTransmitter = remote_ns.class_('LGTransmitter', RemoteTransmitter) NECTransmitter = remote_ns.class_('NECTransmitter', RemoteTransmitter) PanasonicTransmitter = remote_ns.class_('PanasonicTransmitter', RemoteTransmitter) RawTransmitter = remote_ns.class_('RawTransmitter', RemoteTransmitter) +RC5Transmitter = remote_ns.class_('RC5Transmitter', RemoteTransmitter) SamsungTransmitter = remote_ns.class_('SamsungTransmitter', RemoteTransmitter) SonyTransmitter = remote_ns.class_('SonyTransmitter', RemoteTransmitter) RCSwitchRawTransmitter = remote_ns.class_('RCSwitchRawTransmitter', RemoteTransmitter) @@ -76,6 +77,10 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ vol.Required(CONF_ADDRESS): cv.hex_uint16_t, vol.Required(CONF_COMMAND): cv.hex_uint32_t, }), + vol.Optional(CONF_RC5): vol.Schema({ + vol.Required(CONF_ADDRESS): vol.All(cv.hex_int, vol.Range(min=0, max=0x1F)), + vol.Required(CONF_COMMAND): vol.All(cv.hex_int, vol.Range(min=0, max=0x3F)), + }), vol.Optional(CONF_RAW): validate_raw, vol.Optional(CONF_RC_SWITCH_RAW): RC_SWITCH_RAW_SCHEMA, vol.Optional(CONF_RC_SWITCH_TYPE_A): RC_SWITCH_TYPE_A_SCHEMA, @@ -109,6 +114,8 @@ def transmitter_base(full_config): return SamsungTransmitter.new(name, config[CONF_DATA]) if key == CONF_SONY: return SonyTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS]) + if key == CONF_RC5: + return RC5Transmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) if key == CONF_RAW: arr = progmem_array(config[CONF_ID], config[CONF_DATA]) return RawTransmitter.new(name, arr, len(config[CONF_DATA]), diff --git a/esphome/const.py b/esphome/const.py index 3330327e37..bf87d9de07 100644 --- a/esphome/const.py +++ b/esphome/const.py @@ -162,6 +162,7 @@ CONF_COMMAND = 'command' CONF_DATA = 'data' CONF_NBITS = 'nbits' CONF_JVC = 'jvc' +CONF_RC5 = 'rc5' CONF_LG = 'lg' CONF_SAMSUNG = 'samsung' CONF_SONY = 'sony' diff --git a/tests/test1.yaml b/tests/test1.yaml index f4cfb1899a..ce60b556bd 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -895,6 +895,11 @@ switch: group: 'a' device: 2 state: True + - platform: remote_transmitter + name: "Panasonic TV Off" + rc5: + address: 0x00 + command: 0x0B - platform: remote_transmitter name: "Panasonic TV Off" id: living_room_lights_off