1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-07 03:11:00 +01:00
esphome/esphomeyaml/components/remote_receiver.py
Otto Winter 7c7032c59e
[Huge] Util Refactor, Dashboard Improvements, Hass.io Auth API, Better Validation Errors, Conditions, Custom Platforms, Substitutions (#234)
* Implement custom sensor platform

* Update

* Ethernet

* Lint

* Fix

* Login page

* Rename cookie secret

* Update manifest

* Update cookie check logic

* Favicon

* Fix

* Favicon manifest

* Fix

* Fix

* Fix

* Use hostname

* Message

* Temporary commit for screenshot

* Automatic board selection

* Undo temporary commit

* Update esphomeyaml-edge

* In-dashboard editing and hosting files locally

* Update esphomeyaml-edge

* Better ANSI color escaping

* Message

* Lint

* Download Efficiency

* Fix gitlab

* Fix

* Rename extra_libraries to libraries

* Add example

* Update README.md

* Update README.md

* Update README.md

* HassIO -> Hass.io

* Updates

* Add update available notice

* Update

* Fix substitutions

* Better error message

* Re-do dashboard ANSI colors

* Only include FastLED if user says so

* Autoscroll logs

* Remove old checks

* Use safer RedirectText

* Improvements

* Fix

* Use enviornment variable

* Use http://hassio/host/info

* Fix conditions

* Update platformio versions

* Revert "Use enviornment variable"

This reverts commit 7f038eb5d2.

* Fix

* README update

* Temp

* Better invalid config messages

* Platformio debug

* Improve error messages

* Debug

* Remove debug

* Multi Conf

* Update

* Better paths

* Remove unused

* Fixes

* Lint

* lib_ignore

* Try fix platformio colors

* Fix dashboard scrolling

* Revert

* Lint

* Revert
2018-12-05 21:22:06 +01:00

74 lines
2.8 KiB
Python

import voluptuous as vol
from esphomeyaml import pins
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
CONF_PIN, CONF_TOLERANCE
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
remote_ns = esphomelib_ns.namespace('remote')
MULTI_CONF = True
RemoteControlComponentBase = remote_ns.class_('RemoteControlComponentBase')
RemoteReceiverComponent = remote_ns.class_('RemoteReceiverComponent',
RemoteControlComponentBase,
Component)
RemoteReceiveDumper = remote_ns.class_('RemoteReceiveDumper')
DUMPERS = {
'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),
}
def validate_dumpers_all(value):
if not isinstance(value, (str, unicode)):
raise vol.Invalid("Not valid dumpers")
if value.upper() == "ALL":
return list(sorted(list(DUMPERS)))
raise vol.Invalid("Not valid dumpers")
CONFIG_SCHEMA = vol.Schema({
cv.GenerateID(): cv.declare_variable_id(RemoteReceiverComponent),
vol.Required(CONF_PIN): pins.gpio_input_pin_schema,
vol.Optional(CONF_DUMP, default=[]):
vol.Any(validate_dumpers_all,
vol.All(cv.ensure_list, [cv.one_of(*DUMPERS, lower=True)])),
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,
}).extend(cv.COMPONENT_SCHEMA.schema)
def to_code(config):
for pin in gpio_input_pin_expression(config[CONF_PIN]):
yield
rhs = App.make_remote_receiver_component(pin)
receiver = Pvariable(config[CONF_ID], rhs)
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]))
setup_component(receiver, config)
BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER'