mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 12:15:33 +01:00
Fix
This commit is contained in:
parent
cc514526e6
commit
5fad49ec30
@ -49,12 +49,14 @@ MQTTJsonMessageTrigger = mqtt_ns.class_('MQTTJsonMessageTrigger',
|
||||
MQTTComponent = mqtt_ns.class_('MQTTComponent', Component)
|
||||
|
||||
|
||||
def validate_broker(value):
|
||||
value = cv.string_strict(value)
|
||||
if u':' in value:
|
||||
raise vol.Invalid(u"Please specify the port using the port: option")
|
||||
if not value:
|
||||
raise vol.Invalid(u"Broker cannot be empty")
|
||||
def validate_config(value):
|
||||
if CONF_PORT not in value:
|
||||
parts = value[CONF_BROKER].split(u':')
|
||||
if len(parts) == 2:
|
||||
value[CONF_BROKER] = parts[1]
|
||||
value[CONF_PORT] = cv.port(parts[2])
|
||||
else:
|
||||
value[CONF_PORT] = 1883
|
||||
return value
|
||||
|
||||
|
||||
@ -65,10 +67,10 @@ def validate_fingerprint(value):
|
||||
return value
|
||||
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
CONFIG_SCHEMA = vol.All(vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(MQTTClientComponent),
|
||||
vol.Required(CONF_BROKER): validate_broker,
|
||||
vol.Optional(CONF_PORT, default=1883): cv.port,
|
||||
vol.Required(CONF_BROKER): cv.string_strict,
|
||||
vol.Optional(CONF_PORT): cv.port,
|
||||
vol.Optional(CONF_USERNAME, default=''): cv.string,
|
||||
vol.Optional(CONF_PASSWORD, default=''): cv.string,
|
||||
vol.Optional(CONF_CLIENT_ID): vol.All(cv.string, vol.Length(max=23)),
|
||||
@ -97,7 +99,7 @@ CONFIG_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_TOPIC): cv.subscribe_topic,
|
||||
vol.Optional(CONF_QOS, default=0): cv.mqtt_qos,
|
||||
}),
|
||||
})
|
||||
}), validate_config)
|
||||
|
||||
|
||||
def exp_mqtt_message(config):
|
||||
|
@ -24,7 +24,7 @@ import tornado.websocket
|
||||
|
||||
from esphomeyaml import const
|
||||
from esphomeyaml.__main__ import get_serial_ports
|
||||
from esphomeyaml.helpers import run_system_command
|
||||
from esphomeyaml.helpers import run_system_command, mkdir_p
|
||||
from esphomeyaml.storage_json import StorageJSON, ext_storage_path
|
||||
from esphomeyaml.util import shlex_quote
|
||||
|
||||
@ -38,7 +38,7 @@ COOKIE_SECRET = None
|
||||
USING_PASSWORD = False
|
||||
ON_HASSIO = False
|
||||
USING_HASSIO_AUTH = True
|
||||
HASSIO_MQTT_CONFIG = {}
|
||||
HASSIO_MQTT_CONFIG = None
|
||||
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
@ -453,10 +453,10 @@ def _get_mqtt_config_impl():
|
||||
}
|
||||
|
||||
req = requests.get('http://hassio/services/mqtt', headers=headers)
|
||||
mqtt_config = req.json()
|
||||
mqtt_config = req.json()['data']
|
||||
return {
|
||||
'addon': mqtt_config['addon'],
|
||||
'host': mqtt_config['host'],
|
||||
'ssl': mqtt_config['ssl'],
|
||||
'host': mqtt_config['host'] + ':' + mqtt_config['port'],
|
||||
'username': mqtt_config.get('username', ''),
|
||||
'password': mqtt_config.get('password', '')
|
||||
}
|
||||
@ -465,14 +465,14 @@ def _get_mqtt_config_impl():
|
||||
def get_mqtt_config_lazy():
|
||||
global HASSIO_MQTT_CONFIG
|
||||
|
||||
if not ON_HASSIO or HASSIO_MQTT_CONFIG is None:
|
||||
if not ON_HASSIO:
|
||||
return None
|
||||
|
||||
if not HASSIO_MQTT_CONFIG:
|
||||
if HASSIO_MQTT_CONFIG is None:
|
||||
try:
|
||||
HASSIO_MQTT_CONFIG = _get_mqtt_config_impl()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
HASSIO_MQTT_CONFIG = None
|
||||
pass
|
||||
|
||||
return HASSIO_MQTT_CONFIG
|
||||
|
||||
@ -486,8 +486,8 @@ def start_web_server(args):
|
||||
global COOKIE_SECRET
|
||||
|
||||
CONFIG_DIR = args.configuration
|
||||
if not os.path.exists(CONFIG_DIR):
|
||||
os.makedirs(CONFIG_DIR)
|
||||
mkdir_p(CONFIG_DIR)
|
||||
mkdir_p(os.path.join(CONFIG_DIR, ".esphomeyaml"))
|
||||
|
||||
ON_HASSIO = args.hassio
|
||||
if ON_HASSIO:
|
||||
|
Loading…
Reference in New Issue
Block a user