From 91b611acb775c89719986cb24cbf3373c8d36185 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 22:36:54 +0200 Subject: [PATCH 1/6] fix return value --- homeassistant/components/sensor/openweathermap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/openweathermap.py b/homeassistant/components/sensor/openweathermap.py index dbbd23322c0..9601dea1aed 100644 --- a/homeassistant/components/sensor/openweathermap.py +++ b/homeassistant/components/sensor/openweathermap.py @@ -81,7 +81,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Unable to import pyowm. " "Did you maybe not install the 'PyOWM' package?") - return None + return False SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit unit = hass.config.temperature_unit From 9b4b76d36458a06f0767191a669bf8aed12f4650 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 22:37:19 +0200 Subject: [PATCH 2/6] fix return value --- homeassistant/components/sensor/bitcoin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/sensor/bitcoin.py b/homeassistant/components/sensor/bitcoin.py index 8d174981900..bc29198e6a0 100644 --- a/homeassistant/components/sensor/bitcoin.py +++ b/homeassistant/components/sensor/bitcoin.py @@ -113,7 +113,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): "Unable to import blockchain. " "Did you maybe not install the 'blockchain' package?") - return None + return False wallet_id = config.get('wallet', None) password = config.get('password', None) From 88923a8b18cd8f31730fefb3ac9c82be774192f0 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 22:44:53 +0200 Subject: [PATCH 3/6] update psutil to 3.0.0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index bebc21b3464..13d5551b172 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,7 +42,7 @@ pydispatcher>=2.0.5 PyISY>=1.0.2 # PSutil (sensor.systemmonitor) -psutil>=2.2.1 +psutil>=3.0.0 # Pushover bindings (notify.pushover) python-pushover>=0.2 From 05b70825fab2fd71574aa8014d435b4124a232ff Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 23:42:11 +0200 Subject: [PATCH 4/6] add a couple of new resources --- .../components/sensor/systemmonitor.py | 60 ++++++++++++++++++- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 0f9d570f92a..9df27448697 100644 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -21,9 +21,25 @@ sensor: - type: 'memory_use_percent' - type: 'memory_use' - type: 'memory_free' + - type: 'swap_use_percent' + - type: 'swap_use' + - type: 'swap_free' + - type: 'network_in' + arg: 'eth0' + - type: 'network_out' + arg: 'eth0' + - type: 'packets_in' + arg: 'eth0' + - type: 'packets_out' + arg: 'eth0' + - type: 'ipv4_address' + arg: 'eth0' + - type: 'ipv6_address' + arg: 'eth0' - type: 'processor_use' - type: 'process' arg: 'octave-cli' + - type: 'last_boot' Variables: @@ -42,12 +58,12 @@ arg *Optional Additional details for the type, eg. path, binary name, etc. """ +import logging +import psutil +import homeassistant.util.dt as dt_util from homeassistant.helpers.entity import Entity from homeassistant.const import STATE_ON, STATE_OFF -import psutil -import logging - SENSOR_TYPES = { 'disk_use_percent': ['Disk Use', '%'], @@ -58,6 +74,17 @@ SENSOR_TYPES = { 'memory_free': ['RAM Free', 'MiB'], 'processor_use': ['CPU Use', '%'], 'process': ['Process', ''], + 'swap_use_percent': ['Swap Use', '%'], + 'swap_use': ['Swap Use', 'GiB'], + 'swap_free': ['Swap Free', 'GiB'], + 'network_out': ['Sent', 'MiB'], + 'network_in': ['Recieved', 'MiB'], + 'packets_out': ['Packets sent', ''], + 'packets_in': ['Packets recieved', ''], + 'ipv4_address': ['IPv4 address', ''], + 'ipv6_address': ['IPv6 address', ''], + 'last_boot': ['Last Boot', ''], + 'since_last_boot': ['Since Last Boot', ''] } _LOGGER = logging.getLogger(__name__) @@ -120,6 +147,12 @@ class SystemMonitorSensor(Entity): 1024**2, 1) elif self.type == 'memory_free': self._state = round(psutil.virtual_memory().available / 1024**2, 1) + 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) + elif self.type == 'swap_free': + self._state = round(psutil.swap_memory().free / 1024**3, 1) elif self.type == 'processor_use': self._state = round(psutil.cpu_percent(interval=None)) elif self.type == 'process': @@ -127,3 +160,24 @@ class SystemMonitorSensor(Entity): self._state = STATE_ON else: self._state = STATE_OFF + elif self.type == 'network_out': + self._state = round(psutil.net_io_counters(pernic=True) + [self.argument][0] / 1024**2, 1) + elif self.type == 'network_in': + self._state = round(psutil.net_io_counters(pernic=True) + [self.argument][1] / 1024**2, 1) + elif self.type == 'packets_out': + self._state = psutil.net_io_counters(pernic=True)[self.argument][2] + elif self.type == 'packets_in': + self._state = psutil.net_io_counters(pernic=True)[self.argument][3] + elif self.type == 'ipv4_address': + self._state = psutil.net_if_addrs()[self.argument][0][1] + elif self.type == 'ipv6_address': + self._state = psutil.net_if_addrs()[self.argument][1][1] + elif self.type == 'last_boot': + self._state = dt_util.datetime_to_date_str( + dt_util.as_local( + dt_util.utc_from_timestamp(psutil.boot_time()))) + elif self.type == 'since_last_boot': + self._state = dt_util.utcnow() - dt_util.utc_from_timestamp( + psutil.boot_time()) From cb35363e10b85d57cc2adcd2e2e0ee08e6e3f80a Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 23:46:48 +0200 Subject: [PATCH 5/6] add missing resource --- homeassistant/components/sensor/systemmonitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 9df27448697..1125b72f660 100644 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -40,6 +40,7 @@ sensor: - type: 'process' arg: 'octave-cli' - type: 'last_boot' + - type: 'since_last_boot' Variables: From cdb1677b5941dd48afed2dd5b0226b2335c0a28f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 17 Jun 2015 23:58:14 +0200 Subject: [PATCH 6/6] fix pylint issue --- homeassistant/components/sensor/systemmonitor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/sensor/systemmonitor.py b/homeassistant/components/sensor/systemmonitor.py index 1125b72f660..2615ab1a77b 100644 --- a/homeassistant/components/sensor/systemmonitor.py +++ b/homeassistant/components/sensor/systemmonitor.py @@ -131,6 +131,7 @@ class SystemMonitorSensor(Entity): def unit_of_measurement(self): return self._unit_of_measurement + # pylint: disable=too-many-branches def update(self): if self.type == 'disk_use_percent': self._state = psutil.disk_usage(self.argument).percent