Skip to content

Commit

Permalink
Config validation for automation MQTT trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
jaharkes committed Apr 7, 2016
1 parent fca08b0 commit 0ef0d4b
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions homeassistant/components/automation/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
For more details about this automation rule, please refer to the documentation
at https://home-assistant.io/components/automation/#mqtt-trigger
"""
import logging
import voluptuous as vol

import homeassistant.components.mqtt as mqtt
from homeassistant.const import CONF_PLATFORM
import homeassistant.helpers.config_validation as cv

DEPENDENCIES = ['mqtt']

CONF_TOPIC = 'topic'
CONF_PAYLOAD = 'payload'

TRIGGER_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): mqtt.DOMAIN,
vol.Required(CONF_TOPIC): mqtt.valid_subscribe_topic,
vol.Optional(CONF_PAYLOAD): cv.string,
})


def trigger(hass, config, action):
"""Listen for state changes based on configuration."""
topic = config.get(CONF_TOPIC)
topic = config[CONF_TOPIC]
payload = config.get(CONF_PAYLOAD)

if topic is None:
logging.getLogger(__name__).error(
"Missing configuration key %s", CONF_TOPIC)
return False

def mqtt_automation_listener(msg_topic, msg_payload, qos):
"""Listen for MQTT messages."""
if payload is None or payload == msg_payload:
Expand Down

0 comments on commit 0ef0d4b

Please sign in to comment.