Open Remcodebemco opened 1 year ago
This PR sounds interesting! I have a few questions, however:
1) What is the user facing behavior when calls to luna:// are being intercept via a system notification? 2) Can we perhaps merge this behavior with WebOSControlBase directly? I'm personally against the idea of import something and then having behaviors changed behind the scene (via patching).
And some requests (so we can have this PR merged):
SystemControl.notify(..)
to include buttons
, onclose
, onfail
etc?uri.startswith('luna://')
, can you then create an instance of SystemControl(self.client)
in WebOSControlBase.request(..)
, to intercept the luna call and turn that into a notification?I just wanted to chime in and say this works quite well. I implemented it in my own API that handles many LG TV commands, but I did need to make one major change. I had an issue where the initial command to set the backlight would succeed, but subsequent calls would fail. I tracked this down to the luna_command
method overwriting cmd_info["payload"]
on the initial call, replacing the function arguments(0)
with the actual value. Subsequent calls always had the original value instead of the function. I simply changed out cmd_info["payload"]
with a new processed_payload
variable, and then I utilized this below when building the payload variable
def luna_command(*args, **kwargs):
processed_payload = process_payload(cmd_info.get("payload"), *args, **kwargs)
payload = {
"uri": "ssap://system.notifications/createAlert",
"payload": {
"message": " ",
"buttons": [{"label": "", "onClick": cmd_info["uri"], "params": processed_payload}],
"onclose": {"uri": cmd_info["uri"], "params": processed_payload},
"onfail": {"uri": cmd_info["uri"], "params": processed_payload},
},
}
alert_id = original_exec_command(self, "blank", payload)()["alertId"]
payload = {
"uri": "ssap://system.notifications/closeAlert",
"payload": {
"alertId": alert_id
}
}
original_exec_command(self, "blank", payload)()
https://github.com/bendavid/aiopylgtv found a workaround to access luna URI's that are usually hidden. I made a script that adds onto, without changing the functionality that is already there. Basically, whever "lunahack.py" is included, it adds on to the "exec_command" function within "WebOSControlBase". Whenever the uri that's given in controls.py contains "luna://" it kicks in, and handles it with the luna hack. Otherwise, it'll behave the same as original.
Feel free to do with this whatever you want, but I think some other people might like this functionality. If this isn't the way to handle pull requests, please tell me; this is my first time ever working with github :'D