Fix Sonarr and Radarr divide by zero (#10101)

* Fix Sonarr and Radarr divide by zero

* Fixes for hound

* Clean up Radarr diskspace
This commit is contained in:
Trevor 2017-10-25 04:37:08 -05:00 committed by Pascal Vizeli
parent 45e140149b
commit 2a2a106e62
2 changed files with 8 additions and 8 deletions

View File

@ -133,14 +133,12 @@ class RadarrSensor(Entity):
attributes[command['name']] = command['state']
elif self.type == 'diskspace':
for data in self.data:
free_space = to_unit(data['freeSpace'], self._unit)
total_space = to_unit(data['totalSpace'], self._unit)
percentage_used = (0 if total_space == 0
else free_space / total_space * 100)
attributes[data['path']] = '{:.2f}/{:.2f}{} ({:.2f}%)'.format(
to_unit(data['freeSpace'], self._unit),
to_unit(data['totalSpace'], self._unit),
self._unit, (
to_unit(data['freeSpace'], self._unit) /
to_unit(data['totalSpace'], self._unit) * 100
)
)
free_space, total_space, self._unit, percentage_used)
elif self.type == 'movies':
for movie in self.data:
attributes[to_key(movie)] = movie['downloaded']

View File

@ -132,10 +132,12 @@ class SonarrSensor(Entity):
show['seasonNumber'], show['episodeNumber'])
elif self.type == 'queue':
for show in self.data:
remaining = (1 if show['size'] == 0
else show['sizeleft']/show['size'])
attributes[show['series']['title'] + ' S{:02d}E{:02d}'.format(
show['episode']['seasonNumber'],
show['episode']['episodeNumber']
)] = '{:.2f}%'.format(100*(1-(show['sizeleft']/show['size'])))
)] = '{:.2f}%'.format(100*(1-(remaining)))
elif self.type == 'wanted':
for show in self.data:
attributes[show['series']['title'] + ' S{:02d}E{:02d}'.format(