Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Modify a Quickapp from one single JSON table


Question

Posted

Hello

IF anyone is more experienced with API functions regarding a quickapp device,maybe can help me.

 

As far as a know, a quickapp, represented by a .fqa file is a JSON table.

So if I have a quickapp, with id 150, is it possible to completly replace, modify its data, but simple using a api.post or put request?

Will it preserve its ID?

My goal is, to update an existing quickapp files, layouts by posting a properly formatted JSON table.

Can we do it?

 

If yes, what would be that JSON look like?

 

Thanks ahead

10 answers to this question

Recommended Posts

  • 0
Posted

Yes, you can. You need to do it in pieces.

Here is a Python version from my emulator

Please login or register to see this code.

 

1. First add each  new quickAppfiles with with a loop

api.post("/quickApp/" .. <id> .. "/files", <file>)

 

2. Then modify all exiting files with the multi-file put

api.put("/quickApp/" .. <id> .. "/files", <files>)

 

3. Then loop and delete all files that should not be there with

api.delete("/quickApp/" .. <id> .. "/files/" .. <filename>)

 

4. Lastly, update the properties with

api.put("/devices/" .. <id>, {

   properties = {

   uiCallbacks = newUiCallbacks,

   viewLayout = newViewLayout,

   quickAppVariables = newQquickAppVariables,

   }

})

 

You can also update some of the top levels key like name, visible, etc

You can't update type

 

 

  • 0
  • Inquirer
  • Posted (edited)

    Daer Jan, i am getting to get this work..

    The only thing is, that

    34 minutes ago, jgab said:

    Yes, you can. You need to do it in pieces.

    Here is a Python version from my emulator

    Please login or register to see this code.

     

    1. First add each  new quickAppfiles with with a loop

    api.post("/quickApp/" .. <id> .. "/files", <file>)

     

    2. Then modify all exiting files with the multi-file put

    api.put("/quickApp/" .. <id> .. "/files", <files>)

     

    3. Then loop and delete all files that should not be there with

    api.delete("/quickApp/" .. <id> .. "/files/" .. <filename>)

     

    4. Lastly, update the properties with

    api.put("/devices/" .. <id>, {

       properties = {

       uiCallbacks = newUiCallbacks,

       viewLayout = newViewLayout,

       quickAppVariables = newQquickAppVariables,

       }

    })

     

    You can also update some of the top levels key like name, visible, etc

    You can't update type

     

     

    it seems that i am getting to it, but for some reason,, the quickapp  file structure that i dowloaded from github looks a bit different, opposed to a json structure in swagger. This is what it looks like.

     

     

     

    Please login or register to see this code.

    sorry i can't fromat it to json here..but there are different properties..i hope i wont ruin my code on Hc3 using data from this..

    Forexample here there is no properties section but initialproperties...

    3 minutes ago, Neo Andersson said:

    Daer Jan, i am getting to get this work..

    The only thing is, that

    it seems that i am getting to it, but for some reason,, the quickapp  file structure that i dowloaded from github looks a bit different, opposed to a json structure in swagger. This is what it looks like.

     

     

     

    Please login or register to see this code.

    sorry i can't fromat it to json here..but there are different properties..i hope i wont ruin my code on Hc3 using data from this..

    Forexample here there is no properties section but initialproperties...

     

     

    Please login or register to see this image.

    /monthly_2023_08/jsonfile.png.c2c2d42d0ac8100422003ccd5c9a0084.png" />

    Edited by Neo Andersson
    • 0
  • Inquirer
  • Posted
    13 minutes ago, Neo Andersson said:

    Daer Jan, i am getting to get this work..

    The only thing is, that

    it seems that i am getting to it, but for some reason,, the quickapp  file structure that i dowloaded from github looks a bit different, opposed to a json structure in swagger. This is what it looks like.

     

     

     

    Please login or register to see this code.

    sorry i can't fromat it to json here..but there are different properties..i hope i wont ruin my code on Hc3 using data from this..

    Forexample here there is no properties section but initialproperties...

     

     

     

    Please login or register to see this image.

    /monthly_2023_08/jsonfile.png.c2c2d42d0ac8100422003ccd5c9a0084.png" />

     

     

     

     

    Okay, i could update the qa on HC3 using initialProperties instead of properties. (i had a typo)

    but i am curios, why does it have different structure naming

    • 0
    Posted

    The .fqa format is a bit different from the installed device structure. It contains the data to install a QA - but no deviceId etc as those are assigned by the system.

    and initialProperties are typically viewLayout, uiCallbacks, and quickAppVariables

    Please login or register to see this code.

    If you are going to update an existing QA you need to work with the device structure (and the QA files). Not the .fqa structure

    • 0
  • Inquirer
  • Posted
    7 minutes ago, jgab said:

    The .fqa format is a bit different from the installed device structure. It contains the data to install a QA - but no deviceId etc as those are assigned by the system.

    and initialProperties are typically viewLayout, uiCallbacks, and quickAppVariables

    Please login or register to see this code.

    If you are going to update an existing QA you need to work with the device structure (and the QA files). Not the .fqa structure

    Yes, i assumed that, but when i download i fqa file from HC3, and upload it to github, it carries that fqa structure and not the installed device structure, so i cant use other data, than the fqa.

    • 0
    Posted
    1 minute ago, Neo Andersson said:

    Yes, i assumed that, but when i download i fqa file from HC3, and upload it to github, it carries that fqa structure and not the installed device structure, so i cant use other data, than the fqa.

    yes, but then just pick the pieces from the fqa struct.

    • 0
  • Inquirer
  • Posted
    1 minute ago, jgab said:

    yes, but then just pick the pieces from the fqa struct.

    Thats what i did. I was jsut curios, wouldnt this somehow get out of control, and ruin something on my hc3, as the structures are different, but probably nothing to worry about.

    • 0
  • Inquirer
  • Posted
    22 hours ago, jgab said:

    yes, but then just pick the pieces from the fqa struct.

    Jan, can you please assist a little bit...

     

    I think there is no option to get the current quickapp files content. The formula  api.get("/quickApp/" .. <id> .. "/files") does not return the content. It only returns these values. {name, isMain,isOpen}. It is like a horror. When downloading a QA, with extension .fqa, that file actually does contain the full file structure wih contents in it too. So there is no possibility to get any QA's file's content right from HC3.

    If i want to approach it from api.get("/devices/"..id), this table doesnt contain any data about files. If i want to make a archive, before updating the file, i just cant do it locally, as i can't get to the file's content. I need to download the fqa, upload it to github, and later download it from there i think. Or is there any mode, how to get the files content of a QA on HC3?

    • 0
    Posted

    Think about  api.get("/quickApp/" .. <id> .. "/files") as the directory listing - you get the filenames. Then get each file content by

    api.get("/quickApp/"..<id>.."/files/"..<name>) 

    • 0
  • Inquirer
  • Posted
    7 hours ago, jgab said:

    Think about  api.get("/quickApp/" .. <id> .. "/files") as the directory listing - you get the filenames. Then get each file content by

    api.get("/quickApp/"..<id>.."/files/"..<name>) 

    Yes, i figured that out..SO i think tehre is no other better approach to get a QA device data in a LUA code, then upload it to Github, and later when its neaded get it back with an API request and update the original QA device in HC3. 

    I need to parse the device data in HC3, create a JSON from it, format it in a way with initialProperties, than upload that json to Github. The reverse process then fetches that Github JSON, parses it and with an api.put request overwrite the device data on HC3.

    Pretty cumbersome..but might work

    Thanks

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...