deconz-community / node-red-contrib-deconz

Node-Red Nodes for deCONZ connectivity.
GNU General Public License v3.0
81 stars 16 forks source link

Error in deconz-out with Homekit command when device lacks color support #182

Closed jrehwaldt closed 2 years ago

jrehwaldt commented 2 years ago

Current Behavior

When creating a Homekit integration for a device without color, eg. dimmable light or on/off switch, deconz-out crashes with the following stack trace:

5 Dec 20:40:05 - [error] [deconz-output:e13ec4ae128b8806] Error while processing command #1, TypeError: Cannot read property 'includes' of undefined                                                                                                         
TypeError: Cannot read property 'includes' of undefined                                                                                                                                                                                                      
    at CommandParser.parseHomekitArgs (/data/node_modules/node-red-contrib-deconz/src/runtime/CommandParser.js:170:50)                                                                                                                                       
    at CommandParser.getRequests (/data/node_modules/node-red-contrib-deconz/src/runtime/CommandParser.js:260:26)                                                                                                                                            
    at /data/node_modules/node-red-contrib-deconz/nodes/out.js:182:47                                                                                                                                                                                        
    at runMicrotasks (<anonymous>)                                                                                                                                                                                                                           
    at runNextTicks (internal/process/task_queues.js:60:5)
   ...

The issue is that the property deviceMeta.device_colorcapabilities is undefined for devices without colour support:

https://github.com/deconz-community/node-red-contrib-deconz/blob/86da6f8990fdbe25bcbc06444023666973429f50/src/runtime/CommandParser.js#L170

Expected Behavior

It should not crash and the Homekit action should be performed on the device.

Steps To Reproduce

Create a sequence deconz-input -> homekit service -> deconz-out with a non-color device.

image

(On a side note and unrelated: Please also note the wrongly formatted output [object Object] in the UI on the deconz-input node).

Example flow

    {
        "id": "29c2eeceb6193a02",
        "type": "deconz-input",
        "z": "2ff9c9f2.891136",
        "g": "40cac73109ba1b8c",
        "name": "",
        "topic": "",
        "config_version": 2,
        "server": "58d0e60c.b87eb8",
        "statustext": "",
        "statustext_type": "auto",
        "search_type": "device",
        "device_list": [
            "lights/uniqueid/00:15:8d:00:06:d7:34:32-01"
        ],
        "device_name": "",
        "query": "",
        "outputs": 1,
        "output_rules": [
            {
                "type": "homekit",
                "format": "single",
                "onstart": true,
                "onerror": true,
                "payload": [
                    "__auto__"
                ],
                "uniqueId": "ui-id-30"
            }
        ],
        "x": 110,
        "y": 2140,
        "wires": [
            [
                "946f6ccb9c6e19c4"
            ]
        ]
    },
    {
        "id": "946f6ccb9c6e19c4",
        "type": "homekit-service",
        "z": "2ff9c9f2.891136",
        "g": "40cac73109ba1b8c",
        "isParent": true,
        "hostType": "0",
        "bridge": "8127ab1e.5f5518",
        "accessoryId": "",
        "parentService": "",
        "name": "Dimmable Lamp",
        "serviceName": "Lightbulb",
        "topic": "",
        "filter": false,
        "manufacturer": "manufacturer",
        "model": "model",
        "serialNo": "serial",
        "firmwareRev": "",
        "hardwareRev": "",
        "softwareRev": "",
        "cameraConfigVideoProcessor": "ffmpeg",
        "cameraConfigSource": "",
        "cameraConfigStillImageSource": "",
        "cameraConfigMaxStreams": 2,
        "cameraConfigMaxWidth": 1280,
        "cameraConfigMaxHeight": 720,
        "cameraConfigMaxFPS": 10,
        "cameraConfigMaxBitrate": 300,
        "cameraConfigVideoCodec": "libx264",
        "cameraConfigAudioCodec": "libfdk_aac",
        "cameraConfigAudio": false,
        "cameraConfigPacketSize": 1316,
        "cameraConfigVerticalFlip": false,
        "cameraConfigHorizontalFlip": false,
        "cameraConfigMapVideo": "0:0",
        "cameraConfigMapAudio": "0:1",
        "cameraConfigVideoFilter": "scale=1280:720",
        "cameraConfigAdditionalCommandLine": "-tune zerolatency",
        "cameraConfigDebug": false,
        "cameraConfigSnapshotOutput": "disabled",
        "cameraConfigInterfaceName": "",
        "characteristicProperties": "{\"Brightness\":true}",
        "waitForSetupMsg": false,
        "outputs": 2,
        "x": 290,
        "y": 2140,
        "wires": [
            [
                "ab0a69339077e3e8"
            ],
            []
        ]
    },
    {
        "id": "ab0a69339077e3e8",
        "type": "deconz-output",
        "z": "2ff9c9f2.891136",
        "g": "40cac73109ba1b8c",
        "name": "",
        "config_version": 1,
        "server": "58d0e60c.b87eb8",
        "statustext": "",
        "statustext_type": "auto",
        "search_type": "device",
        "device_list": [
            "lights/uniqueid/00:15:8d:00:06:d7:34:32-01"
        ],
        "device_name": "",
        "query": "",
        "commands": [
            {
                "arg": {
                    "payload": {
                        "type": "msg",
                        "value": "payload"
                    },
                    "transitiontime": {
                        "type": "num",
                        "value": ""
                    },
                    "retryonerror": {
                        "type": "num",
                        "value": "0"
                    },
                    "aftererror": {
                        "type": "continue",
                        "value": ""
                    }
                },
                "type": "homekit",
                "domain": "lights",
                "uniqueId": "ui-id-26"
            }
        ],
        "specific": {
            "delay": {
                "type": "num",
                "value": "50"
            },
            "result": {
                "type": "at_end",
                "value": ""
            }
        },
        "x": 520,
        "y": 2140,
        "wires": [
            []
        ]
    },
    {
        "id": "58d0e60c.b87eb8",
        "type": "deconz-server",
        "name": "deconz",
        "ip": "xxxxx",
        "port": "xxxxxx",
        "apikey": "xxxx",
        "ws_port": "xxxxx",
        "secure": true,
        "polling": "15"
    },
    {
        "id": "8127ab1e.5f5518",
        "type": "homekit-bridge",
        "z": "xxxxxxxxxx",
        "bridgeName": "node-red-homekit",
        "pinCode": "xxx-xxxx-xxxx",
        "port": "",
        "allowInsecureRequest": false,
        "manufacturer": "NRCHKB",
        "model": "1.2.0",
        "serialNo": "Default Serial Number",
        "firmwareRev": "1.2.0",
        "hardwareRev": "1.2.0",
        "softwareRev": "1.2.0",
        "customMdnsConfig": false,
        "mdnsMulticast": true,
        "mdnsInterface": "",
        "mdnsPort": "",
        "mdnsIp": "",
        "mdnsTtl": "",
        "mdnsLoopback": true,
        "mdnsReuseAddr": true,
        "allowMessagePassthrough": false
    }
]

