Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for more UPS statuses #8

Open
jimklimov opened this issue Oct 11, 2024 · 1 comment · May be fixed by #10
Open

Add support for more UPS statuses #8

jimklimov opened this issue Oct 11, 2024 · 1 comment · May be fixed by #10

Comments

@jimklimov
Copy link
Member

jimklimov commented Oct 11, 2024

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.

@desertwitch
Copy link

I'm currently working on this as a kind of follow-up to the changes recently proposed to upsmon (ALARM, ECO), will open a pull request when done here as well (might take a while as I'm a bit swamped with daily life at the moment). 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants