1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 04:12:23 +01:00

Web server (#7)

* Web Server

* Preparations for 1.3

* Fixes

* Fix Lint
This commit is contained in:
Otto Winter
2018-04-18 18:43:13 +02:00
committed by GitHub
parent ac5ab33975
commit 3540b3fbb0
53 changed files with 754 additions and 313 deletions

View File

@@ -1,7 +1,7 @@
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_NAME
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_NAME, CONF_MQTT_ID
from esphomeyaml.helpers import App, Pvariable, add, setup_mqtt_component
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
@@ -12,14 +12,26 @@ MQTT_SWITCH_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
vol.Optional(CONF_ICON): cv.icon,
})
MQTT_SWITCH_ID_SCHEMA = MQTT_SWITCH_SCHEMA.extend({
cv.GenerateID('mqtt_switch', CONF_MQTT_ID): cv.register_variable_id,
})
def setup_mqtt_switch(obj, config):
if CONF_ICON in config:
add(obj.set_icon(config[CONF_ICON]))
setup_mqtt_component(obj, config)
def make_mqtt_switch_for(exp, config):
rhs = App.make_mqtt_switch_for(exp, config[CONF_NAME])
mqtt_switch = Pvariable('switch_::MQTTSwitchComponent', config[CONF_ID], rhs)
def setup_switch(obj, config):
if CONF_ICON in config:
add(obj.set_icon(config[CONF_ICON]))
def register_switch(var, config):
setup_switch(var, config)
rhs = App.register_switch(var)
mqtt_switch = Pvariable('switch_::MQTTSwitchComponent', config[CONF_MQTT_ID], rhs)
setup_mqtt_switch(mqtt_switch, config)
def build_flags(config):
return '-DUSE_SWITCH'

View File

@@ -13,6 +13,11 @@ PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
def to_code(config):
rhs = App.make_gpio_switch(exp_gpio_output_pin(config[CONF_PIN]), config[CONF_NAME])
gpio = variable('Application::GPIOSwitchStruct', config[CONF_ID], rhs)
rhs = App.make_gpio_switch(config[CONF_NAME], exp_gpio_output_pin(config[CONF_PIN]))
gpio = variable('Application::MakeGPIOSwitch', config[CONF_ID], rhs)
switch.setup_switch(gpio.Pswitch_, config)
switch.setup_mqtt_switch(gpio.Pmqtt, config)
def build_flags(config):
return '-DUSE_GPIO_SWITCH'

View File

@@ -5,12 +5,12 @@ from esphomeyaml.components import switch
from esphomeyaml.components.ir_transmitter import IR_TRANSMITTER_COMPONENT_CLASS
from esphomeyaml.const import CONF_ADDRESS, CONF_COMMAND, CONF_DATA, CONF_IR_TRANSMITTER_ID, \
CONF_LG, CONF_NBITS, CONF_NEC, CONF_PANASONIC, CONF_REPEAT, CONF_SONY, CONF_TIMES, \
CONF_WAIT_TIME_US, CONF_RAW, CONF_CARRIER_FREQUENCY
CONF_WAIT_TIME_US, CONF_RAW, CONF_CARRIER_FREQUENCY, CONF_NAME, CONF_ID
from esphomeyaml.core import ESPHomeYAMLError
from esphomeyaml.helpers import HexIntLiteral, MockObj, get_variable, ArrayInitializer
from esphomeyaml.helpers import HexIntLiteral, MockObj, get_variable, ArrayInitializer, Pvariable
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
cv.GenerateID('ir_transmitter'): cv.register_variable_id,
cv.GenerateID('ir_transmitter_switch'): cv.register_variable_id,
vol.Exclusive(CONF_NEC, 'code'): vol.Schema({
vol.Required(CONF_ADDRESS): cv.hex_uint16_t,
vol.Required(CONF_COMMAND): cv.hex_uint16_t,
@@ -36,7 +36,7 @@ PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
vol.Required(CONF_WAIT_TIME_US): cv.uint32_t,
})),
vol.Optional(CONF_IR_TRANSMITTER_ID): cv.variable_id,
}).extend(switch.MQTT_SWITCH_SCHEMA.schema)
}).extend(switch.MQTT_SWITCH_ID_SCHEMA.schema)
# pylint: disable=invalid-name
@@ -86,4 +86,11 @@ def exp_send_data(config):
def to_code(config):
ir = get_variable(config.get(CONF_IR_TRANSMITTER_ID), IR_TRANSMITTER_COMPONENT_CLASS)
send_data = exp_send_data(config)
switch.make_mqtt_switch_for(ir.create_transmitter(send_data), config)
rhs = ir.create_transmitter(config[CONF_NAME], send_data)
switch_ = Pvariable(IR_TRANSMITTER_COMPONENT_CLASS + '::DataTransmitter', config[CONF_ID],
rhs)
switch.register_switch(switch_, config)
def build_flags(config):
return '-DUSE_IR_TRANSMITTER'

View File

@@ -1,7 +1,7 @@
import esphomeyaml.config_validation as cv
from esphomeyaml.components import switch
from esphomeyaml.const import CONF_ID, CONF_NAME
from esphomeyaml.helpers import App, Pvariable
from esphomeyaml.helpers import App, variable
PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
cv.GenerateID('restart_switch'): cv.register_variable_id,
@@ -10,5 +10,10 @@ PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
def to_code(config):
rhs = App.make_restart_switch(config[CONF_NAME])
mqtt = Pvariable('switch_::MQTTSwitchComponent', config[CONF_ID], rhs)
switch.setup_mqtt_switch(mqtt, config)
restart = variable('Application::MakeRestartSwitch', config[CONF_ID], rhs)
switch.setup_switch(restart.Prestart, config)
switch.setup_mqtt_switch(restart.Pmqtt, config)
def build_flags(config):
return '-DUSE_RESTART_SWITCH'