python-samsung-smarttv-2016
python-samsung-smarttv-2016 copied to clipboard
Pressing one key is ignored
It seems that if only one keycode is given it gets ignored. Debugging this time.sleep(delay) doesn't get called so the websocket disconnects as soon as it has sent the command, which seems to mean my TV ignores the request. Making the time.sleep run on every key solves this for me.
While True:
message = yield from websocket.recv()
parsed = json.loads(message)
if (parsed['event'] == 'ms.channel.connect'):
k = 0
for key in _keys:
k = k + 1
cmd = '{"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"%s","Option":"false","TypeOfRemote":"SendRemoteKey"}}' % key
yield from websocket.send(cmd)
if k != len(_keys):
time.sleep(delay)
break
time.sleep(delay)
finally:
yield from websocket.close()