dresden-elektronik / deconz-rest-plugin-v2

deCONZ REST-API version 2 development repository.
BSD 3-Clause "New" or "Revised" License
17 stars 0 forks source link

Incorrect data type assumption on resource items #10

Closed SwoopX closed 2 years ago

SwoopX commented 2 years ago

Describe the bug

The current DDF implementation partially assumes the wrong data type for incoming data This e.g. leads to the need to treat integer values as strings.

As an example serves the windowopen state of a Danfoss Ally thermostat. On zigbee level, that data is represented as enum8 with values from 0 - 4. Using the below JS Code, the result will always be "Unknown".

switch (Attr.val) {
    case 0:
        Item.val = "Quarantine";
        break;
    case 1:
        Item.val = "Closed";
        break;
    case 2:
        Item.val = "Hold";
        break;
    case 3:
        Item.val = "Open";
        break;
    case 4:
        Item.val = "Open (external), closed (internal)";
        break;
    default:
        Item.val = "Unknown";
        break;
}

Presumably, the root cause is that the data type defined in resource.cpp for the respective resource item is string. However, this should be considered as the output data type only for consistency.

Steps to reproduce the behavior

See above. Changing the case values to strings results in the expected behavior.

Expected behavior

Enforce the defined data type for a resource item as output data type and leave the input data type untouched.

Screenshots

grafik

grafik

Environment

deCONZ Logs

N/A

Additional context

N/A

manup commented 2 years ago

Should be fixed by now?

SwoopX commented 2 years ago

Ah, yes, forgot to close it :)