Environment

Zehir commented 2 years ago

Could you post your device metadata ?

jrehwaldt commented 2 years ago

Could you post your device metadata ?

Sure. Do you have some documentation somewhere where I get them from?

Zehir commented 2 years ago

Could you post your device metadata ?

Sure. Do you have some documentation somewhere where I get them from?

Just read the msg.meta value from à get node

jrehwaldt commented 2 years ago
{
  "etag": "453808ffafae3f948c4f30e86162c75d",
  "hascolor": false,
  "lastannounced": null,
  "lastseen": "2021-12-05T20:17Z",
  "manufacturername": "Sunricher",
  "modelid": "HK-LN-DIM-A",
  "name": "Living Room/Table Lamp",
  "state": {
    "alert": "none",
    "bri": 66,
    "on": false,
    "reachable": true
  },
  "swversion": "2.5.3_r49",
  "type": "Dimmable light",
  "uniqueid": "68:0a:e2:ff:fe:a4:48:26-01",
  "device_type": "lights",
  "device_id": 7,
  "device_path": "lights/uniqueid/68:0a:e2:ff:fe:a4:48:26-01"
}

or Lidl switches

{
  "etag": "abfd4686a24ab1762465f2c8961fc3c9",
  "hascolor": false,
  "lastannounced": null,
  "lastseen": "2021-12-05T20:14Z",
  "manufacturername": "_TZ3000_kdi2o9m6",
  "modelid": "TS011F",
  "name": "Living Room/Christmas Star",
  "state": {
    "alert": "none",
    "on": true,
    "reachable": true
  },
  "swversion": "66",
  "type": "On/Off plug-in unit",
  "uniqueid": "60:a4:23:ff:fe:05:50:8e-0b",
  "device_type": "lights",
  "device_id": 15,
  "device_path": "lights/uniqueid/60:a4:23:ff:fe:05:50:8e-0b"
}
Zehir commented 2 years ago

Ah I see, hascolor is false, I will make à fix tomorrow

Zehir commented 2 years ago

The fix was published in 2.1.3.

jrehwaldt commented 2 years ago

Thanks. Works like a charm 👍 (also the deconz-input indicator)