Tellduslive: Use magic constants for battery level. Also, the previous formula for battery level was wrong. (#10788)

This commit is contained in:
Erik Eriksson 2017-11-28 15:32:36 +01:00 committed by Pascal Vizeli
parent 4e4d4365a0
commit 7ab15c0e79

View file

@ -343,8 +343,17 @@ class TelldusLiveEntity(Entity):
@property
def _battery_level(self):
"""Return the battery level of a device."""
return round(self.device.battery * 100 / 255) \
if self.device.battery else None
from tellduslive import (BATTERY_LOW,
BATTERY_UNKNOWN,
BATTERY_OK)
if self.device.battery == BATTERY_LOW:
return 1
elif self.device.battery == BATTERY_UNKNOWN:
return None
elif self.device.battery == BATTERY_OK:
return 100
else:
return self.device.battery # Percentage
@property
def _last_updated(self):