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


Recommended Posts

Posted
1 hour ago, jgab said:

You run the tasks from the Command Palette (Shift-Cmd-P on a Mac). There you run Tasks: Run Tasks: ....and there is the QA tasks...

Ok, I do that on MacOS, but then I get the crash.

 

1 hour ago, jgab said:

It logs in the Debug Console (not the Terminal). That's nothing special that I have set up - should work like that when you do a Lua print... Are you using the launch.js and tasks.json files provided with fibemu?

I thought I use these files, let me check again.

 

Thank you for the information, I'm trying to set up a dev container with all the stuff in a few days. 😃

Posted (edited)

ok, the error is fixed. the config.json was in my qa dev folder and not in the fibemu folder 🤐

 

Not updating the QA variables works, but with --%id=-553 in the top of the lua file it creates a new QA.

Also it always touches the GUI and I don't want that, I only want to update the code. Maybe I check your code to see if I can disable it myself.

Edited by Joep
  • Topic Author
  • Posted

    I don't think you can have --%id=-553

    it must be in the command palette prompt. It was not a use case I had.

    Could probably also have some flag for only updating the code but then the question is how to keep the UIs in sync?

    Posted
    7 minutes ago, jgab said:

    Could probably also have some flag for only updating the code but then the question is how to keep the UIs in sync?

    I get you. But I don't want to get the UI in sync, I just want to write code in VScode for completion, color's and a little CoPilot. And if I can push code with a button (task) that saved me copy/paste actions. 

     

    Why? In the past I wrote a complete QA in ZeroBrane, everything worked and on the HC3 it was "just" different and the code failed. So I do big chunks of code in VScode now and finetune with the GUI on the HC3.

     

    But maybe I'm wrong, and have more trust in your emulator, because it is really good. So good that NICE can hire you to work on the HC3 to make a native plugin. :)

  • Topic Author
  • Posted
    6 minutes ago, Joep said:

    I get you. But I don't want to get the UI in sync, I just want to write code in VScode for completion, color's and a little CoPilot. And if I can push code with a button (task) that saved me copy/paste actions. 

     

    Why? In the past I wrote a complete QA in ZeroBrane, everything worked and on the HC3 it was "just" different and the code failed. So I do big chunks of code in VScode now and finetune with the GUI on the HC3.

     

    But maybe I'm wrong, and have more trust in your emulator, because it is really good. So good that NICE can hire you to work on the HC3 to make a native plugin. :)

    I understand you. However, for me, writing really complex QAs like EventRunner requires me to have some decent debugging options and that's why I wrote the emulator...  (Btw, I have played with a dev container too - but a bit unsure how to push updates....)

    What NICE should do is enable remote debugging (ex.by including mob debug). then we could easily write the code in VSCode/Zerobrane and remotely debug in the same IDE. Many Lua based platforms leverage remote debugging because it's common to be in embedded systems.

     

    I have actually written a VSCode plugin that mounts the QAs and their files as a virtual filesystem in the VSCode file browser. With that I can edit remote files but it's cumbersome to make the debugger understand where the file is... with remote debugging enabled most Lua VSCode plugins support it...

     

    There is a lot of cool things NICE could do if they wanted.

    Posted (edited)
    36 minutes ago, jgab said:

    (Btw, I have played with a dev container too - but a bit unsure how to push updates....)

    I think the user has to init a rebuild of the container or update inside. But it’s from the users perspective and no push. If you include a Dockerfile it rebuilds from scratch.

     

    But the end user has to be techy, this is not for the average.

     

    btw: debugging is nice too from vscode. And not stressing the hc3 with tons of QA restarts.

    Edited by Joep
    Typo
    Posted (edited)

    I've build a devcontainer, first with alpine, but the Lua Language Server is not compatible with this container image. So I used Debian bookworm slim and it works. Everything is defined and you can pull in your own code.

     

    If you update the docker image, VScode automatically asks you to rebuild. But I think you only do that every now and then. Users can pull the new code from the repo, and if the devcontainer.json is not changed, it just works.

     

    Now I'm going to check in your Python code to change the credentials that are stored in config.json to the environment variables, so they are not stored in a file.

     

    Edit: I see that you already implemented this, if the values are not set via the config, great work!

     

    Shall I fork your repo to add the container? Maybe as a template, so it doesn't immediatly want to start it (for people that don't have docker installed).

    Edited by Joep
    already implemented
  • Topic Author
  • Posted
    13 hours ago, Joep said:

    I've build a devcontainer, first with alpine, but the Lua Language Server is not compatible with this container image. So I used Debian bookworm slim and it works. Everything is defined and you can pull in your own code.

     

    If you update the docker image, VScode automatically asks you to rebuild. But I think you only do that every now and then. Users can pull the new code from the repo, and if the devcontainer.json is not changed, it just works.

     

    Now I'm going to check in your Python code to change the credentials that are stored in config.json to the environment variables, so they are not stored in a file.

     

    Edit: I see that you already implemented this, if the values are not set via the config, great work!

     

    Shall I fork your repo to add the container? Maybe as a template, so it doesn't immediatly want to start it (for people that don't have docker installed).

    Yes, please do - maybe I start to use it myself...

    Posted (edited)

    Thanks @jgab, the devcontainer is added to the project. To use this install Docker Desktop on your machine and remove the .example extentions from the Dockerfile and devcontainer.json in the .devcontainer folder.

     

    VScode ask you when opening the folder if you want to relaunch in the container, the first time this takes a while because it has to build the container. It builds a Debian container with Python and pulls the fibemu project and configures the requirements fully automatically.

     

    Copy the settings.json from the resources folder to the fibemu root folder if you want to get on speed fast, this has the correct python path and languageserver paths.

     

    If you want to use your own Git project in the container, go to the commandline (ctrl+`) and clone your project in the /workspaces folder. Then add it to the multi-root workspace with the command code -a . (don't forget the 'dot')

     

    Copy the settings.json in your Git project root folder and you are good to go. Everthing runs in the container and the GUi web port is forwarded to your localhost for use in your webbrowser. Don't forget to use the config.json for connection with your HC3.

     

    Note: this is tested on a Mac ;)

    Edited by Joep
    add note
    • Like 1
    Posted

    Did some changes to the tasks and toolt.lua and added keybindings to vscode. With this setup I can press cmd+u to update the file(s) on the HC3 like pressing save on the HC3 editor itself. :)
    (no GUI or vars are manipulated, just code, exactly as I want).

     

    If you are ok with it @jgab I change tools.lua for this behavior and add the task to tasks.json with a keybindings example. Then I'll send you another MR in the next days. 🥸

    • Thanks 1
  • Topic Author
  • Posted (edited)
    On 10/13/2024 at 5:37 PM, Joep said:

    Did some changes to the tasks and toolt.lua and added keybindings to vscode. With this setup I can press cmd+u to update the file(s) on the HC3 like pressing save on the HC3 editor itself. :)
    (no GUI or vars are manipulated, just code, exactly as I want).

     

    If you are ok with it @jgab I change tools.lua for this behavior and add the task to tasks.json with a keybindings example. Then I'll send you another MR in the next days. 🥸

    I assume it's like the update command but without updating qv and ui?

    I also assume that you need to have the main file active to use the logic that finds the relevant files...

     

    It would be nice to have the concept of a current project...

    My thinking was a tool command to create a <QA>.curr file in the top-level directory with the QA files with PC paths and HC3 name and deviceID. Then one could have any QA file active in the editor and have a task/tool that just update that file (with a short cut)

    Edited by jgab
    Posted
    17 minutes ago, jgab said:

    I assume it's like the update command but without updating qv and ui?

    Yes, for now I did a dirty comment action on the code lines that doe the qv and ui and I set up the keybinding.json

     

    Please login or register to see this code.

     

    And I edited tasks.json to copy the QA, update task to QA, update2 that doesn't ask for input and sends the dash as argument. (yes a, dirty first hack)

     

    17 minutes ago, jgab said:

    I also assume that you need to have the main file active to use the logic that finds the relevant files...

    Correct, I have to make the main file active to get it to work.

     

    18 minutes ago, jgab said:

    My thinking was a tool command to create a <QA>.curr file in the top-level directory with the QA files with PC paths and HC3 name and deviceID. Then one could have any QA file active in the editor and have a task/tool that just update that file (with a short cut)

    I was thinking the same, this would be awesome. And set the default file, now the HC3 looses the default file. When I open the QA on the HC3 no file is opened automatically.

     

    Or you speficy this in the main file, because you always need this file.

  • Topic Author
  • Posted

    So, a task named 'createRsrc'. It creates a file curr.json in the projects top level directory. Either one set --%%id=<deviceID> or gives the ID at the task prompt.

    That file would look like (for my Dirigera project)

    Please login or register to see this code.

    Then we can stand in examples/Dirigera/Devices.lua and press update, the tool.lua reads the file and sees what QA the file belongs to and what its name on the HC3 is and then writes it to the HC3... ?

     

    Posted

    That sounds nice. So it updates the current active file only then?

     

    Maybe you can make a variable to set what to update, qv, ui, code, so you define this in the project config?

    So you create a json config for your project.

     

    Posted

    I did a mockup of a json for settings:

    Please login or register to see this code.

     

    I'm going wild now, you can remove the upload task and to auto detection. If the QA doesn't exist, upload a new one. If the id exists update it.

  • Topic Author
  • Posted
    12 minutes ago, Joep said:

    I did a mockup of a json for settings:

    Please login or register to see this code.

     

    I'm going wild now, you can remove the upload task and to auto detection. If the QA doesn't exist, upload a new one. If the id exists update it.

    Yes, something like this - will commit tomorrow.

    Will keep upload task as one will not always have a resource file if one jumps from qa to qa... which I sometimes do.

    • Like 1
  • Topic Author
  • Posted

    Ok, I pushed some new tasks...

    1. The way it works is that there is an 'QA, update' task that works similar to the past

        Need to have the main file being the active file

        -Q, or just -, don't update the quickAppVariables

        -U don't update the UI

         -UQ ignore both

    2. There is a task 'QA, create project'

         Need to have main file being the active file.

         Creates a QA.proj file in the top-level directory for the main file and associated files         and the HC3 deviceId

    3. There is a task "QA, update file"

         Having a QA file active and being in the QA.proj file where the file is listed, updates the file to the HC3 with the QA.proj deviceId.

     

    Also a keybinding.example file with Cmd-U being update, and Cmd-u being update file.

    Only provides keybinding.example as people may want to have their one keybinding.json

     

     

    Posted (edited)

    Great work, so QA, update file only updates the code? And I can update from every file after I created the QA.proj? Or do I hop to the main.lua first?

     

    One thing I see in you tool.ua, you do this:

    Please login or register to see this code.

     

    But the code after the:

    Please login or register to see this code.

    runs always right? So it always updates the vars and viewLayout, or am I missing something. I only read: if updateQvs then print something.

     

    Update: tested the QA update file (with the project) and it works like a charm! Superb!

    Edited by Joep
    update test
  • Topic Author
  • Posted

    Please login or register to see this code.

    No, if the variables are false the corresponding fields in the properties table becomes nil...

     

    Yes, when proj file is created you can jump between the files and send them to the HC3 one by one... no quickVars or UI updated. For that you need run updateQA with main file active (that logic hasn't changed)

     

    • Thanks 1
    Posted

    I programmed past 2 evenings with this VScode setup and uploading code to my HC3 and it works like a charm. Two things I found out:

     

    1. If I use a multi-root workspace then the lsp / intellisense is not working correctly. Like fibaro.getValue doesn't pop up the inline code example. Also the Quick App functions (crawled from the fibemu files, I think) are not always suggested. If I work from the fibemu folder (say fibemu/dev/main.lua) everything works. I think this is a VScode thing, but I can't find a setting to fix this.

     

    2. If I start debugging (F5) from a secondary file (not main.lua) the emulator starts but the QA does nothing. Very strange. I stays at running main:

     

    Please login or register to see this attachment.

     

    Nothing to worry about, I now symlink my second repository to fibemu/dev, but I wanted to notice this.

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