Add Samsung IR protocol (#176)

* add Samsung ir protocol

* fix pylint

* add test

* add transmitter
This commit is contained in:
escoand 2018-10-13 19:21:06 +02:00 committed by Otto Winter
parent 1d75ed1ff4
commit 4a2cdbf31c
5 changed files with 28 additions and 8 deletions

View file

@ -9,14 +9,15 @@ from esphomeyaml.components.remote_transmitter import RC_SWITCH_RAW_SCHEMA, \
from esphomeyaml.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, CONF_DATA, \ from esphomeyaml.const import CONF_ADDRESS, CONF_CHANNEL, CONF_CODE, CONF_COMMAND, CONF_DATA, \
CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, \ CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, \
CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, \ 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_SONY, CONF_STATE CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, CONF_SAMSUNG, CONF_SONY, \
CONF_STATE
from esphomeyaml.helpers import ArrayInitializer, Pvariable, get_variable from esphomeyaml.helpers import ArrayInitializer, Pvariable, get_variable
DEPENDENCIES = ['remote_receiver'] DEPENDENCIES = ['remote_receiver']
REMOTE_KEYS = [CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_RAW, CONF_RC_SWITCH_RAW, REMOTE_KEYS = [CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_SAMSUNG, CONF_RAW,
CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B,
CONF_RC_SWITCH_TYPE_D] CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D]
CONF_REMOTE_RECEIVER_ID = 'remote_receiver_id' CONF_REMOTE_RECEIVER_ID = 'remote_receiver_id'
CONF_RECEIVER_ID = 'receiver_id' CONF_RECEIVER_ID = 'receiver_id'
@ -26,6 +27,7 @@ LGReceiver = remote_ns.LGReceiver
NECReceiver = remote_ns.NECReceiver NECReceiver = remote_ns.NECReceiver
PanasonicReceiver = remote_ns.PanasonicReceiver PanasonicReceiver = remote_ns.PanasonicReceiver
RawReceiver = remote_ns.RawReceiver RawReceiver = remote_ns.RawReceiver
SamsungReceiver = remote_ns.SamsungReceiver
SonyReceiver = remote_ns.SonyReceiver SonyReceiver = remote_ns.SonyReceiver
RCSwitchRawReceiver = remote_ns.RCSwitchRawReceiver RCSwitchRawReceiver = remote_ns.RCSwitchRawReceiver
RCSwitchTypeAReceiver = remote_ns.RCSwitchTypeAReceiver RCSwitchTypeAReceiver = remote_ns.RCSwitchTypeAReceiver
@ -42,6 +44,9 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
vol.Required(CONF_ADDRESS): cv.hex_uint16_t, vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
vol.Required(CONF_COMMAND): cv.hex_uint16_t, vol.Required(CONF_COMMAND): cv.hex_uint16_t,
}), }),
vol.Optional(CONF_SAMSUNG): vol.Schema({
vol.Required(CONF_DATA): cv.hex_uint32_t,
}),
vol.Optional(CONF_SONY): vol.Schema({ vol.Optional(CONF_SONY): vol.Schema({
vol.Required(CONF_DATA): cv.hex_uint32_t, vol.Required(CONF_DATA): cv.hex_uint32_t,
vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)), vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)),
@ -71,6 +76,8 @@ def receiver_base(full_config):
return NECReceiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) return NECReceiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
elif key == CONF_PANASONIC: elif key == CONF_PANASONIC:
return PanasonicReceiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) return PanasonicReceiver.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
elif key == CONF_SAMSUNG:
return SamsungReceiver.new(name, config[CONF_DATA])
elif key == CONF_SONY: elif key == CONF_SONY:
return SonyReceiver.new(name, config[CONF_DATA], config[CONF_NBITS]) return SonyReceiver.new(name, config[CONF_DATA], config[CONF_NBITS])
elif key == CONF_RAW: elif key == CONF_RAW:

View file

@ -15,6 +15,7 @@ DUMPERS = {
'nec': remote_ns.NECDumper, 'nec': remote_ns.NECDumper,
'panasonic': remote_ns.PanasonicDumper, 'panasonic': remote_ns.PanasonicDumper,
'raw': remote_ns.RawDumper, 'raw': remote_ns.RawDumper,
'samsung': remote_ns.SamsungDumper,
'sony': remote_ns.SonyDumper, 'sony': remote_ns.SonyDumper,
'rc_switch': remote_ns.RCSwitchDumper, 'rc_switch': remote_ns.RCSwitchDumper,
} }

View file

