Skip to content

Add support for more UPS statuses #8

@jimklimov

Description

@jimklimov

Currently (v0.70) WMNut only supports a few device status values, namely OL, OB, LB, OVER(loaded):

  • wmnut/src/wmnut.h

    Lines 78 to 85 in e3255f7

    /* UPS status definition */
    #define UPS_DEFAULT 0
    #define UPS_LOWBATT 1
    #define UPS_ONBATT 2
    #define UPS_ONLINE 3
    #define UPS_OVERLOAD 4
  • wmnut/src/wmnut.c

    Lines 130 to 151 in e3255f7

    void get_ups_info(void)
    {
    char value[SMALLBUF];
    int retVal;
    /* Get UPS status */
    if (get_ups_var ("ups.status", value) > NOK) {
    if (!strncmp(value, "OL", 2))
    CurHost->ups_status = UPS_ONLINE;
    else if (!strncmp(value, "OB", 2))
    CurHost->ups_status = UPS_ONBATT;
    else if (!strstr(value, "LB"))
    CurHost->ups_status = UPS_LOWBATT;
    else if (!strncmp(value, "OVER", 4))
    CurHost->ups_status = UPS_OVERLOAD;
    else
    CurHost->ups_status = UPS_DEFAULT;
    }
    else
    CurHost->ups_status = UPS_DEFAULT;
  • wmnut/src/wmnut.c

    Lines 344 to 435 in e3255f7

    /* Check UPS status */
    switch (CurHost->ups_status) {
    /* case UPS_LOWBATT: */
    case UPS_ONBATT:
    {
    if (CurHost->battery_percentage <= CriticalLevel)
    {
    /* Battery Status: Critical.
    * Blink red battery [TODO : and digital %age] on/off...
    */
    if (Toggle||(BlinkRate == 0.0)) {
    /*
    if (Beep)
    XBell(display, Volume);
    */
    /* Toggle = OFF; */
    copyXPMArea(99, 20, 12, 7, 30, 50);
    }
    else{
    /* Toggle = ON; */
    copyXPMArea(83, 20, 12, 7, 30, 50);
    }
    }
    else if (CurHost->battery_percentage <= LowLevel) {
    /*
    * Battery Status: Low.
    * Blink the yellow battery [TODO : and digital %age] on/off...
    */
    if (Toggle||(BlinkRate == 0.0)) {
    /*
    if (Beep)
    XBell(display, Volume);
    */
    /* Toggle = OFF; */
    copyXPMArea(99, 20, 12, 7, 30, 50);
    }
    else{
    /* Toggle = ON; */
    copyXPMArea(69, 20, 12, 7, 30, 50);
    }
    }
    else {
    /*
    * Battery Status: High but charging.
    * Blink the green battery [TODO : and digital %age] on/off...
    */
    if (Toggle||(BlinkRate == 0.0)) {
    /*
    if (Beep)
    XBell(display, Volume);
    */
    copyXPMArea(99, 20, 12, 7, 30, 50);
    }
    else
    copyXPMArea(83, 6, 12, 7, 30, 50);
    }
    }
    break;
    case UPS_OVERLOAD:
    {
    /*
    * UPS is overloaded.
    * [TODO : Blink the battery load %age on/off...]
    */
    /* Hide digits and '%' */
    copyXPMArea(37, 34, 19, 7,37, 34);
    }
    break;
    case UPS_ONLINE:
    {
    /*
    * UPS on-line. I.e. we are "plugged-in".
    */
    copyXPMArea(68, 6, 12, 7, 30, 50);
    }
    break;
    case UPS_DEFAULT:
    {
    /*
    * used to "erase" UPS status when COM_LOST.
    */
    copyXPMArea(99, 20, 12, 7, 30, 50);
    }
    break;
    default:
    break;
    }

Recent years of evolution on NUT side added many more values, see https://github.com/networkupstools/nut/blob/master/clients/status.h and https://github.com/networkupstools/nut/blob/master/clients/upsmon.h -- such as "administrative OFF", "administrative bypass", "calibration", "trim/boost", and recently "ECO mode" in networkupstools/nut#2637 - would be nice to reflect those in the widget.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions