From 8e792c4f4da7111d566377eabd2314c707aadc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sat, 9 Jul 2016 23:55:14 +0200 Subject: dwmstatus: try to show power used by UPS --- dwmstatus.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dwmstatus.c b/dwmstatus.c index daedb81..5453202 100644 --- a/dwmstatus.c +++ b/dwmstatus.c @@ -1672,6 +1672,11 @@ static struct simple_config_item g_config_table[] = { "nut_enabled", "off", "NUT UPS status reading enabled" }, { "nut_load_thld", "50", "NUT threshold for load display" }, + // This is just a hack because my UPS doesn't report that value; a more + // proper way of providing this information would be by making use of the + // enhanced configuration format and allowing arbitrary per-UPS overrides + { "nut_load_power", NULL, "ups.realpower.nominal override" }, + { NULL, NULL, NULL } }; @@ -2280,7 +2285,22 @@ nut_process_ups (struct app_context *ctx, struct str_vector *ups_list, && xstrtoul (&load_n, load, 10) && xstrtoul (&threshold_n, threshold, 10) && load_n >= threshold_n) - str_vector_add_owned (&items, xstrdup_printf ("load %s%%", load)); + { + struct str item; + str_init (&item); + str_append_printf (&item, "load %s%%", load); + + const char *power = str_map_find (dict, "ups.realpower.nominal"); + // Override if NUT cannot tell it correctly for whatever reason + if (!power) power = str_map_find (&ctx->config, "nut_load_power"); + + // Approximation of how much electricity the perpihery actually uses + unsigned long power_n; + if (power && xstrtoul (&power_n, power, 10)) + str_append_printf (&item, " (~%luW)", power_n * load_n / 100); + + str_vector_add_owned (&items, str_steal (&item)); + } struct str result; str_init (&result); -- cgit v1.2.3