Fix MQTT not showing logs with Python 3 (#797)

* Fix MQTT logging for Python 3

* Also fix captive portal PACKED
This commit is contained in:
Otto Winter 2019-10-24 20:11:17 +02:00
parent 576d5021fd
commit 681dcb51da
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E
2 changed files with 5 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#include <DNSServer.h>
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#include "esphome/core/preferences.h"
#include "esphome/components/web_server_base/web_server_base.h"

View file

@ -15,6 +15,7 @@ from esphome.const import CONF_BROKER, CONF_DISCOVERY_PREFIX, CONF_ESPHOME, \
CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_USERNAME
from esphome.core import CORE, EsphomeError
from esphome.helpers import color
from esphome.py_compat import decode_text
from esphome.util import safe_print
_LOGGER = logging.getLogger(__name__)
@ -22,6 +23,7 @@ _LOGGER = logging.getLogger(__name__)
def initialize(config, subscriptions, on_message, username, password, client_id):
def on_connect(client, userdata, flags, return_code):
_LOGGER.info("Connected to MQTT broker!")
for topic in subscriptions:
client.subscribe(topic)
@ -94,7 +96,8 @@ def show_logs(config, topic=None, username=None, password=None, client_id=None):
def on_message(client, userdata, msg):
time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
message = time_ + msg.payload
payload = decode_text(msg.payload)
message = time_ + payload
safe_print(message)
return initialize(config, [topic], on_message, username, password, client_id)