Pairing: custom view and session.emit

Hi, during pairing I am trying to send an event to a custom view but with no success. I have no problem if the custom view is called via the “normal” pairing navigation button (next or prev), but if I call the custom view programmatically with “await session.showView(‘my_view’)” then nothing happens:

From my driver.js

onRepair(session) {
session.setHandler(“showView”, async (viewId) => {

  if (viewId === "my_view") {

      await session.emit("error", this.loginError);

  }
});

}

From custom view:

Homey.on(“error”, function (err) {
Homey.alert(err, “error”);
});

1 Like

Assuming that the session.emit() code is actually being reached, try using a different name (not error).

Hi Robert, same problem even using a different name than ‘error’.

The strange thing is that if I put the custom view as the first, session.emit works perfectly. If I put it as the second and get there by pressing the “next” button once again session.emit works without problems.

If instead I get to the custom view programmatically (so using “await session.showView(‘custom_view’)” or “await session.nextView()”) the custom view is shown but session.emit is not called.

You need to do some more debugging to find out which one of the following is the cause of the problem:

  • is the showView event not being emitted?
  • is the viewId different from what you expect?
  • is the error (or differently named) event not being caught by Homey.on()?

Hi Robert, I did some test and discovered that the error (or bug?!) is on the structure of the driver.compose.json file:

{
“repair”: [
{
“id”: “ewelink_repair_view”
},
{
“id”: “ending_loading”,
“template”: “loading”
},
{
“id”: “repair_done”,
“template”: “done”
}
]
}

The pairing process that I had implemented provides an initial custom view for login, after a loading page and depending on the outcome of the login process from the loading page you went forward to the final page if there were no errors or you went back to the custom view in case of an error.

Once “re-entered” in the custom view in case of error, session.emit stops working.

To bypass the problem I removed the loading page: once the login process has started I stay on the custom view using a css that adds a loading state on the button and in case of an error I launch session.emit(“error”) which in this way is received without problems by the html page.