mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 13:24:15 +01:00
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:
parent
576d5021fd
commit
681dcb51da
@ -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"
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user