2018-06-11 10:01:54 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from esphomeyaml import pins
|
2018-12-05 21:22:06 +01:00
|
|
|
import esphomeyaml.config_validation as cv
|
2018-06-14 00:14:01 +02:00
|
|
|
from esphomeyaml.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
|
|
|
|
CONF_PIN, CONF_TOLERANCE
|
2018-12-05 21:22:06 +01:00
|
|
|
from esphomeyaml.cpp_generator import Pvariable, add
|
|
|
|
from esphomeyaml.cpp_helpers import gpio_input_pin_expression, setup_component
|
|
|
|
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
2019-01-02 14:11:11 +01:00
|
|
|
from esphomeyaml.py_compat import string_types
|
2018-06-11 10:01:54 +02:00
|
|
|
|
|
|
|
remote_ns = esphomelib_ns.namespace('remote')
|
2018-12-05 21:22:06 +01:00
|
|
|
MULTI_CONF = True
|
2018-06-11 10:01:54 +02:00
|
|
|
|
2018-11-12 23:30:31 +01:00
|
|
|
RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase')
|
|
|
|
RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent',
|
|
|
|
RemoteControlComponentBase,
|
|
|
|
Component)
|
|
|
|
|
|
|
|
RemoteReceiveDumper = remote_ns.class_('RemoteReceiveDumper')
|
2018-06-11 10:01:54 +02:00
|
|
|
|
|
|
|
DUMPERS = {
|
2018-11-12 23:30:31 +01:00
|
|
|
'lg': remote_ns.class_('LGDumper', RemoteReceiveDumper),
|
|
|
|
'nec': remote_ns.class_('NECDumper', RemoteReceiveDumper),
|
|
|
|
'panasonic': remote_ns.class_('PanasonicDumper', RemoteReceiveDumper),
|
|
|
|
'raw': remote_ns.class_('RawDumper', RemoteReceiveDumper),
|
|
|
|
'samsung': remote_ns.class_('SamsungDumper', RemoteReceiveDumper),
|
|
|
|
'sony': remote_ns.class_('SonyDumper', RemoteReceiveDumper),
|
|
|
|
'rc_switch': remote_ns.class_('RCSwitchDumper', RemoteReceiveDumper),
|
2018-06-11 10:01:54 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 21:27:58 +02:00
|
|
|
|
|
|
|
def validate_dumpers_all(value):
|
2019-01-02 14:11:11 +01:00
|
|
|
if not isinstance(value, string_types):
|
2018-06-13 21:27:58 +02:00
|
|
|
raise vol.Invalid("Not valid dumpers")
|
|
|
|
if value.upper() == "ALL":
|
2018-08-13 19:11:33 +02:00
|
|
|
return list(sorted(list(DUMPERS)))
|
2018-06-13 21:27:58 +02:00
|
|
|
raise vol.Invalid("Not valid dumpers")
|
|
|
|
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
CONFIG_SCHEMA = vol.Schema({
|
2018-06-11 10:01:54 +02:00
|
|
|
cv.GenerateID(): cv.declare_variable_id(RemoteReceiverComponent),
|
|
|
|
vol.Required(CONF_PIN): pins.gpio_input_pin_schema,
|
2018-06-13 21:27:58 +02:00
|
|
|
vol.Optional(CONF_DUMP, default=[]):
|
2018-12-18 19:31:43 +01:00
|
|
|
vol.Any(validate_dumpers_all, cv.ensure_list(cv.one_of(*DUMPERS, lower=True))),
|
2018-06-11 10:01:54 +02:00
|
|
|
vol.Optional(CONF_TOLERANCE): vol.All(cv.percentage_int, vol.Range(min=0)),
|
|
|
|
vol.Optional(CONF_BUFFER_SIZE): cv.validate_bytes,
|
|
|
|
vol.Optional(CONF_FILTER): cv.positive_time_period_microseconds,
|
|
|
|
vol.Optional(CONF_IDLE): cv.positive_time_period_microseconds,
|
2018-12-05 21:22:06 +01:00
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
2018-06-11 10:01:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2018-12-05 21:22:06 +01:00
|
|
|
for pin in gpio_input_pin_expression(config[CONF_PIN]):
|
|
|
|
yield
|
|
|
|
rhs = App.make_remote_receiver_component(pin)
|
|
|
|
receiver = Pvariable(config[CONF_ID], rhs)
|
2018-11-12 23:30:31 +01:00
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
for dumper in config[CONF_DUMP]:
|
|
|
|
add(receiver.add_dumper(DUMPERS[dumper].new()))
|
|
|
|
if CONF_TOLERANCE in config:
|
|
|
|
add(receiver.set_tolerance(config[CONF_TOLERANCE]))
|
|
|
|
if CONF_BUFFER_SIZE in config:
|
|
|
|
add(receiver.set_buffer_size(config[CONF_BUFFER_SIZE]))
|
|
|
|
if CONF_FILTER in config:
|
|
|
|
add(receiver.set_filter_us(config[CONF_FILTER]))
|
|
|
|
if CONF_IDLE in config:
|
|
|
|
add(receiver.set_idle_us(config[CONF_IDLE]))
|
2018-06-11 10:01:54 +02:00
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
setup_component(receiver, config)
|
2018-11-12 23:30:31 +01:00
|
|
|
|
2018-06-11 10:01:54 +02:00
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'
|