Closed dix0nym closed 1 year ago
sure, here is a small example of dialogs and extensions:
answer_dialog
is not that sophisticated yet, as I assume that there is always only one open dialog.
from myjdapi import myjdapi
import time
def answer_dialog(device, type, answer):
# TODO: implement timeout if no dialog happens despite being expected
dialogs = []
while not dialogs:
dialogs = device.dialogs.list()
time.sleep(1.5)
for dialog_id in dialogs:
dialoginfo = device.dialogs.get(dialog_id)
print(f"dialoginfo: {dialoginfo}")
# get expected structure of answer and question
dialogTypeInfo = device.dialogs.getTypeInfo(dialoginfo["type"])
print(f"dialogTypeInfo: {dialogTypeInfo}")
if dialoginfo["type"] == type:
device.dialogs.answer(dialog_id, answer)
return True
return False
def install_ext(device, id):
isInstalled = device.extensions.isInstalled(id)
if isInstalled:
return True
response = device.extensions.install(id)
dialogType = "org.appwork.uio.ConfirmDialogInterface"
response = {"dontshowagainselected": True, "closereason": "OK"}
return answer_dialog(device, dialogType, response)
def toggle_ext(device, id, state):
isEnabled = device.extensions.isEnabled(id)
if isEnabled == state:
return True
return device.extensions.setEnabled(id, state)
def main():
email = ""
password = ""
device_name = ""
jd = myjdapi.Myjdapi()
jd.set_app_key("http://git.io/vmcsk")
jd.connect(email, password)
jd.update_devices()
device = jd.get_device(device_name)
r = install_ext(device, "scheduler")
print(f"[+] installed scheduler successfully: {r}")
# wait for device to restart, implementing device.ping would be a better solution
time.sleep(30)
r = toggle_ext(device, "scheduler", True)
print(f"[+] enabled scheduler successfully: {r}")
if __name__ == "__main__":
main()
The rest looks good, I didn't test much, but what I tested works, thanks for the example, and in any case nobody was using this so if somebody has issues with it, we will tackle it as it comes. If you could do those small changes I will merge it and release a new version to pip.
The rest looks good, I didn't test much, but what I tested works, thanks for the example, and in any case nobody was using this so if somebody has issues with it, we will tackle it as it comes. If you could do those small changes I will merge it and release a new version to pip.
Sounds great. What small changes are you talking about: am I missing something?
The rest looks good, I didn't test much, but what I tested works, thanks for the example, and in any case nobody was using this so if somebody has issues with it, we will tackle it as it comes. If you could do those small changes I will merge it and release a new version to pip.
Sounds great. What small changes are you talking about: am I missing something?
You should see them now, it seems I started a review adding comments but I didn't do the "submit" part, since it shows them in the PR already but I guess just for me. Just submitted now, sorry about that. The comments are mainly about documentation things that you copy pasted some stuff. Although I am fine merging it as it and fixing it myself if you want, it's really small stuff.
Thanks for reviewing my PR. Yes, I messed up some copy pasted comments, I fixed all 3 comments you mentionend. Should be good now.
Hi, thanks for your collaboration. Will try to check it out, test it and merge and release a new version as soon as I can. PD: If you have an example of usage is always appreciated for testing it.