mirror of
https://github.com/esphome/esphome.git
synced 2024-11-08 09:40:53 +01:00
3540b3fbb0
* Web Server * Preparations for 1.3 * Fixes * Fix Lint
38 lines
968 B
Python
38 lines
968 B
Python
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.helpers import App, Pvariable, add, setup_mqtt_component
|
|
|
|
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
|
|
|
|
})
|
|
|
|
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):
|
|
setup_mqtt_component(obj, config)
|
|
|
|
|
|
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'
|