Skip to content

Conversation

dix0nym
Copy link
Contributor

@dix0nym dix0nym commented May 6, 2023

No description provided.

@mmarquezs
Copy link
Owner

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.

@dix0nym
Copy link
Contributor Author

dix0nym commented May 13, 2023

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()

@mmarquezs
Copy link
Owner

mmarquezs commented May 21, 2023

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.

@dix0nym
Copy link
Contributor Author

dix0nym commented May 29, 2023

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?

Comment on lines 221 to 222
:param params: A dictionary with options. The default dictionary is
configured so it returns you all the downloads with all details, but you
Copy link
Owner

@mmarquezs mmarquezs May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is copy pasted from something else, here it references downloads for example and this doesn't return downloads, you don't need to add the docs if you don't want but I would appreciate it if don't keep unrelated comments.


def listEnum(self, type):
"""
:return: List<AdvancedConfigAPIEntry>
Copy link
Owner

@mmarquezs mmarquezs May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't return a list of AdvancedConfigAPIEntry.
Based on the docs, it's List<EnumOption>. I mean neither of those case we implement the object in the list... it's not great but fine, ends up as dictionary. But I wanted the comment to at least reference the one mentioned in the API.

}]):
"""
:param params: A dictionary with options. The default dictionary is
configured so it returns you all the downloads with all details, but you
Copy link
Owner

@mmarquezs mmarquezs May 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before here. It mentions downloads again.

@mmarquezs
Copy link
Owner

mmarquezs commented May 30, 2023

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.

@dix0nym dix0nym requested a review from mmarquezs June 1, 2023 19:58
@dix0nym
Copy link
Contributor Author

dix0nym commented Jun 1, 2023

Thanks for reviewing my PR. Yes, I messed up some copy pasted comments, I fixed all 3 comments you mentionend. Should be good now.

@mmarquezs mmarquezs merged commit f1dd363 into mmarquezs:master Jun 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants