Skip to content

fix(wifi): honour a partially configured set of signal thresholds - #3691

Merged
nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/wifi-partial-thresholds
Aug 26, 2026
Merged

nicolargo merged 1 commit into
nicolargo:developfrom
ntdatt812:fix/wifi-partial-thresholds

Conversation

@ntdatt812

Copy link
Copy Markdown
Contributor

The defect

WifiPlugin.get_alert overrides the base implementation and chains its three comparisons (glances/plugins/wifi/__init__.py:146):

try:
    if value <= self.get_limit('critical', stat_name=self.plugin_name):
        ret = 'CRITICAL'
    elif value <= self.get_limit('warning', stat_name=self.plugin_name):
        ret = 'WARNING'
    elif value <= self.get_limit('careful', stat_name=self.plugin_name):
        ret = 'CAREFUL'
except (TypeError, KeyError):
    # Catch TypeError for issue1373
    ret = 'DEFAULT'

get_limit returns None for a level the config does not define (plugin/model.py:969). value <= None raises TypeError, the blanket handler catches it, and the whole result collapses to DEFAULT.

Because critical is tested first, omitting it silences the other two as well.

Measured on develop

all three thresholds configured:
  quality_level= -50 dBm -> OK
  quality_level= -70 dBm -> CAREFUL
  quality_level= -80 dBm -> WARNING
  quality_level= -90 dBm -> CRITICAL

only 'critical' configured (careful/warning left out):
  quality_level= -50 dBm -> DEFAULT      <- a strong signal is not even OK
  quality_level= -90 dBm -> CRITICAL

only 'careful' configured:
  quality_level= -50 dBm -> DEFAULT
  quality_level= -70 dBm -> DEFAULT      <- past the careful threshold, no alert

For comparison, the base class handles partial thresholds:
  sensors base get_alert(95) with only 'critical' -> CRITICAL

A user who sets just wifi_careful in glances.conf gets no wifi alert at all, silently.

The fix

Each level is read once and guarded on its own, the way GlancesPluginModel.get_alert already does (plugin/model.py:854-862) — and the way the sensors plugin is already tested for (test_partial_type_thresholds_are_used, test_partial_sensor_thresholds_are_used).

Two details worth calling out:

  • is not None, not truthiness. The base class uses if critical and value >= critical. These limits are negative dBm values, so a 0 threshold would be discarded by a truthiness test; is not None is exact.
  • The TypeError handler is kept but narrowed. It was added for issue TypeError on opening (Wifi plugin) #1373 (a non-numeric signal level). With the None comparisons gone that is now the only way it can fire, so it still does its original job and nothing else. KeyError is dropped because get_limit returns None rather than raising.

After:

only 'careful' configured:
  quality_level= -50 dBm -> OK
  quality_level= -70 dBm -> CAREFUL

Tests

New tests/test_plugin_wifi.py, 13 cases:

  • all four levels with a full config;
  • each level alone still alerts (careful only, warning only, critical only);
  • a strong signal is OK under any partial config, not undecorated;
  • the most severe matching level wins;
  • no thresholds at all stays DEFAULT;
  • a non-numeric level stays DEFAULT — the TypeError on opening (Wifi plugin) #1373 guard.

5 of the 13 fail on develop and all 13 pass with the patch.

$ pytest tests/test_plugin_wifi.py -q
13 passed

WifiPlugin.get_alert chained its three comparisons, so the first undefined level
was compared against None, raised TypeError, and the blanket handler dropped the
result to DEFAULT. Because 'critical' is tested first, leaving it out silenced
the other two: a config defining only wifi_careful produced no alert at all, and
even a strong signal came back undecorated instead of OK.

GlancesPluginModel.get_alert already guards each level separately, and the
sensors plugin has tests pinning that partial thresholds work. This brings wifi
in line. `is not None` rather than truthiness because these limits are negative
dBm values, where `if threshold` would discard a 0.

The TypeError handler is kept for a non-numeric signal level (issue nicolargo#1373) but
narrowed to that case, which is now the only way it can fire.
@nicolargo
nicolargo merged commit 8d6a845 into nicolargo:develop Aug 26, 2026
18 of 19 checks passed
@nicolargo

Copy link
Copy Markdown
Owner

Thanks @ntdatt812

Just merged into develop branch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants