Print error when mqtt.publish used without MQTT enabled (#408)

Fixes https://github.com/esphome/issues/issues/40
This commit is contained in:
Otto Winter 2019-02-10 16:30:17 +01:00 committed by GitHub
parent 9fa95a9a21
commit 7c28eca6de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@ from esphomeyaml.const import CONF_AVAILABILITY, CONF_BIRTH_MESSAGE, CONF_BROKER
CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE
from esphomeyaml.core import EsphomeyamlError from esphomeyaml.core import EsphomeyamlError
from esphomeyaml.cpp_generator import Pvariable, RawExpression, StructInitializer, \ from esphomeyaml.cpp_generator import Pvariable, RawExpression, StructInitializer, \
TemplateArguments, add, process_lambda, templatable TemplateArguments, add, process_lambda, templatable, get_variable
from esphomeyaml.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \ from esphomeyaml.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \
Trigger, bool_, esphomelib_ns, optional, std_string, uint8, void Trigger, bool_, esphomelib_ns, optional, std_string, uint8, void
@ -194,6 +194,7 @@ def to_code(config):
CONF_MQTT_PUBLISH = 'mqtt.publish' CONF_MQTT_PUBLISH = 'mqtt.publish'
MQTT_PUBLISH_ACTION_SCHEMA = vol.Schema({ MQTT_PUBLISH_ACTION_SCHEMA = vol.Schema({
cv.GenerateID(): cv.use_variable_id(MQTTClientComponent),
vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic), vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
vol.Required(CONF_PAYLOAD): cv.templatable(cv.mqtt_payload), vol.Required(CONF_PAYLOAD): cv.templatable(cv.mqtt_payload),
vol.Optional(CONF_QOS): cv.templatable(cv.mqtt_qos), vol.Optional(CONF_QOS): cv.templatable(cv.mqtt_qos),
@ -203,7 +204,9 @@ MQTT_PUBLISH_ACTION_SCHEMA = vol.Schema({
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA) @ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA)
def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg): def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg):
rhs = App.Pget_mqtt_client().Pmake_publish_action(template_arg) for var in get_variable(config[CONF_ID]):
yield None
rhs = var.make_publish_action(template_arg)
type = MQTTPublishAction.template(template_arg) type = MQTTPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type) action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TOPIC], arg_type, std_string): for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):
@ -226,6 +229,7 @@ def mqtt_publish_action_to_code(config, action_id, arg_type, template_arg):
CONF_MQTT_PUBLISH_JSON = 'mqtt.publish_json' CONF_MQTT_PUBLISH_JSON = 'mqtt.publish_json'
MQTT_PUBLISH_JSON_ACTION_SCHEMA = vol.Schema({ MQTT_PUBLISH_JSON_ACTION_SCHEMA = vol.Schema({
cv.GenerateID(): cv.use_variable_id(MQTTClientComponent),
vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic), vol.Required(CONF_TOPIC): cv.templatable(cv.publish_topic),
vol.Required(CONF_PAYLOAD): cv.lambda_, vol.Required(CONF_PAYLOAD): cv.lambda_,
vol.Optional(CONF_QOS): cv.mqtt_qos, vol.Optional(CONF_QOS): cv.mqtt_qos,
@ -235,7 +239,9 @@ MQTT_PUBLISH_JSON_ACTION_SCHEMA = vol.Schema({
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH_JSON, MQTT_PUBLISH_JSON_ACTION_SCHEMA) @ACTION_REGISTRY.register(CONF_MQTT_PUBLISH_JSON, MQTT_PUBLISH_JSON_ACTION_SCHEMA)
def mqtt_publish_json_action_to_code(config, action_id, arg_type, template_arg): def mqtt_publish_json_action_to_code(config, action_id, arg_type, template_arg):
rhs = App.Pget_mqtt_client().Pmake_publish_json_action(template_arg) for var in get_variable(config[CONF_ID]):
yield None
rhs = var.make_publish_json_action(template_arg)
type = MQTTPublishJsonAction.template(template_arg) type = MQTTPublishJsonAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type) action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TOPIC], arg_type, std_string): for template_ in templatable(config[CONF_TOPIC], arg_type, std_string):