Giter Site home page Giter Site logo

Comments (1)

sjorge avatar sjorge commented on July 18, 2024

More confusing things while looking into this, I tried generated the payload in zhc to see if I could at least get the write to work without messing with herdsman yet.

https://github.com/Koenkk/zigbee-herdsman-converters/blob/b9f29f55d3f0531c9235e38a6848908c9a493042/src/devices/ubisys.ts#L509

+                    const cluster = Zcl.Utils.getCluster('manuSpecificUbisysDeviceSetup');
+                    const attributes = {'inputActions': {elementType: 'octetStr', elements: resultingInputActions}};
+                    const payload: {attrId: number; dataType: number; attrData: number| string | boolean}[] = [];
+                    for (const [nameOrID, value] of Object.entries(attributes)) {
+                        if (cluster.hasAttribute(nameOrID)) {
+                            const attribute = cluster.getAttribute(nameOrID);
+                            payload.push({attrId: attribute.ID, attrData: value, dataType: attribute.type});
+                        } else if (!isNaN(Number(nameOrID))){
+                            // NOTE: tsc trisp here, but we take the prev branch
+                            //payload.push({attrId: Number(nameOrID), attrData: value.value, dataType: value.type});
+                        } else {
+                            throw new Error(`Unknown attribute '${nameOrID}', specify either an existing attribute or a number`);
+                        }
+                    }
+
+                    await devMgmtEp.writeStructured(
+                        'manuSpecificUbisysDeviceSetup',
+                        payload,
+                        manufacturerOptions.ubisysNull,
+                    );
+                    /*
                     await devMgmtEp.write(
                         'manuSpecificUbisysDeviceSetup',
                         {'inputActions': {elementType: 'octetStr', elements: resultingInputActions}},
                         manufacturerOptions.ubisysNull,
                     );
+                    */

TSC is very much not happy with this:

src/devices/ubisys.ts:517:65 - error TS2322: Type '{ elementType: string; elements: unknown[]; }' is not assignable to type 'string | number | boolean'.

517                             payload.push({attrId: attribute.ID, attrData: value, dataType: attribute.type});
                                                                    ~~~~~~~~

  src/devices/ubisys.ts:513:71
    513                     const payload: {attrId: number; dataType: number; attrData: number| string | boolean}[] = [];
                                                                              ~~~~~~~~
    The expected type comes from property 'attrData' which is declared here on type '{ attrId: number; dataType: number; attrData: string | number | boolean; }'


Found 1 error in src/devices/ubisys.ts:517

Which leaves me very confused as the original write passes {'inputActions': {elementType: 'octetStr', elements: resultingInputActions}}, as attributes param to endpoint.write() and that somehow does work but the code I added was copied from that function 😕

Edit 1:
I think we somehow end up here:

private writeArray(value: ZclArray): void {
const elTypeNumeric = typeof value.elementType === 'number' ? value.elementType : DataType[value.elementType];
this.writeUInt8(elTypeNumeric);
this.writeUInt16(value.elements.length);
value.elements.forEach(element => {
this.write(DataType[elTypeNumeric], element, {});
});
}

Which would make sense given this attribute is an array (ZCL data type 0x48) of raw binary data (ZCL data type 0x41).
Somehow for the endpoint.write() we bypass a tsc check somewhere allowing us to get here which in my hacked attempt to generate the payload in ZHC we hit.

Edit 2:
Completely manually massaging the ZclPayload:

                    await devMgmtEp.writeStructured(
                        'manuSpecificUbisysDeviceSetup',
                        [{attrId: 0x0001, selector: {}, dataType: Zcl.DataType.array, elementData: {elementType: 'octetStr', elements: resultingInputActions}}],
                        manufacturerOptions.ubisysNull,
                    );

Seems to work

from zigbee-herdsman.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.