1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 22:53:59 +00:00

Disable MQTT if not used (#373)

* Disable MQTT if not used

* Lint
This commit is contained in:
Otto Winter
2019-01-29 17:29:21 +01:00
committed by GitHub
parent 7b26ecc0dc
commit 176c712eeb
66 changed files with 389 additions and 530 deletions

View File

@@ -5,6 +5,7 @@ from esphomeyaml.components import mqtt
from esphomeyaml.components.mqtt import setup_mqtt_component
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID
from esphomeyaml.core import CORE
from esphomeyaml.cpp_generator import Pvariable, add, get_variable
from esphomeyaml.cpp_types import Action, Nameable, esphomelib_ns
@@ -34,16 +35,14 @@ COVER_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
COVER_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(COVER_SCHEMA.schema)
def setup_cover_core_(cover_var, mqtt_var, config):
def setup_cover_core_(cover_var, config):
if CONF_INTERNAL in config:
add(cover_var.set_internal(config[CONF_INTERNAL]))
setup_mqtt_component(mqtt_var, config)
setup_mqtt_component(cover_var.Pget_mqtt(), config)
def setup_cover(cover_obj, mqtt_obj, config):
cover_var = Pvariable(config[CONF_ID], cover_obj, has_side_effects=False)
mqtt_var = Pvariable(config[CONF_MQTT_ID], mqtt_obj, has_side_effects=False)
setup_cover_core_(cover_var, mqtt_var, config)
def setup_cover(cover_obj, config):
CORE.add_job(setup_cover_core_, cover_obj, config)
BUILD_FLAGS = '-DUSE_COVER'

View File

@@ -1,19 +1,17 @@
import voluptuous as vol
import esphomeyaml.config_validation as cv
from esphomeyaml import automation
from esphomeyaml.components import cover
from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_LAMBDA, CONF_MAKE_ID, CONF_NAME, \
CONF_OPEN_ACTION, CONF_STOP_ACTION, CONF_OPTIMISTIC
from esphomeyaml.cpp_generator import variable, process_lambda, add
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, CONF_NAME, \
CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STOP_ACTION
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
from esphomeyaml.cpp_helpers import setup_component
from esphomeyaml.cpp_types import Application, App, optional, NoArg
from esphomeyaml.cpp_types import App, NoArg, optional
MakeTemplateCover = Application.struct('MakeTemplateCover')
TemplateCover = cover.cover_ns.class_('TemplateCover', cover.Cover)
PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(MakeTemplateCover),
cv.GenerateID(): cv.declare_variable_id(TemplateCover),
vol.Optional(CONF_LAMBDA): cv.lambda_,
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
@@ -25,27 +23,27 @@ PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({
def to_code(config):
rhs = App.make_template_cover(config[CONF_NAME])
make = variable(config[CONF_MAKE_ID], rhs)
var = Pvariable(config[CONF_ID], rhs)
cover.setup_cover(make.Ptemplate_, make.Pmqtt, config)
setup_component(make.Ptemplate_, config)
cover.setup_cover(var, config)
setup_component(var, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(cover.CoverState)):
yield
add(make.Ptemplate_.set_state_lambda(template_))
add(var.set_state_lambda(template_))
if CONF_OPEN_ACTION in config:
automation.build_automation(make.Ptemplate_.get_open_trigger(), NoArg,
automation.build_automation(var.get_open_trigger(), NoArg,
config[CONF_OPEN_ACTION])
if CONF_CLOSE_ACTION in config:
automation.build_automation(make.Ptemplate_.get_close_trigger(), NoArg,
automation.build_automation(var.get_close_trigger(), NoArg,
config[CONF_CLOSE_ACTION])
if CONF_STOP_ACTION in config:
automation.build_automation(make.Ptemplate_.get_stop_trigger(), NoArg,
automation.build_automation(var.get_stop_trigger(), NoArg,
config[CONF_STOP_ACTION])
if CONF_OPTIMISTIC in config:
add(make.Ptemplate_.set_optimistic(config[CONF_OPTIMISTIC]))
add(var.set_optimistic(config[CONF_OPTIMISTIC]))
BUILD_FLAGS = '-DUSE_TEMPLATE_COVER'