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


HC3 QuickApps coding - tips and tricks


jgab

Recommended Posts

  • Topic Author
  • 16 minutes ago, rangee said:

     

     

    Thank you very much! I understand.

    Proxy QuickApp is for off-line debugging.

    Both features will be very helpful when I create more then 100 QuickApp.

    Thank you again.

    Yes, the fibaroapiHC3.lua file is for off-line debugging. It tries to emulate the HC3 environment as close as possible.

    Do you use an off-line Lua IDE? I use Zerobrane but I'm looking into VisualStudio - issue is with libraries (sockets / http etc)

    Edited by jgab
    Link to comment
    Share on other sites

    QuickApp:xxxClicked is not working with 5.021.38 like before, one have to call it from the button itself with self:xxxClicked (or what so ever Name was given for the function that Need to be executed once button got clicked)

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, tinman said:

    QuickApp:xxxClicked is not working with 5.021.38 like before, one have to call it from the button itself with self:xxxClicked (or what so ever Name was given for the function that Need to be executed once button got clicked)

    It worked in 5.020.... Oh, well... 

    Link to comment
    Share on other sites

  • Topic Author
  • 37 minutes ago, tinman said:

    QuickApp:xxxClicked is not working with 5.021.38 like before, one have to call it from the button itself with self:xxxClicked (or what so ever Name was given for the function that Need to be executed once button got clicked)

    @tinman ...and how do you get the slider value from the "button code"?

    Link to comment
    Share on other sites

    3 hours ago, jgab said:

    @tinman ...and how do you get the slider value from the "button code"?

     

    inside of slider you can use "value" - it works 

     

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, petrkl12 said:

     

    inside of slider you can use "value" - it works 

     

    Thanks!

    Link to comment
    Share on other sites

    there is however small bug with slider, one can see the value/slider Position, but once the preview got closed and one change the few somewhere and back, the value is still properly set, but position not

     

    Please login or register to see this image.

    /monthly_2020_02/image.png.ddabe945d7df1e312d9e830909eef3dd.png" />image.png.735dcf0564ea262750b0f0d05e60fb8a.png

     

    not tragic, but god to know it.

     

    A small loop to set position based on last saved is good enough

     

    Please login or register to see this code.

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, tinman said:

    there is however small bug with slider, one can see the value/slider Position, but once the preview got closed and one change the few somewhere and back, the value is still properly set, but position not

    A small loop to set position based on last saved is good enough

     

    An improvement that the UI shows shows up in the dashboard. 

     

    In the "device editing/coding" view the UI preview doesn't work at all for me now. In the past, sometimes the self:updateView worked. Now it's dead even if I toggle the blue "Preview slider" back-and-forth (which I at least imagined sometimes helped in the past)

    Link to comment
    Share on other sites

  • Topic Author
  • some 5.021.38 issues

    Please login or register to see this code.

    still gives 501.

    Please login or register to see this code.

    marshalling of arguments are still "helpful", converting strings that "look like" numbers and booleans to actual numbers and boolean...

     

    In the swagger panel, just trying to expand the /plugins/getView view hangs the whole swagger window - do other have the same problem?

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • More 5.021.38 issues I have

    Please login or register to see this code.

    hangs for ~60s but eventually emits the event. Can anyone else replicate that? (only from externally, on the HC3 emitCustomEvent works directly, including the swagger interface)

     

    Please login or register to see this code.

    hangs if there are no events/changes. ~30s - it's been there since 5.020.

    Edited by jgab
    Link to comment
    Share on other sites

    17 minutes ago, jgab said:

    More 5.021.38 issues I have

    Please login or register to see this code.

    hangs for ~60s but eventually emits the event. Can anyone else replicate that? (only from externally, on the HC3 emitCustomEvent works directly, including the swagger interface)

     

    I can confirm complete freeze of HC3 for cca 60s. I didn't see any results/events from curl ....

     

    Link to comment
    Share on other sites

    1 hour ago, jgab said:

    hangs if there are no events/changes. ~30s - it's been there since 5.020.

    IMHO that is by design, if there is nothing in the queue on the HC2/HC3 the TCP (http) channel is "open" but there is no data flow. As soon as the HC has data, the receiving part will unblock. I actually use this aspect to get fast response and crude timing at the same time.

    Edited by petergebruers
    Link to comment
    Share on other sites

  • Topic Author
  • 49 minutes ago, petergebruers said:

    IMHO that is by design, if there is nothing in the queue on the HC2/HC3 the TCP (http) channel is "open" but there is no data flow. As soon as the HC has data, the receiving part will unblock. I actually use this aspect to get fast response and crude timing at the same time.

    I can kind of understand that and from the outside I can hang in another thread which is more efficient than polling - but on the HC3 it hangs the scene/quick app  (setTimeout/setInterval, and the quickapp can't even respond to UI  buttons). Would like to have a "peek" api to see if there is something before accidentally hanging.

    So the way I get around it now is to generate an event last in my refreshState loop. Used to use emitCustomEvent but now they hang so now I resorted to just increment a global variable... (I run the /refreshState outside the HC3)

     

    Even better, provide a callback with new events - and with a filter.

    Edited by jgab
    Link to comment
    Share on other sites

    @jgab how does it look with ER for HC3? I saw something in your github but I don't know if it is working or not...

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, petrkl12 said:

    @jgab how does it look with ER for HC3? I saw something in your github but I don't know if it is working or not...

    I'm going to do some restructuring and most likely move out the autoupdate and Hue code to a separate QD

    Edited by jgab
    Link to comment
    Share on other sites

    @jgab

    In block scenes there is possibility to call toggle for lights -  fibaro.call(24'toggle'). I wanted to use my own function in QA for it but still there is calling function QuickApp:turnOn() or QuickApp:turnOff() based on current value but not my function QuickApp:toggle().

    I need something how to override this function .... Is it possible to do it in lua?

    Link to comment
    Share on other sites

  • Topic Author
  • 3 minutes ago, petrkl12 said:

    @jgab

    In block scenes there is possibility to call toggle for lights -  fibaro.call(24'toggle'). I wanted to use my own function in QA for it but still there is calling function QuickApp:turnOn() or QuickApp:turnOff() based on current value but not my function QuickApp:toggle().

    I need something how to override this function .... Is it possible to do it in lua?

    It probably does something like

    fibaro.call(ID,fibaro.getValue(ID,"value") and "turnOff" or "turnOn")

    so it never calls any toggle function that can be overriden.

     

    Which brings me to another point. Why can't QuickApps implement their own 'get' and 'getValue' instead of fibaro.get/getValue fetching the property directly? Would be nice to trap those calls and "manipulate" the return result...

    Link to comment
    Share on other sites

    2 hours ago, jgab said:

    It probably does something like

    fibaro.call(ID,fibaro.getValue(ID,"value") and "turnOff" or "turnOn")

    so it never calls any toggle function that can be overriden.

     

    but block scene that was changed to lua version - generate fibaro.call(24,’toggle’)

    Link to comment
    Share on other sites

  • Topic Author
  • 3 hours ago, petrkl12 said:

     

    but block scene that was changed to lua version - generate fibaro.call(24,’toggle’)

    Yes, but it doesn't mean that the implementation of fibaro.call actually calls 'toggle'. I believe that the 'toggle' function is something that only lives in the Lua fibaro.call API. The same way as fibaro.call now can take a list of deviceIDs as first argument. The REST API that eventually gets called only takes single deviceIDs, so they just loop over the list in the fibaro.call API.

    This is how I done in fibarapiHC3.lua

    Please login or register to see this code.

     

    I think that instead of requiring all QA's to implement toggle they use getValue and decide to call turnOn/turnOff.

    The correct way would have been to check if the QA did implement 'toggle' and then call it - if not resort to the getValue approach. The latter is the model I used in ER3 to support fibaro:call(ID,"toggle")...

    • Like 1
    Link to comment
    Share on other sites

    • jgab changed the title to SDK for remote and offline HC3 development.

    Join the conversation

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

    Guest
    Reply to this topic...

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