1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-13 14:18:14 +00:00

Improvements

This commit is contained in:
Otto Winter 2018-11-30 14:21:58 +01:00
parent 8495e66ced
commit 5530dadba5
No known key found for this signature in database
GPG Key ID: DB66C0BE6013F97E
6 changed files with 45 additions and 15 deletions

View File

@ -391,7 +391,7 @@ def parse_args(argv):
subparsers = parser.add_subparsers(help='Commands', dest='command')
subparsers.required = True
config = subparsers.add_parser('config', help='Validate the configuration and spit it out.')
subparsers.add_parser('config', help='Validate the configuration and spit it out.')
parser_compile = subparsers.add_parser('compile',
help='Read the configuration and compile a program.')
@ -440,7 +440,7 @@ def parse_args(argv):
subparsers.add_parser('version', help="Print the esphomeyaml version and exit.")
clean = subparsers.add_parser('clean', help="Delete all temporary build files.")
subparsers.add_parser('clean', help="Delete all temporary build files.")
dashboard = subparsers.add_parser('dashboard',
help="Create a simple web server for a dashboard.")
@ -455,9 +455,9 @@ def parse_args(argv):
"add-on.",
action="store_true")
hass_config = subparsers.add_parser('hass-config',
help="Dump the configuration entries that should be added "
"to Home Assistant when not using MQTT discovery.")
subparsers.add_parser('hass-config',
help="Dump the configuration entries that should be added "
"to Home Assistant when not using MQTT discovery.")
return parser.parse_args(argv[1:])

View File

@ -1,13 +1,13 @@
# pylint: disable=wrong-import-position
from __future__ import print_function
import codecs
import collections
import hmac
import json
import logging
import multiprocessing
import os
import random
import subprocess
import threading
@ -26,7 +26,7 @@ from esphomeyaml.__main__ import get_serial_ports
from esphomeyaml.helpers import mkdir_p, run_system_command
from esphomeyaml.storage_json import EsphomeyamlStorageJSON, StorageJSON, \
esphomeyaml_storage_path, ext_storage_path
from esphomeyaml.util import shlex_quote
from esphomeyaml.util import shlex_quote, safe_print
# pylint: disable=unused-import, wrong-import-order
from typing import Optional # noqa
@ -78,7 +78,11 @@ class EsphomeyamlCommandWebSocket(tornado.websocket.WebSocketHandler):
data = yield self.proc.stdout.read_until_regex('[\n\r]')
except tornado.iostream.StreamClosedError:
break
self.write_message({'event': 'line', 'data': data})
try:
self.write_message({'event': 'line', 'data': data})
except UnicodeDecodeError:
data = codecs.decode(data, 'utf8', 'replace')
self.write_message({'event': 'line', 'data': data})
def proc_on_exit(self, returncode):
if not self.closed:

View File

@ -79,7 +79,7 @@ i.very-large {
.log-fg-blue { color: rgb(0,0,255); }
.log-fg-magenta { color: rgb(255,0,255); }
.log-fg-cyan { color: rgb(0,255,255); }
.log-fg-white { background-color: rgb(255,255,255); }
.log-fg-white { color: rgb(187,187,187); }
.log-bg-black { background-color: rgb(0,0,0); }
.log-bg-red { background-color: rgb(255,0,0); }
.log-bg-green { background-color: rgb(0,255,0); }

View File

@ -19,7 +19,11 @@ const colorReplace = (pre, state, text) => {
let i = 0;
if (state.carriageReturn) {
pre.removeChild(pre.lastChild);
console.log(text);
if (text !== "\n") {
// don't remove if \r\n
pre.removeChild(pre.lastChild);
}
state.carriageReturn = false;
}
@ -116,6 +120,8 @@ const colorReplace = (pre, state, text) => {
state.foregroundColor = "cyan";
break;
case 37:
state.foregroundColor = "white";
break;
case 39:
state.foregroundColor = null;
break;

View File

@ -6,10 +6,10 @@ import logging
import socket
import ssl
import sys
import time
import paho.mqtt.client as mqtt
from esphomeyaml import core
from esphomeyaml.const import CONF_BROKER, CONF_DISCOVERY_PREFIX, CONF_ESPHOMEYAML, \
CONF_LOG_TOPIC, CONF_MQTT, CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_SSL_FINGERPRINTS, \
CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_USERNAME
@ -25,9 +25,30 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
for topic in subscriptions:
client.subscribe(topic)
def on_disconnect(client, userdata, result_code):
if result_code == 0:
return
tries = 0
while True:
try:
if client.reconnect() == 0:
_LOGGER.info("Successfully reconnected to the MQTT server")
break
except socket.error:
pass
wait_time = min(2**tries, 300)
_LOGGER.warning(
"Disconnected from MQTT (%s). Trying to reconnect in %s s",
result_code, wait_time)
time.sleep(wait_time)
tries += 1
client = mqtt.Client(client_id or u'')
client.on_connect = on_connect
client.on_message = on_message
client.on_disconnect = on_disconnect
if username is None:
if config[CONF_MQTT].get(CONF_USERNAME):
client.username_pw_set(config[CONF_MQTT][CONF_USERNAME],
@ -72,8 +93,8 @@ def show_logs(config, topic=None, username=None, password=None, client_id=None):
_LOGGER.info(u"Starting log output from %s", topic)
def on_message(client, userdata, msg):
time = datetime.now().time().strftime(u'[%H:%M:%S]')
message = time + msg.payload
time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
message = time_ + msg.payload
safe_print(message)
return initialize(config, [topic], on_message, username, password, client_id)

View File

@ -5,8 +5,6 @@ import logging
import re
import sys
from esphomeyaml import core
_LOGGER = logging.getLogger(__name__)
@ -57,6 +55,7 @@ class RedirectText(object):
def __getattr__(self, item):
return getattr(self._out, item)
# pylint: disable=no-self-use
def isatty(self):
return True