From edf61acfffce68fe8ca56624fd0230be3c688880 Mon Sep 17 00:00:00 2001 From: Morten Brekkevold Date: Wed, 17 Mar 2021 21:35:04 +0100 Subject: [PATCH] Wrap battery times sensors in proxy objects Because: - The template doesn't need to change, we just manipulate what the sensor objects returns, depending on the measurement unit of the sensor. --- python/nav/web/navlets/ups.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/python/nav/web/navlets/ups.py b/python/nav/web/navlets/ups.py index e570c39025..4a150d462a 100644 --- a/python/nav/web/navlets/ups.py +++ b/python/nav/web/navlets/ups.py @@ -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',