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


Visual Studio Code (vscode) for QuickApp development


jgab

Recommended Posts

 I am now playing with select button UI and features and I found 2 issues:

1) when I declare the following:

--%%name="Select test"
--%%type=com.fibaro.binarySwitch
--%%u={select='modeSelector1',text='modes1',options={{text='Auto',value='auto'},{text='Manual',value='manual'},{text='Eco',value='eco'}},onToggled='changeMode2'}
--%%u={select='modeSelector2',text='modes2',options={{text='Heat',value='Heat'},{text='Cool',value='Cool'}},onToggled='newTemp2'}
--%%u={{button='b1',text='newOptions',onReleased='newOptions'},{button='b2',text='setHeat',onReleased='setHeat'},{button='b3',text='setCool',onReleased='setCool'}}
--%%u={switch='s1',text='switch1',onReleased='sb'}
--%%file=examples/fibaroExtra.lua,fibaroExtra
--%%debug=permissions:false,refresh:false

The web UI shows everything except the "modeSelector2" button

 

2) If I declare in one line with the 2 select buttons to be shwon in the same line as below:

--%%u={{select='modeSelector1',text='modes1',options={{text='Auto',value='auto'},{text='Manual',value='manual'},{text='Eco',value='eco'}},onToggled='changeMode2'},{select='modeSelector2',text='modes2',options={{text='Heat',value='Heat'},{text='Cool',value='Cool',onToggled='newTemp'2}}}}

the web UI is well showing the 2 select buttons on the same line and I can change their "options" tables as needed   but only the "modeSelector1"  activate the declared function QuickApp:changeMode2() and "modeSelector2 gives and error saying that the corresponding function "newTemp2" as not been found. 

