Leggin / dirigera

This repository provides an unofficial Python client for controlling the IKEA Dirigera Smart Home Hub.
MIT License
99 stars 17 forks source link

Doubled response from event listener #72

Closed slajob closed 2 months ago

slajob commented 2 months ago

Hi, Some kind of strange issue, I'm using debug code as below:

import dirigera
import json
from typing import Any

dirigera_hub = dirigera.Hub(
    token="tokennn",
    ip_address="ippp"
)

def prettify(message):
    return json.dumps(json.loads(message), indent=2)

def on_message(ws: Any, message: str):
    print(prettify(message)+"\n")

def on_error(ws: Any, message: str):
    print("err",message)

And when I push button on SOMRIG shortcut button assigned to empty scene "test"

    {
        "id": "592edaae-0bac-4689-b31a-197cccf36ed6",
        "info": {
            "name": "Test",
            "icon": "scenes_clean_sparkles"
        },
        "type": "userScene",
        "triggers": [
            {
                "id": "549164c0-f3ab-49a1-b7dc-1d05704808de",
                "type": "app",
                "triggeredAt": "2024-04-19T20:03:29.847Z",
                "disabled": false
            },
            {
                "id": "ed3d5e33-d503-42cd-b0b2-469f106812f2",
                "type": "controller",
                "triggeredAt": "2024-04-20T10:50:22.715Z",
                "disabled": false,
                "trigger": {
                    "days": [
                        "Mon",
                        "Tue",
                        "Wed",
                        "Thu",
                        "Fri",
                        "Sat",
                        "Sun"
                    ],
                    "controllerType": "shortcutController",
                    "clickPattern": "singlePress",
                    "buttonIndex": 0,
                    "deviceId": "b55c75ec-829c-4623-a167-0b537569c9e2_1"
                }
            }
        ],
        "actions": [
            {
                "id": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
                "type": "device",
                "deviceId": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
                "enabled": true,
                "attributes": {
                    "isOn": false
                }
            }
        ],
        "commands": [],
        "createdAt": "2024-04-15T16:48:31.309Z",
        "lastCompleted": "2024-04-20T10:50:22.721Z",
        "lastTriggered": "2024-04-20T10:50:22.721Z",
        "undoAllowedDuration": 30,
        "lastUndo": "2024-04-15T17:01:21.553Z"
    }

I got two identical responses, differing only in id and date. Responses received back to back in two messages

First response:

{
  "id": "c9e53a85-bd68-40cc-9c4b-26fc21db492b",
  "time": "2024-04-20T10:49:53.823Z",
  "specversion": "3.150.0",
  "source": "urn:com:ikea:homesmart:iotc:rulesengine",
  "type": "sceneUpdated",
  "data": {
    "id": "592edaae-0bac-4689-b31a-197cccf36ed6",
    "info": {
      "name": "Test",
      "icon": "scenes_clean_sparkles"
    },
    "type": "userScene",
    "triggers": [
      {
        "id": "549164c0-f3ab-49a1-b7dc-1d05704808de",
        "type": "app",
        "triggeredAt": "2024-04-19T20:03:29.847Z",
        "disabled": false
      },
      {
        "id": "ed3d5e33-d503-42cd-b0b2-469f106812f2",
        "type": "controller",
        "triggeredAt": "2024-04-20T10:49:53.823Z",
        "disabled": false,
        "trigger": {
          "days": [
            "Mon",
            "Tue",
            "Wed",
            "Thu",
            "Fri",
            "Sat",
            "Sun"
          ],
          "controllerType": "shortcutController",
          "clickPattern": "singlePress",
          "buttonIndex": 0,
          "deviceId": "b55c75ec-829c-4623-a167-0b537569c9e2_1"
        }
      }
    ],
    "actions": [
      {
        "id": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
        "type": "device",
        "deviceId": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
        "enabled": true,
        "attributes": {
          "isOn": false
        }
      }
    ],
    "commands": [],
    "createdAt": "2024-04-15T16:48:31.309Z",
    "lastCompleted": "2024-04-20T10:48:00.793Z",
    "lastTriggered": "2024-04-20T10:48:00.793Z",
    "undoAllowedDuration": 30,
    "lastUndo": "2024-04-15T17:01:21.553Z"
  }
}

Second response:

{
  "id": "13a9d10d-aec5-497b-9fb9-a7a7201e2913",
  "time": "2024-04-20T10:49:53.858Z",
  "specversion": "3.150.0",
  "source": "urn:com:ikea:homesmart:iotc:rulesengine",
  "type": "sceneUpdated",
  "data": {
    "id": "592edaae-0bac-4689-b31a-197cccf36ed6",
    "info": {
      "name": "Test",
      "icon": "scenes_clean_sparkles"
    },
    "type": "userScene",
    "triggers": [
      {
        "id": "549164c0-f3ab-49a1-b7dc-1d05704808de",
        "type": "app",
        "triggeredAt": "2024-04-19T20:03:29.847Z",
        "disabled": false
      },
      {
        "id": "ed3d5e33-d503-42cd-b0b2-469f106812f2",
        "type": "controller",
        "triggeredAt": "2024-04-20T10:49:53.823Z",
        "disabled": false,
        "trigger": {
          "days": [
            "Mon",
            "Tue",
            "Wed",
            "Thu",
            "Fri",
            "Sat",
            "Sun"
          ],
          "controllerType": "shortcutController",
          "clickPattern": "singlePress",
          "buttonIndex": 0,
          "deviceId": "b55c75ec-829c-4623-a167-0b537569c9e2_1"
        }
      }
    ],
    "actions": [
      {
        "id": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
        "type": "device",
        "deviceId": "98bb9c74-2899-4cc8-bca3-d7ba111a96ff_1",
        "enabled": true,
        "attributes": {
          "isOn": false
        }
      }
    ],
    "commands": [],
    "createdAt": "2024-04-15T16:48:31.309Z",
    "lastCompleted": "2024-04-20T10:49:53.833Z",
    "lastTriggered": "2024-04-20T10:49:53.833Z",
    "undoAllowedDuration": 30,
    "lastUndo": "2024-04-15T17:01:21.553Z"
  }
}

What could be the reason for this? It's not a big deal, because it can be reduced simply using debouncing time sleep, but still interesting.

slajob commented 2 months ago

@bjorncs reproduced this even with directly through Dirigera using websocket. So it looks like dirigera system bug