Make read_battery use set_battery_info
This allows battery readouts to generate warnings and debug logs for a given status and level.
This commit is contained in:
parent
fbdd923d43
commit
d1b1be32ca
|
@ -125,7 +125,7 @@ class DeviceStatus(dict):
|
||||||
return bool(self._active)
|
return bool(self._active)
|
||||||
__nonzero__ = __bool__
|
__nonzero__ = __bool__
|
||||||
|
|
||||||
def set_battery_info(self, level, status):
|
def set_battery_info(self, level, status, timestamp=None):
|
||||||
self[BATTERY_LEVEL] = level
|
self[BATTERY_LEVEL] = level
|
||||||
self[BATTERY_STATUS] = status
|
self[BATTERY_STATUS] = status
|
||||||
error = None
|
error = None
|
||||||
|
@ -141,7 +141,7 @@ class DeviceStatus(dict):
|
||||||
if error is not None:
|
if error is not None:
|
||||||
# TODO: show visual warning/notif to user
|
# TODO: show visual warning/notif to user
|
||||||
self[ERROR] = error
|
self[ERROR] = error
|
||||||
self._changed(alert=alert, reason=error)
|
self._changed(alert=alert, reason=error, timestamp=timestamp)
|
||||||
|
|
||||||
def read_battery(self, timestamp=None):
|
def read_battery(self, timestamp=None):
|
||||||
d = self._device
|
d = self._device
|
||||||
|
@ -157,8 +157,8 @@ class DeviceStatus(dict):
|
||||||
# return
|
# return
|
||||||
|
|
||||||
if battery:
|
if battery:
|
||||||
self[BATTERY_LEVEL], self[BATTERY_STATUS] = battery
|
level, status = battery
|
||||||
self._changed(timestamp=timestamp)
|
self.set_battery_info(level, status, timestamp=timestamp)
|
||||||
elif BATTERY_STATUS in self:
|
elif BATTERY_STATUS in self:
|
||||||
self[BATTERY_STATUS] = None
|
self[BATTERY_STATUS] = None
|
||||||
self._changed(timestamp=timestamp)
|
self._changed(timestamp=timestamp)
|
||||||
|
|
Loading…
Reference in New Issue