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

  • Topic Author
  • Ah, I didn't update requirements.txt after I started to use websocket.

    I have updated requirements.txt now and a

    Please login or register to see this code.

    should install the correct libs

     

    I just tested it on Windows 11 (Mac is my environment) and it worked. 

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • btw, I have seen that sometimes when the emulator crash (not your Lua code), the socket used by the API server get stuck and it will complain that port 5004 is already in use. This has happened both on MacOS and Windows 11.

    That will require a manual kill of the processes keeping the socket open. Will see if I can improve on this (one way is of course to make sure that the emulator don't crash, which do happen less and less... :-) )

    Edited by jgab
    Link to comment
    Share on other sites

    W dniu 12.07.2023 o 07:25, jgab napisał:

    Lots of bug fixes and improvements the last days.

    I have added 4 tasks to the vscode project.

    • "QA, download fqa" downloads an QA from the HC3 and saves it as a .fqa file. The task will prompt for deviceID and path where to store. The path/dir needs to exist
    • "QA, download and unpack" downloads an QA from the HC3 and saves all QA files as .lua files. It also adds fibemu headers in the main file so it can be opened and run with the emulator . The task will prompt for deviceId and path where to store. The path/dir needs to exist
    • "QA, upload" will upload the QA to the HC3. It will prompt for QA file. If '.' will upload the current opened file. This will create a new QA, with a new deviceId on the HC3.
    • "QA, update" will try to update QA files, viewLayout, uiCallbacks, and quickAppVariables of an existing QA on the HC3. The file must have set the fibemu header --%%id=<ID> so it knows what QA to update. This is convenient when developing and avoiding new IDs being "consumed"....

    Please login or register to see this attachment.

     

    I had not much luck with tasks, this was download and upack

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    @jgab, I'm struggling a bit running ER4 after updating of fibaroExtra to 0.960

     

    Following code:

     

    rule("post(#foo)")

    rule("#foo => log('Yep')")

     

    Produces:

     

    [17.07.2023] [10:32:57] [TRACE ] [QUICKAPP5000]: Posting {"type":"foo"} at Mon Jul 17 10:32:57 2023

    [error] table: 0x1087e8e80

     

    This comes from:

     

    ----------------- Module utilities ----------------------------

    Module.utilities = { name="ER Utilities", version="0.6"}

    function Module.utilities.init(QA)

    if Module.utilities.inited then return Module.utilities.inited end

    Module.utilities.inited = true

     

    QA.color = { banner = 'black', rule='green', info='purple' }

    local self = {}

    local equal=table.equal

     

    function self.findEqual(tab,obj)

    for _,o in ipairs(tab) do if equal(o,obj) then return true end end

    end

     

    function isError(e) return type(e)=='table' and e.ERR end

    function throwError(args) args.ERR=true; error(args,args.level) end

     

    Before upgrade it was rather on the working side.

     

    Link to comment
    Share on other sites

    @jgab

     

    I was looking at the Swagger page in the emulator. There are two things I noticed on the first screen. 

     

    RefresStates should be RefreshStates.

     

    And there are two debugMessages entries. debugMessages and DebugMessages. They look identical.

     

    I tried to see where they were but it was too much this early in the morning. It's good to have the emulator running on my end. Like the environment. Seems very responsive.

    Link to comment
    Share on other sites

  • Topic Author
  • Thanks, will have a look (very nice to have someone using my code :-) )

    8 hours ago, PeterV959 said:

    I installed Python, the Python requirements, and VS Code along with the Tom Blind debugger extensions. Then I git cloned the fibemu repository and I am trying to run any of the examples in the examples folder. I get the following errors on the Debug Console:

     

     

    Please login or register to see this attachment.

     

    So it looks like it can't find 'websocket'. What have I missed?

     

    Looks like an exciting environment. Can't wait to try it out.

     

    Thanks

     

    Update: I saw @jgab had updated something three hours ago so I tried to "git fetch" fibemu. After that I ran the pip install for requirements. Still no effect. But when I poked around I saw a requirements.txt file in the ./.vscode/fibemu folder. I tried to install that and was rewarded with the addition of websockets. I am now up and running, although I need to turn off colors for the debug console output. I am using a dark high contrast theme and I am getting black letters on a black background. Should be an easy fix, right? I will poke around and figure out how to correct that for my environment (and maybe learn something in the process).

     

    Thanks @jgab

    Yes, in your config.json add

       "dark": true

    Link to comment
    Share on other sites

  • Topic Author
  • 13 hours ago, PeterV959 said:

    Update: I saw @jgab had updated something three hours ago so I tried to "git fetch" fibemu. After that I ran the pip install for requirements. Still no effect. But when I poked around I saw a requirements.txt file in the ./.vscode/fibemu folder. I tried to install that and was rewarded with the addition of websockets. 

    It was a mistake. requirements.txt should only be on the top-level. (to reduce the likelihood of future confusions)

    Link to comment
    Share on other sites

    @jgab I did a recent git fetch in my fibemu folder and still see the following so I'm guessing you haven't pushed your changes to github?

     

    I still haven't seen any definition for registerUICallback() and continue to see that error.

     

    The requirements.txt file in my fibemu "root" has not been updated.

    Link to comment
    Share on other sites

  • Topic Author
  • 9 minutes ago, PeterV959 said:

    @jgab I did a recent git fetch in my fibemu folder and still see the following so I'm guessing you haven't pushed your changes to github?

     

    I still haven't seen any definition for registerUICallback() and continue to see that error.

     

    The requirements.txt file in my fibemu "root" has not been updated.

    If you do a git pull?

    1 minute ago, jgab said:

    If you do a git pull?

    it's there in the GitHub repo

    Please login or register to see this link.

     

    Link to comment
    Share on other sites

     

     

    14 hours ago, jgab said:

    If you do a git pull?

    I started with a git clone of your github link. It came down just fine. I then thought I could use git fetch while standing in the fibemu folder. I have done that before with fibemu and TQAE. It worked before. I'm just not especially familiar with the ins & outs of github. I'm only offering my experience in case it's something on your end. I can make things work, regardless. You may not think that I can't figure stuff out but the Fibaro world is new and Lua is new and I feel like I'm spinning my wheels at times.

     

    Thank you for your patience.

     

    Peter

    Link to comment
    Share on other sites

    5 hours ago, PeterV959 said:

    I then thought I could use git fetch while standing in the fibemu folder.

     

    It doesn't matter what folder you are in. Do a git pull, so your local files are replaced with the remote changed. If you do a git fetch the the local files are not altered, only the tracking branches are updated (as I know). It's a commando to look at the remote changes.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 59 minutes ago, Joep said:

     

    It doesn't matter what folder you are in. Do a git pull, so your local files are replaced with the remote changed. If you do a git fetch the the local files are not altered, only the tracking branches are updated (as I know). It's a commando to look at the remote changes.

    Yes, I believe I incorrectly stated in the TQAE thread that one should use fetch...

     

    ------------

    More colors in the debug console.

    You can run this small program to print out the (256) colors available

    Please login or register to see this code.

    only works in fibemu of course, where I have stuffed the colormap in the os.* module.

    The default mapping is
     

    Please login or register to see this code.

    where DARKTEXT is used if the config parameter "dark":true is set.

     

    In your own config.json you can setup your own mapping

    Ex.
     

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • When defining quickAppVariables with

    Please login or register to see this code.

    The value, right hand of the ':', is an evaluated lua expressions. The environment where the expression is evaluated is limited so you can't call functions etc. It's for setting up constants.

    However, there is one variable available, 'config', that is the config file read in.

    This means that if we have the config.json

    Please login or register to see this code.

    We can define a quickAppVariable in our QA as

    Please login or register to see this code.

    and then access it in our code as

    Please login or register to see this code.

    The advantage is of course that we don't have to put the secret in plain text in the QA code, and by accident publish it in the forum or commit it to a repository...

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • Some documentation is available here 

    Please login or register to see this link.

      (work in progress)

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • 8 hours ago, PeterV959 said:

    I started with a git clone of your github link. It came down just fine. I then thought I could use git fetch while standing in the fibemu folder. I have done that before with fibemu and TQAE. It worked before. I'm just not especially familiar with the ins & outs of github. I'm only offering my experience in case it's something on your end. I can make things work, regardless. You may not think that I can't figure stuff out but the Fibaro world is new and Lua is new and I feel like I'm spinning my wheels at times.

     

    Thank you for your patience.

     

    Peter

    We are here to learn, I learn everyday and I also learn from other people's difficulties and learnings.

    When I do these framework, TQAE, fibemu, fibaroExtra, EventRunner etc, it's mainly for my own usage - no one is paying me. However, publishing them here and getting feedback on bugs or unclarities is incredible helpful to improve the quality of the code. My philosophy is that if people are too "stupid" to use my code, eventually I will be too "stupid" to understand how to use my code also :-) 

    At the end this of course benefits me - altruism being the only true driver - but I like to think about it as win-win.

    Link to comment
    Share on other sites

  • Topic Author
  • Made a little video how I install it on Windows 11 - being a native Apple/Mac person, if I can install it on Windows 11 and make it work, anyone can :-) 

     

     

    10 minutes of pure suspense :-) 

    Edited by jgab
    • Like 1
    Link to comment
    Share on other sites

    Good morning. All is right with the world. A bad storm blew through here disrupting the city power grid Tuesday evening. No power here until about 6pm last night. 

     

    I have Child's Play working on both fibemu and my hub. Thank you @jgab for your guidance. I have a question, however. I can't seem to delete the child device. When I hit the trashcan  icon, it goes away from the list. But when I reload the page it's still there. I am trying to force a new child to be created to verify a change. I say it isn't deleted because it has the same device id. I would expect it to be given a new device ID as that's the default (only?) behavior on the hub. There isn't an obvious way to delete a child in the emulator so I'm stuck using the hub for that (hint hint). Sometimes I get the console output on the hub indicating that the removeChild action has been called but I'm not seeing that consistently. What am I not understanding about this action?

     

    BTW, remember that when it comes to making something idiot proof, you can never outsmart or outthink an idiot. Being an idiot myself 😁 I can assure you of that. I believe that is one of Murphy's laws (or it should be).

     

    Thank you again.

     

    Peter

    Edited by PeterV959
    typos
    Link to comment
    Share on other sites

  • Topic Author
  • On 7/21/2023 at 3:17 PM, PeterV959 said:

    Good morning. All is right with the world. A bad storm blew through here disrupting the city power grid Tuesday evening. No power here until about 6pm last night. 

     

    I have Child's Play working on both fibemu and my hub. Thank you @jgab for your guidance. I have a question, however. I can't seem to delete the child device. When I hit the trashcan  icon, it goes away from the list. But when I reload the page it's still there. I am trying to force a new child to be created to verify a change. I say it isn't deleted because it has the same device id. I would expect it to be given a new device ID as that's the default (only?) behavior on the hub. There isn't an obvious way to delete a child in the emulator so I'm stuck using the hub for that (hint hint). Sometimes I get the console output on the hub indicating that the removeChild action has been called but I'm not seeing that consistently. What am I not understanding about this action?

    Yes, I have seen that behaviour too. It must be something with the hub as the id is the same, so the child was never deleted.

    The lua command to delete a child is 

    api.delete("/plugins/removeChildDevice/" .. id)

    but that is of course not a solution, as users can click on that trash icon.

    On 7/21/2023 at 3:17 PM, PeterV959 said:

    BTW, remember that when it comes to making something idiot proof, you can never outsmart or outthink an idiot. Being an idiot myself 😁 I can assure you of that. I believe that is one of Murphy's laws (or it should be).

     

    I agree. If you try to outthink an idiot you are an idiot :-)

     

    One of the trickiest things when designing a code framework to be used by others, is to make sure that there are good error messages. The 2 problems are errors you never anticipated that creates strange errors for the users, secondly, errors you know will happen but it's really tricky to provide good information to the user so he can understand the context.

     

    I spent the last days implementing better error messages in fibemu, thinking it would benefit users of the emulator. ...and lo and behold, in another QA project I'm developing (using fibemu) I just got a really good error message so that I directly understood where my bug was :-)

     

    Link to comment
    Share on other sites

  • Topic Author
  • Bumped version to fibemu v0.33

    Lots' of bug fixes and better error messages.

    I would say that fibemu is less buggy than TQAE now, but it may lack some features...

     

    I'm starting to really appreciate the copilot extension for vscode - we don't always agree, but it saves me some time...

    I also use the vscode extension "Lua Language Server" by sumneko. Nice lua completion and coding warnings.

     

    The provided vscode tasks "upload" and "update" also saves time fixing the last QA bugs when testing on the real HC3...

    Link to comment
    Share on other sites

  • Topic Author
  • On 7/17/2023 at 10:10 AM, michalt said:

     

    I had not much luck with tasks, this was download and upack

     

    Please login or register to see this attachment.

    the directory ./dev in your workspace must exists. Create it first.

    Updated so that the error message will suggest this...

    Edited by jgab
    Link to comment
    Share on other sites

    • jgab featured this topic

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