Skip to content

Commit

Permalink
Use stack for pending snapshots. Clean error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jan 4, 2020
1 parent e3571ca commit 1b9951b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions custom_components/auto_backup/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def new_snapshot(self, data, full=False):
)

# add to pending snapshots and update sensor.
self._pending_snapshots = 1
self._pending_snapshots += 1
if self.update_sensor_callback:
self.update_sensor_callback()

Expand All @@ -294,9 +294,10 @@ async def new_snapshot(self, data, full=False):

slug = result.get("data", {}).get("slug")
if slug is None:
raise HassioAPIError(
f"There may be a backup already in progress: {data.get('message')}"
)
error = "There may be a backup already in progress."
if data.get("message"):
error = f"{error} {data.get('message')}"
raise HassioAPIError(error)

# snapshot creation was successful
_LOGGER.info(
Expand Down Expand Up @@ -344,7 +345,7 @@ async def new_snapshot(self, data, full=False):
self.last_failure = data[ATTR_NAME]

# remove from pending snapshots and update sensor.
self._pending_snapshots = 0
self._pending_snapshots -= 1
if self.update_sensor_callback:
self.update_sensor_callback()

Expand Down

0 comments on commit 1b9951b

Please sign in to comment.