@ -10,15 +10,15 @@ from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_CHANNEL
CONF_COMMAND, CONF_DATA, CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_INVERTED, CONF_LG, \ CONF_COMMAND, CONF_DATA, CONF_DEVICE, CONF_FAMILY, CONF_GROUP, CONF_INVERTED, CONF_LG, \
CONF_NAME, CONF_NBITS, CONF_NEC, CONF_PANASONIC, CONF_PROTOCOL, CONF_RAW, CONF_RC_SWITCH_RAW, \ 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_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D, \
CONF_REPEAT, CONF_SONY, CONF_STATE, CONF_TIMES, \ CONF_REPEAT, CONF_SAMSUNG, CONF_SONY, CONF_STATE, CONF_TIMES, \
CONF_WAIT_TIME CONF_WAIT_TIME
from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, add, get_variable from esphomeyaml.helpers import App, ArrayInitializer, Pvariable, add, get_variable
DEPENDENCIES = ['remote_transmitter'] DEPENDENCIES = ['remote_transmitter']
REMOTE_KEYS = [CONF_NEC, CONF_LG, CONF_SONY, CONF_PANASONIC, CONF_RAW, CONF_RC_SWITCH_RAW, REMOTE_KEYS = [CONF_NEC, CONF_LG, CONF_SAMSUNG, CONF_SONY, CONF_PANASONIC, CONF_RAW,
CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B, CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_RAW, CONF_RC_SWITCH_TYPE_A, CONF_RC_SWITCH_TYPE_B,
CONF_RC_SWITCH_TYPE_D] CONF_RC_SWITCH_TYPE_C, CONF_RC_SWITCH_TYPE_D]
CONF_REMOTE_TRANSMITTER_ID = 'remote_transmitter_id' CONF_REMOTE_TRANSMITTER_ID = 'remote_transmitter_id'
CONF_TRANSMITTER_ID = 'transmitter_id' CONF_TRANSMITTER_ID = 'transmitter_id'
@ -28,6 +28,7 @@ LGTransmitter = remote_ns.LGTransmitter
NECTransmitter = remote_ns.NECTransmitter NECTransmitter = remote_ns.NECTransmitter
PanasonicTransmitter = remote_ns.PanasonicTransmitter PanasonicTransmitter = remote_ns.PanasonicTransmitter
RawTransmitter = remote_ns.RawTransmitter RawTransmitter = remote_ns.RawTransmitter
SamsungTransmitter = remote_ns.SamsungTransmitter
SonyTransmitter = remote_ns.SonyTransmitter SonyTransmitter = remote_ns.SonyTransmitter
RCSwitchRawTransmitter = remote_ns.RCSwitchRawTransmitter RCSwitchRawTransmitter = remote_ns.RCSwitchRawTransmitter
RCSwitchTypeATransmitter = remote_ns.RCSwitchTypeATransmitter RCSwitchTypeATransmitter = remote_ns.RCSwitchTypeATransmitter
@ -46,6 +47,9 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
vol.Required(CONF_ADDRESS): cv.hex_uint16_t, vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
vol.Required(CONF_COMMAND): cv.hex_uint16_t, vol.Required(CONF_COMMAND): cv.hex_uint16_t,
}), }),
vol.Optional(CONF_SAMSUNG): vol.Schema({
vol.Required(CONF_DATA): cv.hex_uint32_t,
}),
vol.Optional(CONF_SONY): vol.Schema({ vol.Optional(CONF_SONY): vol.Schema({
vol.Required(CONF_DATA): cv.hex_uint32_t, vol.Required(CONF_DATA): cv.hex_uint32_t,
vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)), vol.Optional(CONF_NBITS, default=12): vol.All(vol.Coerce(int), cv.one_of(12, 15, 20)),
@ -84,6 +88,8 @@ def transmitter_base(full_config):
return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) return NECTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
elif key == CONF_PANASONIC: elif key == CONF_PANASONIC:
return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND]) return PanasonicTransmitter.new(name, config[CONF_ADDRESS], config[CONF_COMMAND])
elif key == CONF_SAMSUNG:
return SamsungTransmitter.new(name, config[CONF_DATA])
elif key == CONF_SONY: elif key == CONF_SONY:
return SonyTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS]) return SonyTransmitter.new(name, config[CONF_DATA], config[CONF_NBITS])
elif key == CONF_RAW: elif key == CONF_RAW:

View file

@ -161,6 +161,7 @@ CONF_COMMAND = 'command'
CONF_DATA = 'data' CONF_DATA = 'data'
CONF_NBITS = 'nbits' CONF_NBITS = 'nbits'
CONF_LG = 'lg' CONF_LG = 'lg'
CONF_SAMSUNG = 'samsung'
CONF_SONY = 'sony' CONF_SONY = 'sony'
CONF_PANASONIC = 'panasonic' CONF_PANASONIC = 'panasonic'
CONF_REPEAT = 'repeat' CONF_REPEAT = 'repeat'

View file

@ -699,6 +699,11 @@ switch:
data: 4294967295 data: 4294967295
nbits: 28 nbits: 28
repeat: 25 repeat: 25
- platform: remote_transmitter
name: "Panasonic TV Off"
samsung:
data: 0xABCDEF
repeat: 25
- platform: remote_transmitter - platform: remote_transmitter
name: "Panasonic TV Off" name: "Panasonic TV Off"
sony: sony: