mirror of
https://github.com/joBr99/nspanel-lovelace-ui.git
synced 2025-12-19 14:14:12 +01:00
update python test script to support utf8
This commit is contained in:
@@ -5,7 +5,7 @@ import codecs
|
|||||||
print("Calculate NSPanel hex command from JSON payload\n")
|
print("Calculate NSPanel hex command from JSON payload\n")
|
||||||
|
|
||||||
#value = input("Enter JSON:\n")
|
#value = input("Enter JSON:\n")
|
||||||
value = "entityUpdHeading,Heading1234"
|
value = "weatherUpdate~1~9.4 C~Wed~2~14.1 C~Thu~3~12.4 C~Fri~4~7.6 C~Sat~5~8.5 C~6~90 %"
|
||||||
|
|
||||||
def crc16(data:bytes, poly:hex=0xA001) -> str:
|
def crc16(data:bytes, poly:hex=0xA001) -> str:
|
||||||
'''
|
'''
|
||||||
@@ -21,13 +21,13 @@ def crc16(data:bytes, poly:hex=0xA001) -> str:
|
|||||||
return crc
|
return crc
|
||||||
|
|
||||||
|
|
||||||
payload = bytes(value, 'ascii')
|
payload = bytes(value, 'utf-8')
|
||||||
|
|
||||||
header = binascii.unhexlify('55BB')
|
header = binascii.unhexlify('55BB')
|
||||||
|
|
||||||
print("length:", len(value))
|
print("length:", len(payload))
|
||||||
|
|
||||||
length = len(value).to_bytes(2, 'little')
|
length = len(payload).to_bytes(2, 'little')
|
||||||
|
|
||||||
bytes_payload = header + length + payload
|
bytes_payload = header + length + payload
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user