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


  • 0

Virtual Device error handling


Question

Posted

Hi Fibaro experts,

 

I'm trying to implement error handling for temporary errors in the main loop of a  VD, but got stuck.

 

I've made a setError function, which sets an error icon, and sets the lblStatus text on the VD. Then I want to exit this instance of the main loop of the VD. I've tried fibaro:abort() in the error function, but this seems to permanently stop the VD execution.

 

This is about what I am trying to achieve

 

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

function setError(txt)

  -- Set VD icon

 -- Set lbl txt

 fibaro:sleep(sleep_time)

 <Exit this instance>    <--- This is what I cannot figure out how to do. I want to exit this instance

end

 

-- Main code

 

<do something>

 

if status ==1 then setError()

 

<do something else>

 

if status == 2 then setError()

 

etc...

 

fibaro:sleep(sleep_time) <--- Restart the main loop after sleep_time

-------------------------------------------
So whenever the setError() function is called (also within other functions), the main_loop of the VD should exit.

But the main loop shall be restarted again after one second, just as if execution when through to the bottom.

 

Any ideas?

 

 

3 answers to this question

Recommended Posts

  • 0
Posted (edited)

honestly when you break with abort, you need to restart the VD from other place, which is some extra effort (VD or scene as watchdog for this VD, and API call to VD restart). Lazy way, add goto, and jump to end of your VD code, that should work.

Edited by tinman
  • 0
  • Inquirer
  • Posted

    Oh yes.... The good old (dreaded) goto...

    Thx :-)

    • 0
    Posted

    You could use a pcall/error approach too.

     

    Please login or register to see this code.

     

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

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