handle 0x07 battery notifications with indicating charging, but with no battery level
This commit is contained in:
parent
1d305db29e
commit
1d438f098f
|
|
@ -163,10 +163,21 @@ def parse_battery_reply_07(level, battery_status):
|
||||||
else BATTERY_APPOX.low if level == 3 # low
|
else BATTERY_APPOX.low if level == 3 # low
|
||||||
else BATTERY_APPOX.critical if level == 1 # critical
|
else BATTERY_APPOX.critical if level == 1 # critical
|
||||||
else BATTERY_APPOX.empty ) # wtf?
|
else BATTERY_APPOX.empty ) # wtf?
|
||||||
status = ('charging' if battery_status == 0x21 or battery_status == 0x25
|
|
||||||
else 'fully charged' if battery_status == 0x22
|
if battery_status == 0x00:
|
||||||
else 'discharging' if battery_status == 0x00
|
status = 'discharging'
|
||||||
else None)
|
elif battery_status & 0x21 == 0x21:
|
||||||
|
status = 'charging'
|
||||||
|
elif battery_status & 0x22 == 0x22:
|
||||||
|
status = 'fully charged'
|
||||||
|
else:
|
||||||
|
_log.warn("could not parse 0x07 battery status: %02X (level %02X)", battery_status, level)
|
||||||
|
status = None
|
||||||
|
|
||||||
|
if battery_status & 0x03 and level == 0:
|
||||||
|
# some 'charging' notifications may come with no battery level information
|
||||||
|
charge = None
|
||||||
|
|
||||||
return charge, status
|
return charge, status
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,15 +169,21 @@ class DeviceStatus(dict):
|
||||||
__nonzero__ = __bool__
|
__nonzero__ = __bool__
|
||||||
|
|
||||||
def set_battery_info(self, level, status, timestamp=None):
|
def set_battery_info(self, level, status, timestamp=None):
|
||||||
assert isinstance(level, int)
|
|
||||||
if _log.isEnabledFor(_DEBUG):
|
if _log.isEnabledFor(_DEBUG):
|
||||||
_log.debug("%s: battery %s, %s", self._device, level, status)
|
_log.debug("%s: battery %s, %s", self._device, level, status)
|
||||||
|
|
||||||
|
if level is None:
|
||||||
|
# Some notifications may come with no battery level info, just
|
||||||
|
# charging state info, so assume the level is unchanged.
|
||||||
|
level = self[KEYS.BATTERY_LEVEL]
|
||||||
|
else:
|
||||||
|
assert isinstance(level, int)
|
||||||
|
|
||||||
# TODO: this is also executed when pressing Fn+F7 on K800.
|
# TODO: this is also executed when pressing Fn+F7 on K800.
|
||||||
old_level, self[KEYS.BATTERY_LEVEL] = self.get(KEYS.BATTERY_LEVEL), level
|
old_level, self[KEYS.BATTERY_LEVEL] = self.get(KEYS.BATTERY_LEVEL), level
|
||||||
old_status, self[KEYS.BATTERY_STATUS] = self.get(KEYS.BATTERY_STATUS), status
|
old_status, self[KEYS.BATTERY_STATUS] = self.get(KEYS.BATTERY_STATUS), status
|
||||||
|
|
||||||
charging = status in ('charging', 'recharging', 'slow recharge')
|
charging = status in ('charging', 'fully charged', 'recharging', 'slow recharge')
|
||||||
old_charging, self[KEYS.BATTERY_CHARGING] = self.get(KEYS.BATTERY_CHARGING), charging
|
old_charging, self[KEYS.BATTERY_CHARGING] = self.get(KEYS.BATTERY_CHARGING), charging
|
||||||
|
|
||||||
changed = old_level != level or old_status != status or old_charging != charging
|
changed = old_level != level or old_status != status or old_charging != charging
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue