mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Merge pull request #48 from theolind/dev
Added process watching functionality to sensor.systemmonitor
This commit is contained in:
commit
e6ed2e58b0
@ -118,4 +118,5 @@ sensor:
|
||||
- type: 'memory_use'
|
||||
- type: 'memory_free'
|
||||
- type: 'processor_use'
|
||||
- type: 'unknown sensor type'
|
||||
- type: 'process'
|
||||
arg: 'octave-cli'
|
@ -111,7 +111,7 @@ def setup(hass, config=None):
|
||||
if config is None or DOMAIN not in config:
|
||||
config = {DOMAIN: {}}
|
||||
|
||||
api_password = config[DOMAIN].get(CONF_API_PASSWORD)
|
||||
api_password = str(config[DOMAIN].get(CONF_API_PASSWORD))
|
||||
|
||||
no_password_set = api_password is None
|
||||
|
||||
|
@ -8,10 +8,11 @@ Shows system monitor values such as: disk, memory and processor use
|
||||
|
||||
from homeassistant.helpers.device import Device
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT, ATTR_FRIENDLY_NAME)
|
||||
ATTR_UNIT_OF_MEASUREMENT, ATTR_FRIENDLY_NAME, STATE_ON, STATE_OFF)
|
||||
import psutil
|
||||
import logging
|
||||
|
||||
|
||||
SENSOR_TYPES = {
|
||||
'disk_use_percent': ['Disk Use', '%'],
|
||||
'disk_use': ['Disk Use', 'GiB'],
|
||||
@ -20,6 +21,7 @@ SENSOR_TYPES = {
|
||||
'memory_use': ['RAM Use', 'MiB'],
|
||||
'memory_free': ['RAM Free', 'MiB'],
|
||||
'processor_use': ['CPU Use', '%'],
|
||||
'process': ['Process', ''],
|
||||
}
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -88,3 +90,8 @@ class SystemMonitorSensor(Device):
|
||||
self._state = round(psutil.virtual_memory().available / 1024**2, 1)
|
||||
elif self.type == 'processor_use':
|
||||
self._state = round(psutil.cpu_percent(interval=None))
|
||||
elif self.type == 'process':
|
||||
if any(self.argument in l.name() for l in psutil.process_iter()):
|
||||
self._state = STATE_ON
|
||||
else:
|
||||
self._state = STATE_OFF
|
||||
|
Loading…
x
Reference in New Issue
Block a user