1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 15:18:16 +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 = parser.add_subparsers(help='Commands', dest='command')
subparsers.required = True 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', parser_compile = subparsers.add_parser('compile',
help='Read the configuration and compile a program.') 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.") 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', dashboard = subparsers.add_parser('dashboard',
help="Create a simple web server for a dashboard.") help="Create a simple web server for a dashboard.")
@ -455,7 +455,7 @@ def parse_args(argv):
"add-on.", "add-on.",
action="store_true") action="store_true")
hass_config = subparsers.add_parser('hass-config', subparsers.add_parser('hass-config',
help="Dump the configuration entries that should be added " help="Dump the configuration entries that should be added "
"to Home Assistant when not using MQTT discovery.") "to Home Assistant when not using MQTT discovery.")

View File

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

View File

@ -79,7 +79,7 @@ i.very-large {
.log-fg-blue { color: rgb(0,0,255); } .log-fg-blue { color: rgb(0,0,255); }
.log-fg-magenta { color: rgb(255,0,255); } .log-fg-magenta { color: rgb(255,0,255); }
.log-fg-cyan { color: rgb(0,255,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-black { background-color: rgb(0,0,0); }
.log-bg-red { background-color: rgb(255,0,0); } .log-bg-red { background-color: rgb(255,0,0); }
.log-bg-green { background-color: rgb(0,255,0); } .log-bg-green { background-color: rgb(0,255,0); }

View File

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

View File

@ -6,10 +6,10 @@ import logging
import socket import socket
import ssl import ssl
import sys import sys
import time
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from esphomeyaml import core
from esphomeyaml.const import CONF_BROKER, CONF_DISCOVERY_PREFIX, CONF_ESPHOMEYAML, \ 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_LOG_TOPIC, CONF_MQTT, CONF_NAME, CONF_PASSWORD, CONF_PORT, CONF_SSL_FINGERPRINTS, \
CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_USERNAME 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: for topic in subscriptions:
client.subscribe(topic) 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 = mqtt.Client(client_id or u'')
client.on_connect = on_connect client.on_connect = on_connect
client.on_message = on_message client.on_message = on_message
client.on_disconnect = on_disconnect
if username is None: if username is None:
if config[CONF_MQTT].get(CONF_USERNAME): if config[CONF_MQTT].get(CONF_USERNAME):
client.username_pw_set(config[CONF_MQTT][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) _LOGGER.info(u"Starting log output from %s", topic)
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
time = datetime.now().time().strftime(u'[%H:%M:%S]') time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
message = time + msg.payload message = time_ + msg.payload
safe_print(message) safe_print(message)
return initialize(config, [topic], on_message, username, password, client_id) return initialize(config, [topic], on_message, username, password, client_id)

View File

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