Link to comment
Share on other sites

  • Topic Author
  • 1 hour ago, Christb said:

    dear JGAB,

    it seems that the json function: local AutoTemp = json.util.InitArray({}) is not yet accepted; I got error:

    [18.02.2024] [11:21:05] [ERROR ] [QUICKAPP5000]: :onInit() :attempt to index a nil value (field 'util'), C:\Users\ASUS\Documents\fibemu\examples\QA_UIselect.lua:_onInit:124
    --> C:\Users\ASUS\Documents\fibemu\examples\fibaroExtra.lua:onInit:111
    --> @.vscode/emufiles/lua/quickApp.lua:_init:194
    --> C:\Users\ASUS\Documents\fibemu\examples\fibaroExtra.lua:init:117
    --> @.vscode/emufiles/lua/class.lua:QuickApp:41

    No, because fibemu has another json encoder.

    I will (this week) try to upgrade the json encoder to the same version that the HC3 QuickApps uses.

    Link to comment
    Share on other sites

    Thank you for the json.utiI.InitArray.

    About my first post on select UI, I have rewrite the QA completly and the 2 select buttons on one line is now working correctly (I have not any clue of what was the initial error).

    I will do the same with the 2 Select type buttons in 2 rows and let you know if there is still an issue.

    Same for the 2 select buttons on 2 lines, now all OK

    Edited by Christb
    Link to comment
    Share on other sites

    Hi Jan,

     

    I have a case with net.TCPSocket() that is working on the HC3 but not on the with fibemu.

    Use case : Manage a Swiming pool Heat connected Heat Pump with standard string commands and results.
    Here is the response on the HC3...

    Please login or register to see this attachment.

     

    Some investigation that I did:

    • With Putty, when I send a "#023 123456/#" command, I get a return string that give me the global status
      "#0060/0057/0069/0/0/0000/008/001/003/000/250/260/250/340/-79/000/000/000/000/000/000/0057/-400/0063/-400#"
      Then, the TCP connection is immediately closed.

      Please login or register to see this attachment.

    • Using the Exact same code with VSCode / fibemu emulator, the string is sent, but I never received any data... 
      Here is the code:

      Please login or register to see this code.


      End the result

      Please login or register to see this code.

    • It did a Wireshark network trace of the fibemu session, on my computer, the data is sent back to the PC but never read in the TCPSocket implementation.

      Please login or register to see this attachment.



      Please login or register to see this attachment.



      Please login or register to see this attachment.

     

    It is most probably because the connection is closed immediately by the remote host (the PAC). Is it something related to the Pythin Net Socket implementation?

     

    Same result with a quick test taking the QA_tcp_test.lua in the examples.

     

    Any advice is welcome.

     

    Many thanks for your help.
     

    Link to comment
    Share on other sites

  • Topic Author
  • 55 minutes ago, chelson said:

    Hi Jan,

     

    I have a case with net.TCPSocket() that is working on the HC3 but not on the with fibemu.

    Use case : Manage a Swiming pool Heat connected Heat Pump with standard string commands and results.
    Here is the response on the HC3...

    Please login or register to see this attachment.

     

    Some investigation that I did:

    • With Putty, when I send a "#023 123456/#" command, I get a return string that give me the global status
      "#0060/0057/0069/0/0/0000/008/001/003/000/250/260/250/340/-79/000/000/000/000/000/000/0057/-400/0063/-400#"
      Then, the TCP connection is immediately closed.

      Please login or register to see this attachment.

    • Using the Exact same code with VSCode / fibemu emulator, the string is sent, but I never received any data... 
      Here is the code:

      Please login or register to see this code.


      End the result

      Please login or register to see this code.

    • It did a Wireshark network trace of the fibemu session, on my computer, the data is sent back to the PC but never read in the TCPSocket implementation.

      Please login or register to see this attachment.



      Please login or register to see this attachment.



      Please login or register to see this attachment.

     

    It is most probably because the connection is closed immediately by the remote host (the PAC). Is it something related to the Pythin Net Socket implementation?

     

    Same result with a quick test taking the QA_tcp_test.lua in the examples.

     

    Any advice is welcome.

     

    Many thanks for your help.
     

    In fibemu, does it hang forever? or do you get "operation cancelled" or something else?

    Link to comment
    Share on other sites

    Going back to Select type button:

    when the QA starts you have the Select button showing Choose label as below but when you have made one selection it is not possible to reset the button to the Choose display.

    I have not find a way to come back to the Choose display. Is there a method for doing that? I need that when I am changing the options table of the bottom select button following a selection on the top select button

    Please login or register to see this image.

    /monthly_2024_02/Capturedcran2024-02-18141522.png.fac736eb8990706493f79fb5553c17a2.png" />

    Top button selection: "Heat" the bottom select button forced to "Heat": I am able to do so,

    Top button selection: "Cool" the bottom select button forced to "Cool": I am able to do so,

    Top button selection: "Off" the bottom select button forced to blank and no choice: I am able to do so with self:updateView("modeSelector2","options",{})

    Top button selection: "Auto" the bottom select button forced to Choose allowing possible selection between "Heat" or "Cool" (cannot do so, the last selection is always diplayed).

     

     

    Link to comment
    Share on other sites

  • Topic Author
  • 30 minutes ago, Christb said:

    Going back to Select type button:

    when the QA starts you have the Select button showing Choose label as below but when you have made one selection it is not possible to reset the button to the Choose display.

    I have not find a way to come back to the Choose display. Is there a method for doing that? I need that when I am changing the options table of the bottom select button following a selection on the top select button

    Please login or register to see this link.

    Top button selection: "Heat" the bottom select button forced to "Heat": I am able to do so,

    Top button selection: "Cool" the bottom select button forced to "Cool": I am able to do so,

    Top button selection: "Off" the bottom select button forced to blank and no choice: I am able to do so with self:updateView("modeSelector2","options",{})

    Top button selection: "Auto" the bottom select button forced to Choose allowing possible selection between "Heat" or "Cool" (cannot do so, the last selection is always diplayed).

     

     

    Is it possible on the HC3?

    Link to comment
    Share on other sites

    59 minutes ago, jgab said:

    In fibemu, does it hang forever? or do you get "operation cancelled" or something else?

    It hangs forever, no return code.
    If I run it in a loop, any other try to connect and send a command returns 'PAC connection error:[WinError 87] Paramètre incorrect'
    Most probably because PY thinks the previous connection is still active.

    Link to comment
    Share on other sites

    JGAB wrote: Is it possible on the HC3?

    Tested and I found the following:

     

    - Cannot get 2 Select buttons on one line (not surprised)

    - Changing the options table of a select button does not work in the QA edit view but it is working when you press the button "Change S2 option" in the working QA!!!
       It seems that the QA structure is not updated as well but the QA view is still showing the new choices.

    - The self:updateView("modeSelector2","options",{}) does not give any error message but is ignored, the modeSelector2 stays on previous selection.

    - After the above updateView is used, when you select the first choice of "modeSelector1" , the modeSelector2 is displaying "Choose" but not for the other S1 choices.

    - Even if you make a change in the main QA code, save  and refresh the dashboard, the QA is keeping for both buttons their last selection.

     

    Grrr....🥶

    Like in TQAE, you editor is more powerfull than Fibaro

    I will try to find where the last position is stored but yet I have not been able to find anything in the device structure...

    Attached the HC3 502_Binary_Switch_BC.fqa

    Please login or register to see this attachment.

    Edited by Christb
    Link to comment
    Share on other sites

    JGAB wrote: Is it possible on the HC3?

    Adding the line of code below as the last one of in the elseif event.values[1] == "Auto" then selecting Auto on "modeSelector1"
    makes that the modeSelector2 button is showing "Choose" instead of the previous "modeSelector2" choice:

    self:updateView("modeSelector2", "selectedItem","")

    So it is possible in HC3 but not (yet?) in fibemu.

    Attached new fqa file

     

    Btw, I have make some changes in the code of the Switch1/turnOn/turnOff buttons to synchronise them.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • On 2/18/2024 at 12:33 PM, jgab said:

    No, because fibemu has another json encoder.

    I will (this week) try to upgrade the json encoder to the same version that the HC3 QuickApps uses.

    OK, I pushed a version with a new json.encoder that is the same version as in HC3 QuickApps - so we can use json.utiI.InitArray.

    The json.decoder is still the old one.

    The reason is that the HC3 QUickApp json library uses lpeg (for decoding) and I don't want to drag that into fibemu as it is not Lua native.

    • Thanks 1
    Link to comment
    Share on other sites

  • Topic Author
  • On 2/18/2024 at 3:26 PM, chelson said:

    It hangs forever, no return code.
    If I run it in a loop, any other try to connect and send a command returns 'PAC connection error:[WinError 87] Paramètre incorrect'
    Most probably because PY thinks the previous connection is still active.

    Have you tried to set a short timeout, like 2-3s ?

    Link to comment
    Share on other sites

    • 3 weeks later...

    @jgab, a while back you provided a QA called ChildsPlay. It's a simple QA which creates a QwikAppChild class to allow child devices to have their own UI. I am trying to take that and use it by building up the simple child device into something I will use. When I run it on FibEmu it works fine (of course). But when I port it to the Z-Box hub (which is an HC3 or HCL device) the UIHandler can't find the methods in the class. I used swagger to examine the child device structure and the UI callbacks have been mangled by adding "ui" to the front and the event type to the end (but, of course, the event type onReleased is changed to OnReleased to make it camel case). Thus, the table of UI Callbacks stored in the child's QA Variables is one thing:

    Please login or register to see this image.

    /monthly_2024_03/image.png.b35023f1c0558adb97b0260ff6860f0c.png" />

     

    but the callback found in the uiCallbacks sub-table becomes:

    image.png.c5711a804c9ad586f13880ad7c44db4b.png

     

    So my question is:

     

    Am I wrong for overriding the QuickApp:UIHandler() method to redirect the UI Event? Or is there an update to this code which modifies the names being searched for to be more compliant with the way the HC3 handles this? FibEmu doesn't have the mangled names and works as expected. I am running version 5.150 on my hub.

     

    On a different note, is it not possible to add a property entry on the child QA? My device not only must turn on and off, but there is a speed setting (a value from 1 to 6), a direction of rotation setting (forward or reverse), and a sleep timer setting (a value, in minutes, for one 24 hour period), for my ceiling fan device. In FibEmu I can add these properties to the properties table but they are discarded on the hub.

     

    Thanks @jgab.

     

    Peter

    Link to comment
    Share on other sites

    W dniu 27.06.2023 o 10:46, jgab napisał:

    Please login or register to see this code.

    Note the --%%remote directive

    It instructs the emulator that it's ok to call device 788,789 o the HC3. As a default, the emulator treats all resources as local (we can read from HC3 but then treat them as local copies) and we enable resources we want to interact with on the HC3 as 'remote'. This goes for other resources also like 'globalVariables'.

     

    Hello Jan,

    I have the follwing problem with VSC for QA:

    fibaro.call(device, "turnOn")

    does not in fact turn on the device on HC3. Device type is: dimmer, switch, power outlet - I've tested with all devices I have who can be "turnedOn". The --%%remote directive was set to device number  - the command has no effect on real device. Also, no error.

    What is worth to be mentioned: fibaro.getValue(...) on the same devices works, and show real values reflecting actual state of the device on HC3.

    Also, access to global variables on the HC3 (with --%remote...) is working (only after list it by names, '*' does not work).

     

    I'm using it on OS X.

    I'm out of idea. Could you please tell me what is the reason for this?

    Link to comment
    Share on other sites

  • Topic Author
  • 10 hours ago, Łukasz997 said:

     

    Hello Jan,

    I have the follwing problem with VSC for QA:

    fibaro.call(device, "turnOn")

    does not in fact turn on the device on HC3. Device type is: dimmer, switch, power outlet - I've tested with all devices I have who can be "turnedOn". The --%%remote directive was set to device number  - the command has no effect on real device. Also, no error.

    What is worth to be mentioned: fibaro.getValue(...) on the same devices works, and show real values reflecting actual state of the device on HC3.

    Also, access to global variables on the HC3 (with --%remote...) is working (only after list it by names, '*' does not work).

     

    I'm using it on OS X.

    I'm out of idea. Could you please tell me what is the reason for this?

    It turned out to be a bug introduced in one of the last patches. 

    (I started to use another json encoder that did not code empty tables lists)

    I have reverted the patch so  fibaro.call should work now and I will re-think how to introduce the new json.encoder. 

    • Thanks 1
    Link to comment
    Share on other sites

    4 minuty temu, jgab napisał:

    It turned out to be a bug introduced in one of the last patches. 

    (I started to use another json encoder that did not code empty tables lists)

    I have reverted the patch so  fibaro.call should work now and I will re-think how to introduce the new json.encoder. 

    Thank you very much - it's working right now as expected!

    Link to comment
    Share on other sites

    Dear JGAB,

    I have found that the goup call action was not working in fibemu (doest not accept a table as group of Ids) so to make the same, I used the following code

    Please login or register to see this image.

    /monthly_2024_03/image.png.3e5f8ceee77afa9b7efc2412871379c4.png" />

    the print lines were printed ok but the turnOff did nothing to any device.

    Thinking it was the same issue as Luskasz997, I made a git pull and after that I have this error about python (not recognised as a valid command)!

    I know it is not comming from the git pull action because replacing the new net.lua file by the previous one does not change anything.

    It is like if Python311 was no more installed. I checked the path and it is present in my environment path...the Python311.exe is also there.

    What I can do to fix that problem?

     

    I fact I had to again desinstall all application as I explained in a previous post.

    If some one in the forum is a specialist of Microsoft Windows / Visual Studio code can help me, I will be happy to know what I can do for protecting my vscode fibemu settings...

    Edited by Christb
    Link to comment
    Share on other sites

    Now that I have back vscode fibemu, I tested again the loop to turn off all lights of a floor with the loop (for i,light in ipairs(lamp[indx]) do fibaro.call(light,"turnOff" end) and the group call (fibaro.call(lamp[indx],"turnOff") and both are accepted but not working with a strange warning message that I do not understand:


    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id: 187 true
    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id; 187  will be Off
    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id: 187 true
    [10.03.2024] [15:27:57] [SYSWRN] [onAction]: No action, QA declared local, ID:187

    For the group action, I have the same message with at the beguining of the line, a number in a grey circle corresponding to the number of devices with issue in the lamp[indx] file.

    local lamp={}

    lamp[2]={502,502,502,502,502,410,410,388,389,187,463,464,311,54,50,80} -- Ground floor 11 devices 16 lamps: 5x502 are a QA binary switch for test

    The SVGTest_3.lua is runing with the configuration "Fibenv QA file (remote, HC3 access) (fibemu)"

     

    With more testing, I have found that print("Id:",light,fibaro.getValue(light,"value")) print Id number and "true" or "false" from HC3 device state but 

    fibaro.call(light,"turnOff") and fibaro.call({187,502},"turnOff") are giving the warning message and does not switch the lights and that

    fibaro.call(502,"turnOff") and fibaro.call(187,"turnOff") are both working.

    I just decided to introduce the quickApp function "lightsOff" in my HC3 QA and it is working perfectly for all floors without any warning or error message:

    function QuickApp:lightsOff()
      local lum = {}
        for i,k in ipairs(lamp[indx]) do
            lum[i]=tonumber(k)
            print(
    "Id",k," status:",fibaro.getValue(lum[i],"value"))
        end
        print(json.encode(lum)) -- give for indx==1:  [502,502,502,502,502,410,410,388,389,187,463,464,311,54,50,80]
        fibaro.call(lum,"turnOff") -- > turns off all devices of lum table
        print("---- all lights off ----")
    end

     

    The same function in fibemu semms to work once (all of the floor lights are off), just after a new run with the QA with at the end the warning message and any other launch did not switch off lights.

    Edited by Christb
    Test feature in HC3
    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Christb said:

    Now that I have back vscode fibemu, I tested again the loop to turn off all lights of a floor with the loop (for i,light in ipairs(lamp[indx]) do fibaro.call(light,"turnOff" end) and the group call (fibaro.call(lamp[indx],"turnOff") and both are accepted but not working with a strange warning message that I do not understand:


    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id: 187 true
    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id; 187  will be Off
    [10.03.2024] [15:27:57] [DEBUG ] [QUICKAPP5000]: Id: 187 true
    [10.03.2024] [15:27:57] [SYSWRN] [onAction]: No action, QA declared local, ID:187

    For the group action, I have the same message with at the beguining of the line, a number in a grey circle corresponding to the number of devices with issue in the lamp[indx] file.

    local lamp={}

    lamp[2]={502,502,502,502,502,410,410,388,389,187,463,464,311,54,50,80} -- Ground floor 11 devices 16 lamps: 5x502 are a QA binary switch for test

    The SVGTest_3.lua is runing with the configuration "Fibenv QA file (remote, HC3 access) (fibemu)"

     

    With more testing, I have found that print("Id:",light,fibaro.getValue(light,"value")) print Id number and "true" or "false" from HC3 device state but 

    fibaro.call(light,"turnOff") and fibaro.call({187,502},"turnOff") are giving the warning message and does not switch the lights and that

    fibaro.call(502,"turnOff") and fibaro.call(187,"turnOff") are both working.

    callGroupAction is not implemented.

    If you want to run it against the HC3 do your own implementation

    Please login or register to see this code.

    The log messages I don't understand. I can't find them in my code.

    You say that fibaro.call(light,"turnOff")  doesn't work.

    but fibaro.call(502,"turnOff") do work? What is 'light'

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, jgab said:

    callGroupAction is not implemented.

    If you want to run it against the HC3 do your own implementation

    Please login or register to see this code.

    The log messages I don't understand. I can't find them in my code.

    You say that fibaro.call(light,"turnOff")  doesn't work.

    but fibaro.call(502,"turnOff") do work? What is 'light'

    In vscode, do Edit->Search in Files

    and look for "will be" and see if it is in some log statement...

    Link to comment
    Share on other sites

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