Advertisement
Python253

batstats.js

May 6th, 2024
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // -*- coding: utf-8 -*-
  2. // Filename: batstats.js
  3. // Version: 1.0.0
  4. // Author: Jeoi Reqi
  5.  
  6. // This script retrieves battery information.
  7. // The script presents battery details like status and charge level clearly.
  8. // Users can quickly gauge battery health and make informed decisions about power usage.
  9.  
  10. // Example Output:
  11. //    --------------------------------------------------
  12. //    :: BATTERY STATS ::
  13. //    --------------------------------------------------
  14. //
  15. //    Internal Battery: [AP18E8M]    Status: OK
  16. //    Battery Status:                Connected to AC (2)
  17. //    Charge Remaining:              95%
  18. //
  19. //    --------------------------------------------------
  20. console.log("-".repeat(50));
  21. console.log("\t\t:: BATTERY STATS ::");
  22. console.log("-".repeat(50));
  23.  
  24. const batteryStatus = {
  25.     1: 'Discharging',
  26.     2: 'Connected to AC',
  27.     3: 'Fully charged',
  28.     4: 'Low',
  29.     5: 'Critical',
  30.     6: 'Charging',
  31.     7: 'Charging/High',
  32.     8: 'Charging/Low',
  33.     9: 'Charging/Critical',
  34.     10: 'Undefined',
  35.     11: 'Partially Charged'
  36. };
  37.  
  38. // Assuming battery information is obtained from an API call
  39. const battery = {
  40.     Caption: 'Internal Battery',
  41.     Name: 'AP18E8M',
  42.     Status: 'OK',
  43.     BatteryStatus: 2,
  44.     EstimatedChargeRemaining: 95
  45. };
  46.  
  47. const batteryStatusDescription = batteryStatus[battery.BatteryStatus] || 'Unknown';
  48.  
  49. // Print battery information header
  50. console.log("");
  51. console.log(`${battery.Caption}: [${battery.Name}]    Status: ${battery.Status}`);
  52. console.log(`Battery Status:                ${batteryStatusDescription} (${battery.BatteryStatus})`);
  53. console.log(`Charge Remaining:              ${battery.EstimatedChargeRemaining}%\n`);
  54. console.log("-".repeat(50));
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement