Function: battery--upower-state

battery--upower-state is a byte-compiled function defined in battery.el.gz.

Signature

(battery--upower-state PROPS STATE)

Documentation

Merge the UPower battery state in PROPS with STATE.

This is an extension of the UPower DisplayDevice algorithm for merging multiple battery states into one. PROPS is an alist of battery properties from battery-upower-device-interface, and STATE is a symbol representing the state to merge with.

Source Code

;; Defined in /usr/src/emacs/lisp/battery.el.gz
(defun battery--upower-state (props state)
  "Merge the UPower battery state in PROPS with STATE.
This is an extension of the UPower DisplayDevice algorithm for
merging multiple battery states into one.  PROPS is an alist of
battery properties from `battery-upower-device-interface', and
STATE is a symbol representing the state to merge with."
  ;; Map UPower enum into our printable symbols.
  (let* ((new (pcase (cdr (assoc "State" props))
                (1 'charging)
                (2 'discharging)
                (3 'empty)
                (4 'fully-charged)
                (5 'pending-charge)
                (6 'pending-discharge)))
         ;; Unknown state represented by nil.
         (either (delq nil (list new state))))
    ;; Earlier states override later ones.
    (car (cond ((memq 'charging either))
               ((memq 'discharging either))
               ((memq 'pending-charge either))
               ((memq 'pending-discharge either))
               ;; Only options left are full or empty,
               ;; but if they conflict return nil.
               ((null (cdr either)) either)
               ((apply #'eq either) either)))))