Skip to content

Commit

Permalink
Fix crash when user has channel 1 disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
David00 committed Apr 3, 2023
1 parent ba8b129 commit 75372b0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rpi_power_monitor/power_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,11 @@ def calculate_power(self, samples, board_voltage):
ac_voltage_ratio = (self.grid_voltage / self.ac_transformer_output_voltage) * 11 # Rough approximation
voltage_scaling_factor = vref * ac_voltage_ratio * self.voltage_calibration

num_samples = len(v_samples_1)
# Get the number of samples by checking the length of one of the sample buffers.
for chan_num in range(1, 7):
if f'ct{chan_num}' in samples.keys():
num_samples = len(samples[f'ct{chan_num}'])
break

for i in range(0, num_samples):
if ct1_samples:
Expand Down

0 comments on commit 75372b0

Please sign in to comment.