charge status: Refactor to enum and move to module of use
The charge status is solely used in the hiddpp20 module, thus put it into this module. Related #2273
This commit is contained in:
parent
c34fd3c2b0
commit
c9d7d7234a
|
@ -44,7 +44,6 @@ from .common import BatteryLevelApproximation
|
||||||
from .common import BatteryStatus
|
from .common import BatteryStatus
|
||||||
from .common import FirmwareKind
|
from .common import FirmwareKind
|
||||||
from .common import NamedInt
|
from .common import NamedInt
|
||||||
from .hidpp20_constants import CHARGE_STATUS
|
|
||||||
from .hidpp20_constants import DEVICE_KIND
|
from .hidpp20_constants import DEVICE_KIND
|
||||||
from .hidpp20_constants import ChargeLevel
|
from .hidpp20_constants import ChargeLevel
|
||||||
from .hidpp20_constants import ChargeType
|
from .hidpp20_constants import ChargeType
|
||||||
|
@ -117,6 +116,13 @@ class MappingFlag(Flag):
|
||||||
DIVERTED = 0x01
|
DIVERTED = 0x01
|
||||||
|
|
||||||
|
|
||||||
|
class ChargeStatus(Flag):
|
||||||
|
CHARGING = 0x00
|
||||||
|
FULL = 0x01
|
||||||
|
NOT_CHARGING = 0x02
|
||||||
|
ERROR = 0x07
|
||||||
|
|
||||||
|
|
||||||
class FeaturesArray(dict):
|
class FeaturesArray(dict):
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
assert device is not None
|
assert device is not None
|
||||||
|
@ -1879,10 +1885,10 @@ def decipher_battery_voltage(report: bytes):
|
||||||
charge_type = ChargeType.STANDARD
|
charge_type = ChargeType.STANDARD
|
||||||
if flags & (1 << 7):
|
if flags & (1 << 7):
|
||||||
status = BatteryStatus.RECHARGING
|
status = BatteryStatus.RECHARGING
|
||||||
charge_sts = CHARGE_STATUS[flags & 0x03]
|
charge_sts = ChargeStatus(flags & 0x03)
|
||||||
if charge_sts is None:
|
if charge_sts is None:
|
||||||
charge_sts = ErrorCode.UNKNOWN
|
charge_sts = ErrorCode.UNKNOWN
|
||||||
elif charge_sts == CHARGE_STATUS.full:
|
elif ChargeStatus.FULL in charge_sts:
|
||||||
charge_lvl = ChargeLevel.FULL
|
charge_lvl = ChargeLevel.FULL
|
||||||
status = BatteryStatus.FULL
|
status = BatteryStatus.FULL
|
||||||
if flags & (1 << 3):
|
if flags & (1 << 3):
|
||||||
|
|
|
@ -179,16 +179,6 @@ class OnboardMode(IntEnum):
|
||||||
MODE_HOST = 0x02
|
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):
|
class ChargeLevel(IntEnum):
|
||||||
AVERAGE = 50
|
AVERAGE = 50
|
||||||
FULL = 90
|
FULL = 90
|
||||||
|
|
Loading…
Reference in New Issue