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 (edited)

If I use any calculated condition in assert - I have an error assertion failed. O.E:
 

Please login or register to see this code.

gives:
 

Please login or register to see this code.

Tested on .80 and .97, the same result. On HC3 - ok.

When I wrote:

Please login or register to see this code.

there's no error.

I'm installing and using versions as they are coming, but to be honest have no idea which one can be presume stable.

One remark about WATCH window: this debugger does not include text with "". Text is brown, instead; when o.e. value false is blue.

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

    So, assert, if the test condition is false will generate an error and show the optional message.

    It seems to be failing on line 100 in your example showing the message "assertion failed!" - is that correct?

    I was a bit thrown off because your example has the text "Do inicjalizacji sterownika brama nie może być uchylona"... 

     

    Anyway, assertion works, it generates an error with the traceback. The prefix "[C]]"may not be so nice and I will fix that.

    So the problem is that you have a test that works on the HC3 (lastCmd == "ajar") and not on in the emulator?
    The question is then how lastCmd is computed, then we can try to understand if there is a difference.

    Are you running offline, or in proxy mode or?

    I do appreciate these error reports from you, and I'm happy if I can help you.

    The QA you are developing, is it something that you can PM me so I could test it? or does it depend too much on external devices? (some of it I can fake).

     

    I would go with the latest now. 1.0.98 - I been using since 1.0.96 for my own QA developments.

    I'm only fixing bugs now so I hope to come out with a 1.1 soon that I would consider "stable"

    Edited by jgab
    • Like 1
    Posted

    The morning is wiser than the evening, we said in Poland - and I know what's happening.

     

    I'm running online with proxy.

    Yes, program ends with assertion in line 100, no my message as needed.

     

    But real line 100 was other that - for simplicity - I wrote in last message (additionally I've made an error with condition). Real is:

    Please login or register to see this code.

    and inform returns nil.

     

    I forgot to return a string in function inform (which write on the QA UI and throw push), having assert error without message.

    The construction is such because I would like to squeeze inform and assert in one line.

     

    I'm sorry for wasting your time!

     

    Only profit is that I noticed: even if the assert condition is TRUE (so assert could continue, no error throwing) the function inform is executed. But if we have pure text as second argument - no print occurs, as expected.

    So when condition == false I have message on the UI + on the debug console and error by assertion.

    When condition == true I still get a message in the UI anyway.

     

  • Topic Author
  • Posted

    Yes, that's the way lua works. 

    assert is just a function, and lua will always evaluate all function  arguments before calling the function.

    So, yes, don't do anything complicated in the second argument of assert, as it will always be computed.

    Then if the test is false, assert will throw the result of the second argument upwards as the error message...

     

    For efficiency I sometimes make the test explicit. Instead of

    Please login or register to see this code.

    that will do the string.format every time, even if the test is true, I do

    Please login or register to see this code.

    This way, the strain is only formatted and thrown with an error if the test fails

     

     

    • Thanks 1
  • Topic Author
  • Posted

    Pushed v1.1.0-1

    Please login or register to see this code.

    • Major re-implementation of the API code. Hopefully better performance and easier to maintain...
    • Better error messages
    • Lots of small bugfixes
    • Improved setup/bootstrap procedure

    So, there have been a large rewrite of the core API handling mechanism in hc3emu, starting from v1.0.81.  It has stabilized now and it runs through all the tests that v1.0.80 did - and more. I have been using this since v1.0.96 myself for my rather complicated QAs and it works well.

     

    The main usage of hc3emu when developing QAs is to enable "proxy mode", meaning that there is a proxy QA for your QA running on the HC3 where you interact with (end define ) the UI, and the proxy relays button presses etc back to the emulated code in hc3emu, so one can interact and debug like everything was running on the HC3.

    There is also an "offline mode", where everything runs in the emulator and there is a limited webUI generated for the QA running so one can interact with it.

    However, running offline there are limitations as not all HC3 APIs are implemented, alarms, climate, energy etc... on the other hand, WebSocket,MQTT, TCPClient etc are all there so it's suitable for developing and debugging more advanced network interactions. Offline mode can also run QuickApp children. 

     

    If you have an "UI intensive" QA, I strongly recommend to run in proxy mode as it will give you the ability to debug the real UI with all it's quirks... ;-)

    Ex. I have a HASS QA that generates ~30 QA children for the different types of devices imported from HASS. I can run it offline, but some of the children like the sonos player don't have a good webUI interface, so that's missing. However running online I have the real QA child UIs and I can debug the interaction with each child.

     

     

    • Like 1
    Posted

    Good evening,

    I have another issue, I hope not my error this time.

    I have my own event manager that handles events from RefreshStateSubscriber().

    I have the situation that in  v1.1.0 the events are called twice. O.e. I hit the button and event handler is called, and it's called with the same event once again. Maybe not all events, but this comes from the button - duplicates. I do not investigate it deeper.
    In HC3 for sure it's working ok. In .80 also OK.

    This occurs only in hc3emu 1.1.0

    What can be the reason???

    Event handler is very simple (shortened):

    Please login or register to see this code.

     

  • Topic Author
  • Posted

    Yes, that's a bug. I'll fix it tomorrow - needs some brain cells to fix...

  • Topic Author
  • Posted (edited)

    Pushed v1.1.1-1

    Please login or register to see this code.

    • Fix for duplicate events introduced in 1.1.0.

    vscode logging merge identical log messages into 1 single line starting with the number of identical log messages. I was blind to this in my test examples before releasing 1.1.0...

    Lesson, don't rely on visual inspection of log outputs... and 1.1.1 is maybe a lucky number :-) 

    Edited by jgab
    • Thanks 1
    Posted
    9 hours ago, jgab said:

    Pushed v1.1.1-1

    I was using v1.0.76-1 since a while with no issue. Seeing that you made few new updates I updated from 1.1.0.76-1 to 80 without any issue with the QA under development but from v1.0.90-1 and all intermediate version and  v1.1.1-1 I have the following error:

    HC3Emu - Tiny QuickApp emulator for the Fibaro Home Center 3, v1.0.92
    ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:119: Failed to open file: hc3emuHelper.fqa (coroutine: copas_initializer, socket: nil)
    stack traceback:
        [C]: in function 'assert'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:119: in function 'hc3emu.config.loadResource'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:12: in upvalue 'installHelper'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:92: in function 'hc3emu.helper.start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\api.lua:175: in method 'start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:199: in function 'hc3emu.emu.setupApi'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:648: in function <...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:644>
        (...tail calls...)

     

    'hc3emuHelper.fqa' file exists in C:\Users\ASUS\scoop\persist\luarocks\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.1-1\rsrcs.

    Is it an issue with a missing path?

  • Topic Author
  • Posted

    Yes, on Windows, that is a bit tricky with the path, the algorithm to find the resource directory is that it should be in a path

    C:\Users\...\scoop\apps\luarocks\

    but I see that you have it in 

    C:\Users\...\scoop\persists\luarocks\

     

    I think they link to the same place.

    Can you see if you have the file in

    \Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu\<version>\rsrcs

    ?

    You should also be able to set the windows environment variable EMU_RSRCS

    to the ...\rsrcs\

    directory.

    Note though that vscode is a bit tricky what environment variables it relays to the running program. Think it should be set in launch.json

  • Topic Author
  • Posted

    To be more specific, 

    If the emulator can't figure out where my hc3emu directory is, and I have it in, ex.

    Please login or register to see this code.

    then I can set the user environment variable EMU_RSRC to C:\Users\jgab\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu

    This way the emulator will look in that directory for the latest hc3emu installation and it's rsrcs directory.

    Please login or register to see this image.

    /monthly_2025_05/image.png.635f1a1eb7d8326af5c4e197cb0ce869.png" />

    This also works on MacOS, but there it's usually not a problem for the emulator to guess the directory...

  • Topic Author
  • Posted

    Pushed v1.1.3-1

    Please login or register to see this code.

    • Bugfixes and code cleanup

     

  • Topic Author
  • Posted (edited)

    Tips and tricks

     

    1. Bypassing the emulator for api calls not implemented

    When running the emulator, all api.* calls goes through the emulator.

    Some calls may not be implemented yet and may thus return a 501 code...

    It is possible to bypass the emulator, and calling the HC3 directly by using

    api.hc3.*

    Ex.

    Please login or register to see this code.

    If panels/sprinklers is not implemented in the emulator, this is the way we can call out and get. the value directly from the HC3.

    We can conditionally use that form if we are running in the emulator, so we later can move the code to the HC3

    Please login or register to see this code.

    If we are running online, most unimplemented calls will try to call directly to the HC3 as a fallback, so the case with sprinklers above is not necessary in that case.

    However, if we are running offline, this can be a way to do certain calls to the HC3 anyway, for debugging purposes.

     

    2. Restricted Lua function.

    A QA has a restricted Lua environment where not all standard Lua functions are available.

    In the emulator some the missing functions are available from fibaro.hc3emu.lua.*

    Ex.

    Please login or register to see this code.

    Please login or register to see this code.

    Obviously they will not work on the HC3, but for debugging purposes in the emulator they can be handy.

     

    3. Access to emulator tools.

    The emulator functions are available via fibaro.hc3emu.*

    The existence of fibaro.hc3emu is a good test if your QA runs in the emulator or on the HC3.

    fibaro.hc3emu also contains a suite of useful  functions and values

    Please login or register to see this code.

     

     

    Edited by jgab
    • Like 1
  • Topic Author
  • Posted (edited)

    Running hc3emu in vscode devcontainer

     

     

    Requirements

    • Install vscode
    • Install Docker desktop
    • Install vscode docker extension

     

    This is probably one of the easiest way to get going.

     

    The devcontainer model creates a virtual container with Linux, install all the tools and connects vscode editor to the container.

    This is a good way to develop without having to install a lot of stuff in your system, Tried on MacOS and WIndows11

    In the video I rebuild the container without cache to show the full process. Normally the container image is cached so the startup is very fast.

    The preferred approach is to have the credentials for the HC3 stored in the config file in your home directory. When running a container, the home directory is inside the container (usually at root/.hc3emu.lua) and the config file will be lost when rebuilding the container.

    Instead, we can add the credentials to the .devcontainer/resources/devcontainer.json as environment variables as shown in the video.

    Please login or register to see this code.

    It's important to set the HC3EMUHOST variable to the laptop IP (the PC running the emulator) to make the webUI work. It's a bit complicated to serve traffic in and out of a container. 

     

    It's also possible to create a config file in the workspace directory (the vscode workspace directory is mounted to the container so we can work with the files like a normal vscode workspace project).

     

     

    Edited by jgab
    • Like 1
    Posted
    On 5/8/2025 at 7:27 PM, jgab said:

     

    I think they link to the same place.

    Can you see if you have the file in

    \Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu\<version>\rsrcs

    ?

    You should also be able to set the windows environment variable EMU_RSRCS

    I have this file 'hc3emuHelper.fqa' in 2 places:

    C:\Users\ASUS\scoop\apps\luarocks\current\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs

    C:\Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs

     

    I have still the error in the DEBUG CONSOLE:

    [12.05.2025][16:01:35][SYSERR]    Failed to load resource .\rsrcs\hc3emuHelper.fqa
    ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:122: Failed to open file: hc3emuHelper.fqa (coroutine: copas_initializer, socket: nil)
    stack traceback:
        [C]: in function 'assert'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:122: in function 'hc3emu.config.loadResource'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:12: in upvalue 'installHelper'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:102: in function 'hc3emu.helper.start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\api.lua:155: in method 'start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:200: in function 'hc3emu.emu.setupApi'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:660: in function <...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:656>
        (...tail calls...)

    the EMU_RSRCS path is: C:\Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu

    Even if I add this one: C:\Users\ASUS\scoop\apps\luarocks\current\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs, error is stille there...

    Posted
    33 minutes ago, jgab said:

    Running hc3emu in vscode devcontainer

    Do you think that if I make devcontainer installation, this will resolve my path issue for versions over 1.1.0.80-1?

    If yes, do I have to desinstall all previous installations?

  • Topic Author
  • Posted
    26 minutes ago, Christb said:

    I have this file 'hc3emuHelper.fqa' in 2 places:

    C:\Users\ASUS\scoop\apps\luarocks\current\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs

    C:\Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs

     

    I have still the error in the DEBUG CONSOLE:

    [12.05.2025][16:01:35][SYSERR]    Failed to load resource .\rsrcs\hc3emuHelper.fqa
    ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:122: Failed to open file: hc3emuHelper.fqa (coroutine: copas_initializer, socket: nil)
    stack traceback:
        [C]: in function 'assert'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\config.lua:122: in function 'hc3emu.config.loadResource'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:12: in upvalue 'installHelper'
        ...s\luarocks\current\rocks\share\lua\5.4\hc3emu\helper.lua:102: in function 'hc3emu.helper.start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\api.lua:155: in method 'start'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:200: in function 'hc3emu.emu.setupApi'
        ...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:660: in function <...apps\luarocks\current\rocks\share\lua\5.4\hc3emu\emu.lua:656>
        (...tail calls...)

    the EMU_RSRCS path is: C:\Users\ASUS\scoop\apps\luarocks\3.11.1\rocks\lib\luarocks\rocks-5.4\hc3emu

    Even if I add this one: C:\Users\ASUS\scoop\apps\luarocks\current\rocks\lib\luarocks\rocks-5.4\hc3emu\1.1.3-1\rsrcs, error is stille there...

    Is 

    _DEVELOP=true

    set at the top of the QA file you try to run?

    If that is set it tries to load the emulator files from the local directory, assuming it's the full repo of hc3emu. 

    It's used for developing and debugging the emulator.

    Your error says

    Please login or register to see this code.

    which says that it's looking in the current directory - and _DEVELOP=true is set. There the file is in <workspace>/rsrcs/hc3emuHelper.fqa

    Many files in my examples/ directory has that flag set as I use them for debugging/testing the emulator

     

    Just comment out that line, and the emulator will fetch the files from the place where luarocks install them.

     

    Posted (edited)
    30 minutes ago, jgab said:

    Is 

    _DEVELOP=true

    set at the top of the QA file you try to run?

    NO, I have learn that few weeks ago...

    This QA file is one I started to develop with your first emulator on ZeroBrane, modified it for using fibemu and now hc3emu.

    Is is perfectly working** using your version 1.0.80-1🙂

    ** except for my few remaining bugs 🫣

    Edited by Christb
  • Topic Author
  • Posted
    36 minutes ago, Christb said:

    NO, I have learn that few weeks ago...

    This QA file is one I started to develop with your first emulator on ZeroBrane, modified it for using fibemu and now hc3emu.

    Is is perfectly working** using your version 1.0.80-1🙂

    ** except for my few remaining bugs 🫣

    can you PM me the file so I can test?

    Posted (edited)
    2 hours ago, jgab said:

    can you PM me the file so I can test?

    Attached

    Note: if you are using a proxi view on your HC3, do not select new view (forcing choice of a select button does not mork then)

    Please login or register to see this attachment.

    Edited by Christb
    adding a note

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