athombv / homey-apps-sdk-issues

This issue tracker is for Homey Developers using the Apps SDK.
21 stars 4 forks source link

[HomeyCompose] Unexpected when a same flow is used by multiple drivers #318

Closed OlivierZal closed 1 year ago

OlivierZal commented 1 year ago

When a same flow template is defined under .homeycompose/drivers/flow/<triggers|conditions|actions> extends multiple drivers, the following error is raised:

✖ Error: Found multiple Flow card triggers with the id "mode_changed", all Flow cards should have a unique id.

The reason is that 2 different cards are created in app.json:

"flow": {
    "triggers": [
      {
        "id": "mode_changed",
        "title": {
          "en": "The mode has changed",
          "fr": "Le mode a changé"
        },
        "tokens": [
          {
            "name": "mode",
            "type": "string",
            "title": {
              "en": "Mode",
              "fr": "Mode"
            },
            "example": {
              "en": "Eco",
              "fr": "Éco"
            }
          }
        ],
        "args": [
          {
            "type": "device",
            "name": "device",
            "filter": "driver_id=heatzy"
          }
        ]
      },
      {
        "id": "mode_changed",
        "title": {
          "en": "The mode has changed",
          "fr": "Le mode a changé"
        },
        "tokens": [
          {
            "name": "mode",
            "type": "string",
            "title": {
              "en": "Mode",
              "fr": "Mode"
            },
            "example": {
              "en": "Eco",
              "fr": "Éco"
            }
          }
        ],
        "args": [
          {
            "type": "device",
            "name": "device",
            "filter": "driver_id=heatzy_1"
          }
        ]
      }
    ],
...

although we would expect only one card as follows (with all drivers in filter):

"flow": {
    "triggers": [
      {
        "id": "mode_changed",
        "title": {
          "en": "The mode has changed",
          "fr": "Le mode a changé"
        },
        "tokens": [
          {
            "name": "mode",
            "type": "string",
            "title": {
              "en": "Mode",
              "fr": "Mode"
            },
            "example": {
              "en": "Eco",
              "fr": "Éco"
            }
          }
        ],
        "args": [
          {
            "type": "device",
            "name": "device",
            "filter": "driver_id=heatzy,heatzy_1"
          }
        ]
      }
    ],
...

Here's the code to adapt: https://github.com/athombv/node-homey/blob/master/lib/HomeyCompose.js#L341

Otherwise we miss the interest of having templates...

OlivierZal commented 1 year ago

Note: I know I can add different ids in order to differenciate them.

WeeJeWel commented 1 year ago

While Homey Compose enabled you to define Flow cards on a driver-leve, in reality Flow cards are available app-wide.

If you 'share' a Flow card between drivers, you need to move it to the app level, so in .homeycompose/flow/.../my_card.json.

Then add a filter "filter": "driver_id=mydriver1|mydriver2". Here | means 'or'.

OlivierZal commented 1 year ago

@WeeJeWel, thanks for your answer.

I do mean at the driver level, that is some drivers (and not others).

WeeJeWel commented 1 year ago

That's why you need to target those drivers with driver_id=mydriver1|mydriver2|... :)

OlivierZal commented 1 year ago

Yes @WeeJeWel, and it works well (that's why I close the issue).