Report swap in MiB (#13148)

It makes sense to report swap and memory in the same unit and MiB is
more useful considering Home Assistant may be running on lower end
hardware (Raspberry Pi for example) where 100MiB resolution is not
adequate.
pull/11000/merge
Dan Nixon 2018-03-14 07:47:45 +00:00 committed by Fabian Affolter
parent 948f29544a
commit b6bed1dfab
1 changed files with 4 additions and 4 deletions

View File

@ -42,8 +42,8 @@ SENSOR_TYPES = {
'process': ['Process', ' ', 'mdi:memory'],
'processor_use': ['Processor use', '%', 'mdi:memory'],
'since_last_boot': ['Since last boot', '', 'mdi:clock'],
'swap_free': ['Swap free', 'GiB', 'mdi:harddisk'],
'swap_use': ['Swap use', 'GiB', 'mdi:harddisk'],
'swap_free': ['Swap free', 'MiB', 'mdi:harddisk'],
'swap_use': ['Swap use', 'MiB', 'mdi:harddisk'],
'swap_use_percent': ['Swap use (percent)', '%', 'mdi:harddisk'],
}
@ -135,9 +135,9 @@ class SystemMonitorSensor(Entity):
elif self.type == 'swap_use_percent':
self._state = psutil.swap_memory().percent
elif self.type == 'swap_use':
self._state = round(psutil.swap_memory().used / 1024**3, 1)
self._state = round(psutil.swap_memory().used / 1024**2, 1)
elif self.type == 'swap_free':
self._state = round(psutil.swap_memory().free / 1024**3, 1)
self._state = round(psutil.swap_memory().free / 1024**2, 1)
elif self.type == 'processor_use':
self._state = round(psutil.cpu_percent(interval=None))
elif self.type == 'process':