|
772 | 772 | sections.innerHTML += element; |
773 | 773 | } |
774 | 774 |
|
| 775 | + |
| 776 | + export function convertSecondsToHHMM(totalSeconds) { |
| 777 | + const hours = Math.floor(totalSeconds / 3600); |
| 778 | + const minutes = Math.floor((totalSeconds % 3600) / 60); |
| 779 | + |
| 780 | + // You can customize the format here |
| 781 | + return `${hours}h ${minutes}m`; |
| 782 | + } |
| 783 | + |
| 784 | + |
| 785 | + |
775 | 786 | monitorStarted = false; |
776 | 787 | function fetchSchedule() { |
777 | 788 | fetchBatteryInfo().then(info => { |
|
820 | 831 | voltage: info.totalVolts, |
821 | 832 | }); |
822 | 833 |
|
823 | | - // use current capacity, current and nominal capacity to calculate remaining |
824 | | - let secondsRemaining = |
825 | | - (info.remainingCapacityAh / Math.abs(info.current)) * 3600; |
| 834 | + const charging = current > 0; |
| 835 | + const discharging = current < 0; |
| 836 | + |
| 837 | + let secondsRemaining; |
826 | 838 |
|
827 | | - const charging = info.current > 0; |
828 | | - const discharging = info.current < 0; |
829 | 839 | if (charging) { |
830 | 840 | secondsRemaining = |
831 | | - ((info.nominalCapacityAh - info.remainingCapacityAh) / |
832 | | - Math.abs(info.current)) * |
833 | | - 3600; |
| 841 | + ((nominalCapacityAh - remainingCapacityAh) / Math.abs(current)) * 3600; |
| 842 | + } else if (discharging) { |
| 843 | + secondsRemaining = (remainingCapacityAh / Math.abs(current)) * 3600; |
834 | 844 | } |
| 845 | + const HHMMRemaining = convertSecondsToHHMM(secondsRemaining); |
835 | 846 |
|
836 | 847 | let estTitle = ''; |
837 | 848 | if (charging || discharging) { |
838 | | - estTitle = `Estimated ${ |
| 849 | + estTitle = `Est ${ |
839 | 850 | charging ? 'Charging' : 'Discharging' |
840 | | - }: ${new Date(secondsRemaining * 1000).toISOString().slice(11, 19)}`; |
| 851 | + }: ${HHMMRemaining}`; |
841 | 852 | } |
842 | 853 | const estTime = document.getElementById('estimateTime'); |
843 | 854 | estTime.innerText = !charging && !discharging ? '' : estTitle; |
|
0 commit comments