Change lib to only support 2011 models

This commit is contained in:
sqozz 2019-01-31 18:10:45 +01:00
parent 22c7791baa
commit 2521428614
2 changed files with 149 additions and 76 deletions

View File

@ -7,4 +7,5 @@ if __name__ == "__main__":
key = raw_input('Enter pairing key: ')
remote.set_pairing_key(key)
remote.send_command(Remote.VOLUME_UP)
print("EXAMPLE: remote.send_command(INSERT_CMD_HERE, remote.session)")
import pdb; pdb.set_trace()

222
lg.py
View File

@ -23,12 +23,13 @@ class Remote():
self.pair_key = pair_key
self.ip_address = ip_address
self.session = None
if not self.ip_address:
raise Remote.NoTVFound
if self.pair_key:
self.get_session()
self.session = self.get_session()
else:
self.request_pair()
@ -82,7 +83,7 @@ class Remote():
"""
self.pair_key = pair_key
self.get_session()
self.session = self.get_session()
def make_request(self, endpoint, content, extra_headers={}):
"""
@ -108,7 +109,7 @@ class Remote():
<type>AuthKeyReq</type>
</auth>
"""
self.make_request('/roap/api/auth', content)
self.make_request('/hdcp/api/auth', content)
def get_session(self):
"""
@ -122,10 +123,10 @@ class Remote():
<value>{0}</value>
</auth>
""".format(self.pair_key)
response = self.make_request('/roap/api/auth', content)
response = self.make_request('/hdcp/api/auth', content)
return response.find('session').text
def send_command(self, code):
def send_command(self, code, session):
"""
Send a remote control key command. Ignores response for now.
"""
@ -135,11 +136,12 @@ class Remote():
content = """
<?xml version="1.0" encoding="utf-8"?>
<command>
<name>HandleKeyInput</name>
<session>{1}</session>
<type>HandleKeyInput</type>
<value>{0}</value>
</command>
""".format(code)
self.make_request('/roap/api/command', content)
""".format(code, session)
self.make_request('/hdcp/api/dtv_wifirc', content)
def send_multiple(self, codes, delay=0.2):
"""
@ -149,7 +151,7 @@ class Remote():
"""
for code in codes:
self.send_command(code)
self.send_command(code, self.session)
time.sleep(delay)
# exceptions
@ -168,71 +170,141 @@ class Remote():
"""
pass
# heavily inspired by https://github.com/dreamcat4/lgremote/blob/master/lgremote
commands = {}
# command code shortcuts
# all work with 42LW579S-ZD
menus = {
"STATUS_BAR" : 35,
"QUICK_MENU" : 69,
"HOME_MENU" : 67,
"PREMIUM_MENU" : 89
}
POWER = 1
NUM_0 = 2
NUM_1 = 3
NUM_2 = 4
NUM_3 = 5
NUM_4 = 6
NUM_5 = 7
NUM_6 = 8
NUM_7 = 9
NUM_8 = 10
NUM_9 = 11
UP = 12
DOWN = 13
LEFT = 14
RIGHT = 15
OK = 20
HOME = 21
MENU = 22
BACK = 23
VOLUME_UP = 24
VOLUME_DOWN = 25
MUTE = 26
CHANNEL_UP = 27
CHANNEL_DOWN = 28
BLUE = 29
GREEN = 30
RED = 31
YELLOW = 32
PLAY = 33
PAUSE = 34
STOP = 35
FF = 36
REW = 37
SKIP_FF = 38
SKIP_REW = 39
REC = 40
REC_LIST = 41
LIVE = 43
EPG = 44
INFO = 45
ASPECT = 46
EXT = 47
PIP = 48
SUBTITLE = 49
PROGRAM_LIST = 50
TEXT = 51
MARK = 52
_3D = 400
_3D_LR = 401
DASH = 402
PREV = 403
FAV = 404
QUICK_MENU = 405
TEXT_OPTION = 406
AUDIO_DESC = 407
NETCAST = 408
ENERGY_SAVE = 409
AV = 410
SIMPLINK = 411
EXIT = 412
RESERVE = 413
PIP_CHANNEL_UP = 414
PIP_CHANNEL_DOWN = 415
PIP_SWITCH = 416
APPS = 417
# all work with 42LW579S-ZD
power_controls = {
"POWER" : 8,
"SLEEP_MENU" : 14
}
# all work with 42LW579S-ZD
navigation_controls = {
"LEFT" : 7,
"RIGHT" : 6,
"UP" : 64,
"DOWN" : 65,
"SELECT" : 68,
"BACK" : 40,
"EXIT" : 91,
"RED" : 114,
"GREEN" : 113,
"YELLOW" : 99,
"BLUE" : 97
}
# all work with 42LW579S-ZD
keypad_controls = {
"0" : 16,
"1" : 17,
"2" : 18,
"3" : 19,
"4" : 20,
"5" : 21,
"6" : 22,
"7" : 23,
"8" : 24,
"9" : 25,
"_" : 76,
}
# untested
playback_controls = {
"PLAY" : 176,
"PAUSE" : 186,
"FAST_FORWARD" : 142,
"REWIND" : 143,
"STOP" : 177,
"RECORD" : 189
}
# untested
tv_controls = {
"CHANNEL_UP" : 0,
"CHANNEL_DOWN" : 1,
"CHANNEL_BACK" : 26,
"FAVORITES" : 30,
"TELETEXT" : 32,
"T_OPT" : 33,
"CHANNEL_LIST" : 83,
"GUIDE" : 169,
"INFO_TOGGLE" : 170,
"INFO" : 217,
"LIVE_TV" : 158
}
# all work with 42LW579S-ZD
input_controls = {
"TV_RADIO" : 15,
"SIMPLINK" : 126,
"INPUT" : 11,
"COMPONENT_RGB_HDMI" : 152,
"RGB" : 213, #215 seems to do the same
"COMPONENT" : 191,
"ANTENNA" : 214, #240 does the same without channels programmed. 240 could also be CABLE input
"HDMI" : 198,
"HDMI1" : 206,
"HDMI2" : 204,
"HDMI3" : 233,
"HDMI4" : 218,
"AV1" : 90,
"AV2" : 208,
"AV3" : 209,
"USB" : 124,
"SLIDESHOW_USB1" : 238,
"SLIDESHOW_USB2" : 168
}
# should work
audio_controls = {
"VOLUME_UP" : 2,
"VOLUME_DOWN" : 3,
"MUTE" : 9,
"AUDIO" : 10,
"SOUND_MODE" : 82,
"SUBTITLE_LANGUAGE" : 57,
"AUDIO_DESCRIPTION" : 145,
"FACTORY_SOUND_CHECK" : 253
}
# all work with 42LW579S-ZD
picture_controls = {
"AV_MODE" : 48,
"PICTURE_MODE" : 77,
"RATIO" : 121,
"RATIO_4_3" : 118,
"RATIO_16_9" : 119,
"ENERGY_SAVING" : 149, #only works as expected in quick-menu. Outside of it it sets Energy Saving to Auto and toggles the GREEN_EYE_CHECK menu. Maybe due to previous tinkering with POWER_ONLY mode.
"CINEMA_ZOOM" : 175,
"3D" : 220,
"FACTORY_PICTURE_CHECK" : 252
}
# not sure about these
self_diagnosis = {
"DIAG1" : 164,
"DIAG2" : 165,
"DIAG3" : 173,
"DIAG4" : 188,
"DIAG5" : 190,
"PICTURE_TEST" : 249
}
# see: http://openlgtv.org.ru/wiki/index.php/Hidden_service_modes_/_menus
hidden_menues = {
"INSTALLATION_MENU" : 207,
"POWER_ONLY" : 254,
"EZ_ADJUST" : 255,
"IN_START" : 251
}
HAPPENS_WITHOUT_CONFIRMATION = { "FACTORY_RESET" : 250 }