mirror of https://github.com/home-assistant/core
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:
parent
45e140149b
commit
2a2a106e62
|
@ -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']
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue