Merge pull request #48 from theolind/dev

Added process watching functionality to sensor.systemmonitor
This commit is contained in:
Theodor Lindquist 2015-03-08 08:45:17 +01:00
commit e6ed2e58b0
3 changed files with 11 additions and 3 deletions

View File

@ -118,4 +118,5 @@ sensor:
- type: 'memory_use'
- type: 'memory_free'
- type: 'processor_use'
- type: 'unknown sensor type'
- type: 'process'
arg: 'octave-cli'

View File

@ -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

View File

@ -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