Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3 support #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Description

# * All Scripts are written using python 2.7
https://github.com/clach04/Broadlink-e-control-db-dump

Python 3.x and 2.7 scripts for processing data for BroadLink InfraRed / IR devices like the BroadLink New RM Mini3 IR Control Hub ,Smart Home Wi-Fi Enabled Infrared Universal Remote Control, One for All Control

Friendly fork of https://github.com/NightRang3r/Broadlink-e-control-db-dump - pending merges of PRs

# econtrol-db-dump.py

Expand Down
2 changes: 1 addition & 1 deletion broadlink_to_home_assistant_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
packet = binascii.unhexlify(packet)
packet = base64.b64encode(packet).decode('utf8')

print packet
print(packet)
64 changes: 54 additions & 10 deletions getBroadlinkSharedData.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,49 @@

'''

import simplejson as json
import base64, sys

try:
# Python 2.6+
import json
except ImportError:
try:
# from http://code.google.com/p/simplejson
import simplejson as json
except ImportError:
json = None

if json is None:

def dump_json(x, indent=None):
"""dumb not safe!
Works for the purposes of this specific script as quotes never
appear in data set.

Parameter indent ignored"""
if indent:
result = pprint.pformat(x, indent)
else:
result = repr(x).replace("'", '"')
return result

def load_json(x):
"""dumb not safe! Works for the purposes of this specific script"""
x = x.replace('\r', '')
return eval(x)
else:
dump_json = json.dumps
load_json = json.loads


IS_PY2 = sys.version_info[0] == 2

def hex2bin(x):
if IS_PY2:
return x.decode('hex')
else:
return bytes.fromhex(x)


if len(sys.argv) > 1:
MultipleCode = sys.argv[1]
Expand All @@ -36,23 +76,25 @@


jsonSubIr = open("jsonSubIr").read()
jsonSubIrData = json.loads(jsonSubIr)
jsonSubIrData = load_json(jsonSubIr)



for i in range(0, len(jsonSubIrData)):
print "ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name']
print("ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name'])


choice = input("Select accessory ID: ")
choice = int(choice)

for i in range(0, len(jsonSubIrData)):
if jsonSubIrData[i]['id'] == choice:
accessory_name = jsonSubIrData[i]['name']
print "[+] You selected: ", accessory_name
print("[+] You selected: ", accessory_name)


jsonButton = open("jsonButton").read()
jsonButtonData = json.loads(jsonButton)
jsonButtonData = load_json(jsonButton)


for i in range(0, len(jsonButtonData)):
Expand All @@ -62,16 +104,18 @@


jsonIrCode = open("jsonIrCode").read()
jsonIrCodeData = json.loads(jsonIrCode)
jsonIrCodeData = load_json(jsonIrCode)


print "[+] Dumping codes to " + accessory_name + ".txt"
codesFile = open(accessory_name + '.txt', 'w')
print("[+] Dumping codes to " + accessory_name + ".txt")
codesFile = open(accessory_name + '.txt', 'wb')

for i in range(0, len(jsonIrCodeData)):
for j in range(0, len(buttonIDS)):
if jsonIrCodeData[i]['buttonId'] == buttonIDS[j]:
code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code']) * int(MultipleCode)
code_base64 = code.decode("hex").encode("base64")
code_bytes = hex2bin(code)
code_base64 = base64.b64encode(code_bytes)
code_base64 = code_base64.decode('utf-8')
result = "Button Name: " + buttonNames[j] + "\r\n" + "Button ID: " + str(jsonIrCodeData[i]['buttonId']) + "\r\n" + "Code: " + code + "\r\n" + "Base64: " + "\r\n" + code_base64 + "\r\n"
codesFile.writelines(result.encode('utf-8'))
codesFile.write(result.encode('utf-8'))