mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 16:27:44 +01:00
Attempt to solve UnicodeEncodeError in HassIO when running on RPi
This commit is contained in:
parent
b799d2df7f
commit
16eeb3af31
@ -102,12 +102,15 @@ def run_miniterm(config, port, escape=False):
|
||||
|
||||
with serial.Serial(port, baudrate=baud_rate) as ser:
|
||||
while True:
|
||||
line = ser.readline()
|
||||
line = ser.readline().replace('\r', '').replace('\n', '')
|
||||
time = datetime.now().time().strftime('[%H:%M:%S]')
|
||||
message = time + line.decode('unicode-escape').replace('\r', '').replace('\n', '')
|
||||
message = time + line
|
||||
if escape:
|
||||
message = message.replace('\033', '\\033').encode('ascii', 'replace')
|
||||
print(message)
|
||||
message = message.replace('\033', '\\033')
|
||||
try:
|
||||
print(message)
|
||||
except UnicodeEncodeError:
|
||||
print(message.encode('ascii', 'backslashreplace'))
|
||||
|
||||
|
||||
def write_cpp(config):
|
||||
|
@ -57,10 +57,13 @@ 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 = msg.payload.decode('utf-8')
|
||||
message = time + msg.payload
|
||||
if escape:
|
||||
message = message.replace('\033', '\\033')
|
||||
print(time + message)
|
||||
try:
|
||||
print(message)
|
||||
except UnicodeEncodeError:
|
||||
print(message.encode('ascii', 'backslashreplace'))
|
||||
|
||||
return initialize(config, [topic], on_message, username, password, client_id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user