esphome/esphomeyaml/components/switch/__init__.py

37 lines
946 B
Python
Raw Normal View History

2018-04-07 01:23:03 +02:00
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ICON, CONF_ID, CONF_NAME, CONF_MQTT_ID
2018-04-07 01:23:03 +02:00
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,
})
2018-04-07 01:23:03 +02:00
def setup_mqtt_switch(obj, config):
setup_mqtt_component(obj, config)
def setup_switch(obj, config):
2018-04-07 01:23:03 +02:00
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)
2018-04-07 01:23:03 +02:00
setup_mqtt_switch(mqtt_switch, config)
2018-05-06 15:56:12 +02:00
BUILD_FLAGS = '-DUSE_SWITCH'