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

  • Topic Author
  • Posted (edited)

    There is one problem with Lua Language Server in vscode and that is that it doesn't understand the class construct.

    Please login or register to see this code.

    This will make LLS complain that Foo is an undeclared global. The issue is that the 'class' function create a global Foo from the string "Foo", but LLS can't see that (and the 'class' function is not standard lua)

     

    The way I silence LLS is to declare

    Please login or register to see this code.

    Two extra lines declaring Foo to be a class and setting Foo to {}. The assignment of {} is for LLS. The class statement on the next line will reassign Foo to a proper class object. But for LLS it's enough to know that Foo is a class represented by a table.

     

    So this way LLS knows that Foo is a class and will make intelligent assumptions in the rest of the code.

     

    Edited by jgab
    Posted (edited)

    I also use LLC. However, it doesn't warn about certain obvious and fairly common errors - probably due to the nature of the Lua language.

    o.e: reference to non existing field in existing structure: tab.field  - tab exists, and field is never initiated, so tab.field is nil. Sometimes, it's very comfortable, and sometimes it leads to well hidden errors. I've tried to find among hundreds of settings of LLC find appropriate one, without success.

    I think its also questionable that every substitution without 'local' is treated as new global variable (just a=0, even in local function). I miss keyword 'global'... 

    And several more.

    At the other hand LLC informs about type mismatch, even if it's ok in the term of pure LUA. (local a='';a=true)

    Edited by Łukasz997
  • Topic Author
  • Posted (edited)

    If you declare your tables using the ---@class directive, you can declare what fields it has. When you then create a table you type it as this class and you will get warning if you use

    or try to add fields that aren't declared.

    Please login or register to see this attachment.

     

    To warn about using fields not yet initialized is tricky to do statically (need to do a complete flow analyzes of the code like a compiler), so I guess it's outside LLCs scope (at the moment)

    Edited by jgab
    • Thanks 1
  • Topic Author
  • Posted
    1 hour ago, Łukasz997 said:

    I also use LLC. However, it doesn't warn about certain obvious and fairly common errors - probably due to the nature of the Lua language.

    o.e: reference to non existing field in existing structure: tab.field  - tab exists, and field is never initiated, so tab.field is nil. Sometimes, it's very comfortable, and sometimes it leads to well hidden errors. I've tried to find among hundreds of settings of LLC find appropriate one, without success.

    I think its also questionable that every substitution without 'local' is treated as new global variable (just a=0, even in local function). I miss keyword 'global'... 

    And several more.

    At the other hand LLC informs about type mismatch, even if it's ok in the term of pure LUA. (local a='';a=true)

     

    Yes, the type mismatch can be annoying, but it's usually because one is lazy and wants to reuse a variable for something else. I try to introduce a new variable these days - 

    make the code easier to understand.

    Ex.

    Please login or register to see this code.

    vs.

    Please login or register to see this code.

    The code produced is equally efficient in speed and size.

     

    One can also declare custom types that are unions of existing types if needed...

    Posted

    Thanks for all precious advices. Going back to emu2,  I have (sometimes, quite rare) the following error:

    Please login or register to see this code.

    I can't reproduce it. It just simply happens. Nothing urgent for me...

  • Topic Author
  • Posted

    Yes, so there is refreshState loop that fetches the event from the HC3. Normally it succeeds and return events and status 200.

    Sometimes the request times out after ~30s if there are no requests. In that case the loop will retry.

    For all other errors the loop exits as I don't want to shoot a lot of requests to a HC3 that has troubles...

    So, ex. if I get an authorization failed I block the requests immediately. The HC3 will otherwise block any client that makes more than 3-5 failed

    authentication requests (failed logins). It has happened to me in the past. I misspelled the password and the HC3 locked me out when I run the emulator :-) 

     

    Anyway, in this case the HC3 returns a generic 500 error status.

     

    500 Internal Server Error

    The HTTP 500 Internal Server Error 

    Please login or register to see this link.

     status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request. This error is a generic "catch-all" response to server issues, indicating that the server cannot find a more appropriate 

    Please login or register to see this link.

     to respond with.

    If you're a visitor seeing 500 errors on a web page, these issues require investigation by server owners or administrators. There are many possible causes of 500 errors, including: improper server configuration, out-of-memory (OOM) issues, unhandled exceptions, improper file permissions, or other complex factors. Server administrators may proactively log occurrences of server error responses, like the 500 status code, with details about the initiating requests to improve the stability of a service in the future.

     

    So, I guess that once in a while the HC3 fails returning a refreshStates request for some reason or other...

    Anyway, tomorrow I will release patch that are more forgiving for 500 errors and will allow a handful in a row before exiting.

    That may fix your issues if it is just a temporary 500 occurring once in a while...

     

    • Thanks 1
  • Topic Author
  • Posted

    Hc3Emu Helper - Extension for VSCode

     

    There is an extension for VSCode that helps with developing QAs and running the hc3emu emulator.

    Please login or register to see this attachment.

     

    It adds a couple of features:

     

    1. It installs launch and tasks commands for running the emulator/QA. Normally you provide that with .vscode/launch.json  and .vscode/tasks.json files in your workspace. This extension adds these commands to the general preferences of vscode.

    Ex. You get a "hc3emu: Current File" launch command that starts your QA with the emulator.

     

    2. You get "snippets" for common code structures.

    Specifically for the different device types your QA can have.

    Start typing 

    "com"

    and a window will pop up with the different types. Selecting one inserts a code template for the QA.

    Please login or register to see this attachment.

     

    3. Completion and documentation for fibaro and QuickApp functions

    Please login or register to see this attachment.

     

    4. It declares the global lua variables when coding QAs, so if you have the Lunaguage Server that checks your code, it will not complain about variables like

    QuickApp etc.

    • Like 2
    Posted

    Good morning,

    I'm wondering how exactly should run task->update file works.

    In my system it updates only main file of QuickApp. And even if I change something in files included via directive --%%file=... those changed files are not updated on the HC3. I've checked it twice.

    I think all touched files should be updated as well. 

    My files are connected to github repo - if it make any difference.

  • Topic Author
  • Posted

    Which command?
    1. "QA, update file (part of .project)"

    2. "QA, upload current file as QA to HC3"

     

    The first (1) requires that you have a 

    --%%project=<deviceId on HC3>

    set in your QA. That will create a .project file when you run the QA.

    That .project file is used to map files on disks to files in the QA on the HC3.

    When running  "QA, update file (part of .project)", it uploads file in the current active vscode buffer, to the QA on the HC3. So, only one file is updated.

     

    There is no command that updates the whole QA on the HC3 currently.

     

    • Like 1
  • Topic Author
  • Posted

    I have started coding a "update QA" command. It will probably require that you have set the 

    --%%project=<deviceId on HC3>

    directive, so I know what QA on the HC3 to update.

    Posted

    I mean "QA, update file (part of .project)". I have project properly set in main file. 

    Now, everything is clear. It will be nice when new update QA command will function!

  • Topic Author
  • Posted (edited)

    Pushed v2.0.18

    Please login or register to see this code.

    • updateQA task added

    The tasks is named, "QA, update QA (defined in .project)".

     

    There are now 4 supported tasks

    • "QA, upload current file as QA to HC3"    -- Creates a new QA on the HC3 given the QA definition file in the current buffer.
    • "QA, update single file (part of .project)" -- Updates a single file, part of a .project, on a QA on the HC3
    • "QA, update QA (defined in .project)"       -- Updates the whole QA on the HC3, part of a .project file.
    • "QA, Download and unpack from HC3"    -- Downloads a QA from HC3 and unpacks it to lua files.

    The updateQA is a "powerful" command that syncs files with HC3 QA, UI definition, QuickAppVariables, and misc properties, and interfaces.

    At the moment it syncs all of the above. In the future I may come up with a way to specify that some components should not be synched....

     

    The new tasks is part of the tasks installed by the extension "Hc3Emu Helper", v0.9.0

    To get the new tasks.json (and launch.json) from the extension, just remove the ./vscode/tasks.json 

    and create a new file with the extension .lua. The Helper detects that a .lua file is created and there is no tasks.json

    and then installs it. The Helper will not create a tasks.json and launch.json if they already exists.

     

    Sometimes when the UI is updated on an existing QA on the HC3, the Web editor may not be in sync, so it may be necessary to switch to another QA and back again, or even reload the web page.

     

    Edited by jgab
    • Like 2
    • Thanks 1
    Posted (edited)
    2 hours ago, jgab said:

    Pushed v2.0.18

    You are already at 2.0.20-1    😄

    PS C:\WINDOWS\system32> luarocks install hc3emu2
    Installing

    Please login or register to see this link.

     

    The print screen below is comming when I run: "lua -e "require('hc3emu2')" terminal -nodebug" in terminal

    Please login or register to see this attachment.

    It may be because I am offline so I will do it again when back home.

    Edited by Christb
  • Topic Author
  • Posted (edited)
    1 hour ago, Christb said:

    You are already at 2.0.20-1    😄

    PS C:\WINDOWS\system32> luarocks install hc3emu2
    Installing

    Please login or register to see this link.

     

    The print screen below is comming when I run: "lua -e "require('hc3emu2')" terminal -nodebug" in terminal

    It may be because I am offline so I will do it again when back home.

    Yes, but it shows that you have installed the rock correctly and the system paths are ok.

    (It starts an interactive terminal that's under development)

     

    So, if it then doesn't work in vscode it must be some problem with your launch.json or tasks.json.

     

    If you install the "Hc3Emu Helper" vscode extension (v0.9.0) and remove eventual .vscode/launch.json and .vscode/tasks.json from your workspace,

    and the create a file with the extension .lua, the Helper will add the latest  .vscode/launch.json and .vscode/tasks.json to your workspace.

    It should work with those...

     

    Edited by jgab
    • Like 1
    Posted

    I've done upgrade according to instruction, new config files was created by helper 0.9.0. Definition in .project is present. However executing update QA ends with error:

    Please login or register to see this code.

    Emulator itself is working properly. By no mean I haven't listed in error message path on my desktop/hc3emu2 directory.

  • Topic Author
  • Posted

    Sorry, the updateQA tasks had accidently  a "-develop" appended as last argument (which I use for debugging). 

    Remove it in your tasks.json file.

    I have pushed a new version of Hc3Emu Helper (v0.10.0) that has it fixed (usually takes 5min for Msft to publish it)

    • Thanks 1
    • 2 weeks later...
    Posted
    On 6/7/2025 at 6:31 PM, jgab said:

    f you install the "Hc3Emu Helper" vscode extension (v0.9.0) and remove eventual .vscode/launch.json and .vscode/tasks.json from your workspace,

    and the create a file with the extension .lua, the Helper will add the latest  .vscode/launch.json and .vscode/tasks.json to your workspace.

    It should work with those...

    Dear @jgab,

     I am back home with local access to my HC3 and get a new issue with my QA:

    Process started
    -HC3 is not reachable, please check your HC3 URL and network connection
    -Switching to offline mode
    -Running in offline mode
    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v2.0.22
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: tempUnit is °C
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: infinite character:∞
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: HC3 language: en
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: Manual Heating Override version: 8.0
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: Choosing mode
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: ----- Starting up QA : MyQA - deviceId: 5000 ----- Version:8.0
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: error code f:  501

    I have checked all json or lua files and all information for connecting to my HC3 are correct (these settings were allowing the QA to access HC3 before I leave from home) 

    .

    But if I run again "lua -e "require('hc3emu2')" terminal -nodebug" then I have a message in the TERMINAL that the HC3 is on line...

    PS C:\Users\ASUS\Documents\hc3emu-main> lua -e "require('hc3emu2')" terminal -nodebug
    -Running in online mode
    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v2.0.22
    Hc3Emu Terminal v0.5    (Esc to quit)
    hc3emu>

     

    What I have done wrong to loose this connection?

     

  • Topic Author
  • Posted
    10 hours ago, Christb said:

    Dear @jgab,

     I am back home with local access to my HC3 and get a new issue with my QA:

    Process started
    -HC3 is not reachable, please check your HC3 URL and network connection
    -Switching to offline mode
    -Running in offline mode
    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v2.0.22
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: tempUnit is °C
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: infinite character:∞
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: HC3 language: en
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: Manual Heating Override version: 8.0
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: Choosing mode
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: ----- Starting up QA : MyQA - deviceId: 5000 ----- Version:8.0
    [20.06.2025][19:37:12][DEBUG  ][MYQA5000]: error code f:  501

    I have checked all json or lua files and all information for connecting to my HC3 are correct (these settings were allowing the QA to access HC3 before I leave from home) 

    .

    But if I run again "lua -e "require('hc3emu2')" terminal -nodebug" then I have a message in the TERMINAL that the HC3 is on line...

    PS C:\Users\ASUS\Documents\hc3emu-main> lua -e "require('hc3emu2')" terminal -nodebug
    -Running in online mode
    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v2.0.22
    Hc3Emu Terminal v0.5    (Esc to quit)
    hc3emu>

     

    What I have done wrong to loose this connection?

     

    My guess it's some config file you read when you run from the workspace, like ${workspaceFolder}/.hc3emu.lua or ~/.hc3emu.lua

     

    I have pushed v2.0.25 that when you get a "-HC3 is not reachable, please check your HC3 URL and network connection"

    will print out what the url, user,password it tried to use.

     

     

    Posted (edited)
    7 hours ago, jgab said:

    have pushed v2.0.25 that when you get a "-HC3 is not reachable, please check your HC3 URL and network connection"

    will print out what the url, user,password it tried to use.

    Thank for this version 👍

    Below what I am getting with this new version:

    Process Started

    -HC3 is not reachable, please check your HC3 URL and network connection (invalid host '')

    -HC3 URL: 192.168.1.107/

    -HC3 user: *********@orange.fr

    -HC3 password: #************#

    -Switching to offline mode

    -Running in offline mode

    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v2.0.27

    All the data printed are OK:  IP of the URL, user and password

    I think the config file read is; ~/.hc3emu.lua 

    Is the '/' ending the URL an issue?

     

    Btw, is it possible to use  the HC3 domain name like "hc3-00006081" instead of IP address?

    Edited by Christb
    adding a new question
  • Topic Author
  • Posted

    Try to add http:// in the beginning

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