Skip to content

Commit

Permalink
Wrap battery times sensors in proxy objects
Browse files Browse the repository at this point in the history
Because:
- The template doesn't need to change, we just manipulate what the
  sensor objects returns, depending on the measurement unit of the
  sensor.
  • Loading branch information
lunkwill42 committed Mar 17, 2021
1 parent 7f5b9c7 commit edf61ac
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/nav/web/navlets/ups.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ def get_context_data_view(self, context):
context['output'] = zip(output_voltages, output_power)

# Battery
context['battery_times'] = netbox.sensor_set.filter(
internal_name__in=['upsEstimatedMinutesRemaining',
'upsAdvBatteryRunTimeRemaining'])
context['battery_times'] = (
BatteryTimesProxy(sensor)
for sensor in netbox.sensor_set.filter(
internal_name__in=[
'upsEstimatedMinutesRemaining',
'upsAdvBatteryRunTimeRemaining',
]
)
)

context['battery_capacity'] = netbox.sensor_set.filter(
internal_name__in=['upsHighPrecBatteryCapacity',
Expand Down

0 comments on commit edf61ac

Please sign in to comment.