Skip to content

Commit

Permalink
Fix iCloud device battery level can be None (#31468)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentame authored and frenck committed Feb 5, 2020
1 parent 6d79898 commit 2d393b8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions homeassistant/components/icloud/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,13 @@ def update(self, status) -> None:
device_status = DEVICE_STATUS_CODES.get(self._status[DEVICE_STATUS], "error")
self._attrs[ATTR_DEVICE_STATUS] = device_status

if self._status[DEVICE_BATTERY_STATUS] != "Unknown":
self._battery_level = int(self._status.get(DEVICE_BATTERY_LEVEL, 0) * 100)
self._battery_status = self._status[DEVICE_BATTERY_STATUS]
low_power_mode = self._status[DEVICE_LOW_POWER_MODE]

self._battery_status = self._status[DEVICE_BATTERY_STATUS]
self._attrs[ATTR_BATTERY_STATUS] = self._battery_status
device_battery_level = self._status.get(DEVICE_BATTERY_LEVEL, 0)
if self._battery_status != "Unknown" and device_battery_level is not None:
self._battery_level = int(device_battery_level * 100)
self._attrs[ATTR_BATTERY] = self._battery_level
self._attrs[ATTR_BATTERY_STATUS] = self._battery_status
self._attrs[ATTR_LOW_POWER_MODE] = low_power_mode
self._attrs[ATTR_LOW_POWER_MODE] = self._status[DEVICE_LOW_POWER_MODE]

if (
self._status[DEVICE_LOCATION]
Expand Down

0 comments on commit 2d393b8

Please sign in to comment.