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

Create a sharable library of functions??


Question

Posted (edited)

Hello

I know that this topic was probably answered in many posts, but maybe someone got any idea about it
I am using many many custom functions..And i could not find any reasonable way to reuse that library of my functions.
We have to insert the whole file again and again (like i did when we were using JGAB's fibaro etxra, or evetnLib)
I am just wondering, is it gonna ever happened in Fibaro, that we will be able to - maybe send data between quickapps? Or
load a code somehow inside a quickapp? or is this too futuristic desire?
I am pretty sure, JGAB sees the big picture about this, and if he did not come out with some solution, then probably there is no solution, but copy paste all the time the reused code snippets is just soo freaking baaad.
Anyway, if any fibaro developer can comment this, i would really appreciate it. Will this ever get changed?? Like will the entire quickapp developement handling improved? CSS,html, more controls, data sharing between quickapps..or at least some input elements?? textboxes?? some datepickers, or

whatever..will this ever get some update??
thanks for any answer
 

Edited by Neo Andersson

5 answers to this question

Recommended Posts

  • 0
Posted

So, there are 2 possible solutions today.
1. Have lua code that copies over QA files from a "Library QA", to your QA. It could check if the file and version is already installed before starting up.

1.1 Download the file from a GitHub repo and install instead of another QA, but that requires that there is always internet connection.

 

2. Don't copy the file, have a "library QA! and call the functions using a more elaborate fibaro.call.
2.1 I did a more elaborate export/import function 2020, 

2.2 There is also the more lightweight  rpc library I have used in the past
 

Please login or register to see this code.

 

The the library QA, assume it's id is 777,  just declares global lua functions
 

Please login or register to see this code.

 

and the client does
 

Please login or register to see this code.

 

 

But to be honest, I don't use this so much myself.
Instead I develop with plua where I can declare library files to be automatically included when I compile QAs - much simpler...
 

  • Like 1
  • Thanks 1
  • 0
  • Inquirer
  • Posted (edited)

    Jan, i have choosen your second point, so i am using github, download the file, update it (or create) in the plugin file list. Works nicely..
    But can we somehow force upate the editor after the library got downloaded and the file got created? It shows up to me only after i exit the editor and re-enter.
    plugin.restart() did not help.

    Edited by Neo Andersson
    • 0
    Posted

    No, we have no "api" into the editor itself.

    • 0
  • Inquirer
  • Posted (edited)

    @jgabJan may i get some help here

    I have created a function GHpuler(qa_id) that pulls the github asset down , and uploads it to a given QA (id is the argument). This function sits in a quickapp that serves as the central manager for many other stuff, so other QAs are calling this central QA for other things too, so for me it is the best way to define the GHpuller inside the central QA, and whichever other QA needs the library, it can call it like

    Please login or register to see this code.

    and this works nicely. The only problem is, to detect if the library is already inserted or not. If i call the puller inside the onInit it creates an infitin loop
    I tried to add a QA variable "libraryLoaded" and set it to "true" (string) after the pull happened, and this avioded the inifinte loop, but for some reason, this made the QA variable "libraryLoaded" non editable, so user can not update the library by setting the QA variable to false. I dont know the reason because i was setting it to true using "true" as string, and vice versa.

    So i tried another way..I placed inside the libray file a single global variable LIBRARY_LOADED = true, and i am checking it before the fetch call. Idea was, that if the insert happens, the LIBRARY_LOADED quickapp global gets created, so we can check upon that, but i am stuck here a bit..becuase i think it is not granted that the LIBRARY_LOADED global will be initialized before the onInit finishes, so i dont know if this will work always, or it just worked because i had some luck
     

    Please login or register to see this code.


    What idea can be used, to avoid inifite fetching, and detecting if the library is loaded?? Or how else to implement some version follow if any update is needed??
    I could not find any reasonable way how to handle it saefly.

    Edited by Neo Andersson
    • 0
  • Inquirer
  • Posted

    okay i came up with an approach..still not sure if this can work

    The central QA handles averything around the pull
    The target QA where we want to install/update the library calls the central function with an additonal argument where the current version of his library is sent to the central QA
    The central QA checks the last commit message of the library in github. I they are the same, we do nothing
    On every new commit push we create the commit message from the current lbrary's version variable..
    i think this can work

    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...