Skip to content

Commit

Permalink
charge status: Refactor to enum and move to module of use
Browse files Browse the repository at this point in the history
The charge status is solely used in the hiddpp20 module, thus put it
into this module.

Related pwr-Solaar#2273
  • Loading branch information
MattHag committed Dec 1, 2024
1 parent 77564d5 commit 3d0b401
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 9 additions & 3 deletions lib/logitech_receiver/hidpp20.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from .common import BatteryStatus
from .common import FirmwareKind
from .common import NamedInt
from .hidpp20_constants import CHARGE_STATUS
from .hidpp20_constants import DEVICE_KIND
from .hidpp20_constants import ChargeLevel
from .hidpp20_constants import ChargeType
Expand Down Expand Up @@ -117,6 +116,13 @@ class MappingFlag(Flag):
DIVERTED = 0x01


class ChargeStatus(Flag):
CHARGING = 0x00
FULL = 0x01
NOT_CHARGING = 0x02
ERROR = 0x07


class FeaturesArray(dict):
def __init__(self, device):
assert device is not None
Expand Down Expand Up @@ -1879,10 +1885,10 @@ def decipher_battery_voltage(report: bytes):
charge_type = ChargeType.STANDARD
if flags & (1 << 7):
status = BatteryStatus.RECHARGING
charge_sts = CHARGE_STATUS[flags & 0x03]
charge_sts = ChargeStatus(flags & 0x03)
if charge_sts is None:
charge_sts = ErrorCode.UNKNOWN
elif charge_sts == CHARGE_STATUS.full:
elif ChargeStatus.FULL in charge_sts:
charge_lvl = ChargeLevel.FULL
status = BatteryStatus.FULL
if flags & (1 << 3):
Expand Down
10 changes: 0 additions & 10 deletions lib/logitech_receiver/hidpp20_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,6 @@ class OnboardMode(IntEnum):
MODE_HOST = 0x02


CHARGE_STATUS = NamedInts(charging=0x00, full=0x01, not_charging=0x02, error=0x07)


class ChargeStatus(IntEnum):
CHARGING = 0x00
FULL = 0x01
NOT_CHARGING = 0x02
ERROR = 0x07


class ChargeLevel(IntEnum):
AVERAGE = 50
FULL = 90
Expand Down

0 comments on commit 3d0b401

Please sign in to comment.