Battery status report

This “case” kept me awake for 3 nights, now I found a way to get the Notes field data, and edited a script for battery level reporting.
Can you test the code below?

Code

const devicesObject = await Homey.devices.getDevices({ filter: { class: 'sensor' } });
const deviceKeys = Object.keys(devicesObject);
const batteryLevels = [];

for (const deviceKey of deviceKeys) {
  const device = devicesObject[deviceKey];
  const batteryCapability = device.capabilitiesObj?.measure_battery;
    if (batteryCapability) {
      const batteryLevel = batteryCapability.value;
      const deviceName = device.name;
      const batteryInfo = device.energyObj.batteries;
      const deviceNote = device.note;
      batteryLevels.push({ name: deviceName, battery: batteryLevel, info: batteryInfo, note: deviceNote });
      }
  }
// Sort on charge level low > high
batteryLevels.sort(function(a, b) {
return a.battery - b.battery;
});

const batteryInfoText = batteryLevels.map((device) => `- ${device.name} \nCharge: ${device.battery}% \nInfo: ${device.info} \nNote: ${device.note}`).join('\n');
      
console.log('Device Battery info:\n' + batteryInfoText);
// for use in Homeyscript flow cards:
return 'Device Battery info:\n' + batteryInfoText;



NB
To have it formatted like:

You just have to change this line

const batteryInfoText = batteryLevels.map((device) => `- ${device.name} \nCharge: ${device.battery}% \nInfo: ${device.info} \nNote: ${device.note}`).join('\n');

into this:

const batteryInfoText = batteryLevels.map((device) => `${device.name}, ${device.info}, ${device.note}, ${device.battery}%`).join('\n');

Output: