Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update payload.js #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update payload.js #119

wants to merge 1 commit into from

Conversation

Watteco
Copy link

@Watteco Watteco commented Feb 7, 2025

add node power desc

Decoder Description

Explain the functionality of your decoder or any other relevant information.

Type of change

  • Adding a new Decoder of Connector
  • Adding a new Decoder of Network
  • Update or fixing an issue in existing Decoder

Decoder Information and Payload to test and review

  • Documentation of the hardware or protocol:
  • Payload of example the test the decoder:

Checklist for Adding a New Decoder

  • Created a new folder under ./decoders/network/ or ./decoders/connector/ with the name of your decoder.
  • Added a network.jsonc or connector.jsonc file that follows the structure defined in ./schema/.
  • Created version folders and added manifest.jsonc files for each version.
  • Followed the folder structure guidelines for manufacturer and sensor/device model.
  • The code has unit test and it's in TypeScript.

Additional Notes

Please add any other information that you think is important.

add node power desc
Comment on lines +887 to +902
// configuration node power desc
if ( (clusterdID === 0x0050 ) & (attributID === 0x0006)) {
index2 = index + 3;
if ((bytes[index+2] &0x01) === 0x01) {
tab.push({label:"ExternalPowerVoltage" ,value:(bytes[index2]*256+bytes[index2+1])/1000, date:lDate}) ;
index2=index2+2;
}
if ((bytes[index+2] &0x04) === 0x04) {
tab.push({label:"BatteryVoltage" ,value:(bytes[index2]*256+bytes[index2+1])/1000, date:lDate}) ;
index2=index2+2;
}
if ((bytes[index+2] &0x02) === 0x02) {decoded.data.rechargeable_battery_voltage = (bytes[index2]*256+bytes[index2+1])/1000;index2=index2+2;}
if ((bytes[index+2] &0x08) === 0x08) {decoded.data.solar_harvesting_voltage = (bytes[index2]*256+bytes[index2+1])/1000;index2=index2+2;}
if ((bytes[index+2] &0x10) === 0x10) {decoded.data.tic_harvesting_voltage = (bytes[index2]*256+bytes[index2+1])/1000;index2=index2+2;}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add unit tests for your modification to ensure everything is working as expected.

Additionally, when adding the unit tests, include the following test to verify that other data is allowed beyond what has been decoded.

describe("Shall not be parsed", () => {
  let payload = [
    { variable: "shallnotpass", value: "04096113950292" },
    { variable: "fport", value: 9 },
  ];
  payload = decoderRun(file_path, { payload });

  test("Output Result", () => {
    expect(Array.isArray(payload)).toBe(true);
  });

  test("Not parsed Result", () => {
    expect(payload).toEqual([
      { variable: "shallnotpass", value: "04096113950292" },
      { variable: "fport", value: 9 },
    ]);
  });
});

Example: https://github.com/tago-io/decoders/blob/main/decoders/connector/elsys/ems/v1.0.0/payload.test.ts

@mateuscardosodeveloper
Copy link
Collaborator

Hello @Watteco, I have reviewed your changes and requested one adjustment. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants