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

fibaro.call can't sent a class object to another QuickDevice


NLWaard

Question

Locally I can place the current class (self) in a variable and call an Object in this class.

 

This code is working (localy):

Please login or register to see this code.

Please login or register to see this code.

[15.09.2020] [13:22:42] [DEBUG] [QUICKAPP105]: Can I print this : Yes

 

If I send this variable to another class using fibaro.call(id, 'action', variable) , the call disappears into the darkness.

Calling the Object in the other class(QuickApp) results in calling the nil value?

!!! This next code is (because of the class=self) not working:

Please login or register to see this code.

Please login or register to see this code.

This is a pity because I would like to indicate in the called class where the call was coming from.
Now I solve this by sending a table with sender = {id=self.id, name=self.name, value=newValue}.

 

Do I do something wrong? or has Fibaro disabled the oop function for sending object classes?

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
1 hour ago, NLWaard said:

Locally I can place the current class (self) in a variable and call an Object in this class.

 

This code is working (localy):

Please login or register to see this code.

Please login or register to see this code.

[15.09.2020] [13:22:42] [DEBUG] [QUICKAPP105]: Can I print this : Yes

 

If I send this variable to another class using fibaro.call(id, 'action', variable) , the call disappears into the darkness.

Calling the Object in the other class(QuickApp) results in calling the nil value?

!!! This next code is (because of the class=self) not working:

Please login or register to see this code.

Please login or register to see this code.

This is a pity because I would like to indicate in the called class where the call was coming from.
Now I solve this by sending a table with sender = {id=self.id, name=self.name, value=newValue}.

 

Do I do something wrong? or has Fibaro disabled the oop function for sending object classes?

 

 

No you can't. Different QAs run in different processes. It's like trying to send object between servers. In theory you can serialise objects but in this case it doesn't make much sense as the QA object also keeps the current state of the running QA. (self variables, lua variables etc).

What you do is that you send the id (self.id) as an identifier to other QAs. (methods = all functions defined on the class or 'self')

You can "remotely" call methods of other QAs with fibaro.call(<id of QA>,<method name>,...args)

Ex. fibaro.call(105,"localPrintValue",self.id)

...and QA 105 can see who called and ev. return the favour...

Edited by jgab
  • Thanks 2
Link to comment
Share on other sites

  • 0

1st of. 

fibaro.call(qaID,"poem", "if", "you", "wanna", "call", "and", "funny", "call", "with", "self", "and", "pass", "parameters")

 

Please login or register to see this attachment.

 

and finallly 

updateProperty

is method of QA you can't call it via RPC.

 

local poem = {"if""you""wanna""call""and""funny""call""with""self""and""pass""parameters"}
fibaro.call(2004"updateProperty""userDescription", json.encode(poem))

 

Please login or register to see this attachment.

 

you are caling method of QA instead of QuickAppBase

 

 

 

  • Thanks 1
Link to comment
Share on other sites

  • 0
  • Inquirer
  • 5 hours ago, jgab said:

     

    No you can't. Different QAs run in different processes. It's like trying to send object between servers. In theory you can serialise objects but in this case it doesn't make much sense as the QA object also keeps the current state of the running QA. (self variables, lua variables etc).

    What you do is that you send the id (self.id) as an identifier to other QAs. (methods = all functions defined on the class or 'self')

    You can "remotely" call methods of other QAs with fibaro.call(<id of QA>,<method name>,...args)

    Ex. fibaro.call(105,"localPrintValue",self.id)

    ...and QA 105 can see who called and ev. return the favour...

    Okay, jcab.
    Thanks for your super quick response again. I appreciate it.
    Unfortunately. But I will now put the same  function code in every QA,

    what I actually wanted was, to put this code in the EventRunner. And call it back from the called QuickApp.

    So I know the Call worked.


    Double unfortunately, because there is also no easy method to set up a basic library with common functions.
    Yes I know, you have written 'Shared functions calls between QuickApps'. And maybe I should take a closer look at that.


    B.T.W. it is wonderful what you have set up.

    But because everything is now in one big topic, it is hard to go through.

    For example, I don't know what your latest version of EventRunner is now.

    I think I will install it now instead of the timed trigger I am using now.

     

    Edited by NLWaard
    taken ER4 version from jgab signature..
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 20 minutes ago, 10der said:

     

    and finallly 

    updateProperty

    is method of QA you can't call it via RPC.

     

    local poem = {"if""you""wanna""call""and""funny""call""with""self""and""pass""parameters"}
    fibaro.call(2004"updateProperty""userDescription", json.encode(poem))

     

    Please login or register to see this attachment.

     

    you are caling method of QA instead of QuickAppBase

     

    Hahaha, Il like your poem, 10der many thanks.
    I know I can't use the updateProperty method so I created updateMyProperty. (I could have been a bit clearer with that).

     

    I think when I say, given your programming background.

    You understand that in an oop, classes are used for inheritance or embedded as I indicated in my question, isn't it?


    But instead of using the json.encode / decode, I used a table as workaround.

    see:

    Please login or register to see this code.

    And then send this table to the QA.

    In the called QA I can check for 'type' table, and use it.

    Please login or register to see this code.

    But the result remains the same. tx.

     

     

    • Thanks 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • For completeness.

    If you do the call from a scene. Then 10ders proposal are the ones that works.

    3 hours ago, 10der said:

    1st of. 

    fibaro.call(qaID,"poem", "if", "you", "wanna", "call", "and", "funny", "call", "with", "self", "and", "pass", "parameters")

     

    Please login or register to see this attachment.

     

     

    when I do the next ACTION in my scene:

    Please login or register to see this code.

    and do the following in the QA

    Please login or register to see this code.

    I receive the next ERROR:

    [15.09.2020] [19:22:00] [DEBUG] [KLICKDIMMER 71]: onInit

    [15.09.2020] [19:22:00] [DEBUG] [KLICKDIMMER 71]: onAction: {"deviceId":71,"actionName":"updateMyProperty","args":[26,"clickdimmer",0]}

    [15.09.2020] [19:22:00] [DEBUG] [KLICKDIMMER 71]: ./include/main.lua:50: attempt to index a number value (local 'sender')

    [15.09.2020] [19:22:00] [ERROR] [QUICKAPP71]: QuickApp crashed

     

     

    You can change (like 10der) the transmitting call to :

    Please login or register to see this code.

    and the receiving part

    Please login or register to see this code.

    Or you can change the transmitting call to a json format:

    (last  row first code block)

    Please login or register to see this code.

    Don't decode the received part, leave the code as it is.

    Why? I have no clue!! but it works.

     

    I chose the json version!

    thanks 10der

     

     

    • Thanks 1
    Link to comment
    Share on other sites

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