mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 14:38:10 +01:00
Generic Switch inversion support fixes #14
This commit is contained in:
parent
ebb5991889
commit
3a9febaf85
6 changed files with 22 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_NAME, CONF_MQTT_ID
|
||||
from esphomeyaml.const import CONF_ICON, CONF_INVERTED, CONF_MQTT_ID
|
||||
from esphomeyaml.helpers import App, Pvariable, add, setup_mqtt_component
|
||||
|
||||
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
||||
|
@ -10,6 +10,7 @@ PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
|||
|
||||
MQTT_SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
|
||||
vol.Optional(CONF_ICON): cv.icon,
|
||||
vol.Optional(CONF_INVERTED): cv.boolean,
|
||||
})
|
||||
|
||||
MQTT_SWITCH_ID_SCHEMA = MQTT_SWITCH_SCHEMA.extend({
|
||||
|
@ -24,6 +25,8 @@ def setup_mqtt_switch(obj, config):
|
|||
def setup_switch(obj, config):
|
||||
if CONF_ICON in config:
|
||||
add(obj.set_icon(config[CONF_ICON]))
|
||||
if CONF_INVERTED in config:
|
||||
add(obj.set_inverted(config[CONF_INVERTED]))
|
||||
|
||||
|
||||
def register_switch(var, config):
|
||||
|
|
|
@ -5,7 +5,7 @@ from esphomeyaml.components import switch
|
|||
from esphomeyaml.components.ir_transmitter import IR_TRANSMITTER_COMPONENT_CLASS
|
||||
from esphomeyaml.const import CONF_ADDRESS, CONF_CARRIER_FREQUENCY, CONF_COMMAND, CONF_DATA, \
|
||||
CONF_ID, CONF_IR_TRANSMITTER_ID, CONF_LG, CONF_NAME, CONF_NBITS, CONF_NEC, CONF_PANASONIC, \
|
||||
CONF_RAW, CONF_REPEAT, CONF_SONY, CONF_TIMES, CONF_WAIT_TIME
|
||||
CONF_RAW, CONF_REPEAT, CONF_SONY, CONF_TIMES, CONF_WAIT_TIME, CONF_INVERTED
|
||||
from esphomeyaml.core import ESPHomeYAMLError
|
||||
from esphomeyaml.helpers import ArrayInitializer, HexIntLiteral, MockObj, Pvariable, get_variable
|
||||
|
||||
|
@ -45,6 +45,7 @@ PLATFORM_SCHEMA = vol.All(switch.PLATFORM_SCHEMA.extend({
|
|||
vol.Optional('wait_time_us'): cv.invalid(WAIT_TIME_MESSAGE),
|
||||
})),
|
||||
vol.Optional(CONF_IR_TRANSMITTER_ID): cv.variable_id,
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("IR Transmitters do not support inverted mode!"),
|
||||
}).extend(switch.MQTT_SWITCH_ID_SCHEMA.schema), cv.has_at_least_one_key(*IR_KEYS))
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import switch
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_INVERTED
|
||||
from esphomeyaml.helpers import App, variable
|
||||
|
||||
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID('restart_switch'): cv.register_variable_id,
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("Restart switches do not support inverted mode!"),
|
||||
}).extend(switch.MQTT_SWITCH_SCHEMA.schema)
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import switch
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME
|
||||
from esphomeyaml.const import CONF_ID, CONF_NAME, CONF_INVERTED
|
||||
from esphomeyaml.helpers import App, variable
|
||||
|
||||
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID('shutdown_switch'): cv.register_variable_id,
|
||||
vol.Optional(CONF_INVERTED): cv.invalid("Shutdown switches do not support inverted mode!"),
|
||||
}).extend(switch.MQTT_SWITCH_SCHEMA.schema)
|
||||
|
||||
|
||||
|
|
|
@ -186,15 +186,15 @@ class Literal(Expression):
|
|||
|
||||
|
||||
# From https://stackoverflow.com/a/14945195/8924614
|
||||
def cpp_string_escape(s, encoding='utf-8'):
|
||||
if isinstance(s, unicode):
|
||||
s = s.encode(encoding)
|
||||
def cpp_string_escape(string, encoding='utf-8'):
|
||||
if isinstance(string, unicode):
|
||||
string = string.encode(encoding)
|
||||
result = ''
|
||||
for c in s:
|
||||
if not (32 <= ord(c) < 127) or c in ('\\', '"'):
|
||||
result += '\\%03o' % ord(c)
|
||||
for character in string:
|
||||
if not (32 <= ord(character) < 127) or character in ('\\', '"'):
|
||||
result += '\\%03o' % ord(character)
|
||||
else:
|
||||
result += c
|
||||
result += character
|
||||
return '"' + result + '"'
|
||||
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ void setup() {
|
|||
|
||||
void loop() {
|
||||
App.loop();
|
||||
delay(1);
|
||||
delay(16);
|
||||
}
|
||||
""")
|
||||
|
||||
|
|
Loading…
Reference in a new issue