mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 02:04:13 +01:00
GPIO Switch Power On Value v2 (#183)
This commit is contained in:
parent
db8313e0d5
commit
820067ae5a
4 changed files with 13 additions and 6 deletions
|
@ -3,14 +3,15 @@ import voluptuous as vol
|
||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml import pins
|
from esphomeyaml import pins
|
||||||
from esphomeyaml.components import switch
|
from esphomeyaml.components import switch
|
||||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN
|
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_PIN, CONF_POWER_ON_VALUE
|
||||||
from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable
|
from esphomeyaml.helpers import App, Application, gpio_output_pin_expression, variable, add
|
||||||
|
|
||||||
MakeGPIOSwitch = Application.MakeGPIOSwitch
|
MakeGPIOSwitch = Application.MakeGPIOSwitch
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch),
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeGPIOSwitch),
|
||||||
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
vol.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
||||||
|
vol.Optional(CONF_POWER_ON_VALUE): cv.boolean,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +21,10 @@ def to_code(config):
|
||||||
yield
|
yield
|
||||||
rhs = App.make_gpio_switch(config[CONF_NAME], pin)
|
rhs = App.make_gpio_switch(config[CONF_NAME], pin)
|
||||||
gpio = variable(config[CONF_MAKE_ID], rhs)
|
gpio = variable(config[CONF_MAKE_ID], rhs)
|
||||||
|
|
||||||
|
if CONF_POWER_ON_VALUE in config:
|
||||||
|
add(gpio.Pswitch_.set_power_on_value(config[CONF_POWER_ON_VALUE]))
|
||||||
|
|
||||||
switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config)
|
switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,10 @@ from esphomeyaml.components import switch
|
||||||
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
|
from esphomeyaml.const import CONF_MAKE_ID, CONF_NAME, CONF_OUTPUT
|
||||||
from esphomeyaml.helpers import App, Application, get_variable, variable
|
from esphomeyaml.helpers import App, Application, get_variable, variable
|
||||||
|
|
||||||
MakeSimpleSwitch = Application.MakeSimpleSwitch
|
MakeOutputSwitch = Application.MakeOutputSwitch
|
||||||
|
|
||||||
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
|
||||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeSimpleSwitch),
|
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeOutputSwitch),
|
||||||
vol.Required(CONF_OUTPUT): cv.use_variable_id(None),
|
vol.Required(CONF_OUTPUT): cv.use_variable_id(None),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ def to_code(config):
|
||||||
output = None
|
output = None
|
||||||
for output in get_variable(config[CONF_OUTPUT]):
|
for output in get_variable(config[CONF_OUTPUT]):
|
||||||
yield
|
yield
|
||||||
rhs = App.make_simple_switch(config[CONF_NAME], output)
|
rhs = App.make_output_switch(config[CONF_NAME], output)
|
||||||
gpio = variable(config[CONF_MAKE_ID], rhs)
|
gpio = variable(config[CONF_MAKE_ID], rhs)
|
||||||
switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config)
|
switch.setup_switch(gpio.Pswitch_, gpio.Pmqtt, config)
|
||||||
|
|
||||||
|
|
||||||
BUILD_FLAGS = '-DUSE_SIMPLE_SWITCH'
|
BUILD_FLAGS = '-DUSE_OUTPUT_SWITCH'
|
||||||
|
|
|
@ -340,6 +340,7 @@ CONF_MONTHS = 'months'
|
||||||
CONF_DAYS_OF_WEEK = 'days_of_week'
|
CONF_DAYS_OF_WEEK = 'days_of_week'
|
||||||
CONF_CRON = 'cron'
|
CONF_CRON = 'cron'
|
||||||
CONF_POWER_SAVE_MODE = 'power_save_mode'
|
CONF_POWER_SAVE_MODE = 'power_save_mode'
|
||||||
|
CONF_POWER_ON_VALUE = 'power_on_value'
|
||||||
|
|
||||||
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
|
ALLOWED_NAME_CHARS = u'abcdefghijklmnopqrstuvwxyz0123456789_'
|
||||||
ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'
|
ARDUINO_VERSION_ESP32_DEV = 'https://github.com/platformio/platform-espressif32.git#feature/stage'
|
||||||
|
|
|
@ -690,6 +690,7 @@ switch:
|
||||||
icon: "mdi:restart"
|
icon: "mdi:restart"
|
||||||
inverted: True
|
inverted: True
|
||||||
command_topic: custom_command_topic
|
command_topic: custom_command_topic
|
||||||
|
power_on_value: True
|
||||||
- platform: remote_transmitter
|
- platform: remote_transmitter
|
||||||
name: "Panasonic TV Off"
|
name: "Panasonic TV Off"
|
||||||
nec:
|
nec:
|
||||||
|
|
Loading…
Reference in a new issue