mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
commit
26fcb9395e
@ -113,7 +113,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"Unable to import blockchain. "
|
"Unable to import blockchain. "
|
||||||
"Did you maybe not install the 'blockchain' package?")
|
"Did you maybe not install the 'blockchain' package?")
|
||||||
|
|
||||||
return None
|
return False
|
||||||
|
|
||||||
wallet_id = config.get('wallet', None)
|
wallet_id = config.get('wallet', None)
|
||||||
password = config.get('password', None)
|
password = config.get('password', None)
|
||||||
|
@ -81,7 +81,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
"Unable to import pyowm. "
|
"Unable to import pyowm. "
|
||||||
"Did you maybe not install the 'PyOWM' package?")
|
"Did you maybe not install the 'PyOWM' package?")
|
||||||
|
|
||||||
return None
|
return False
|
||||||
|
|
||||||
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
|
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
|
||||||
unit = hass.config.temperature_unit
|
unit = hass.config.temperature_unit
|
||||||
|
@ -21,9 +21,26 @@ sensor:
|
|||||||
- type: 'memory_use_percent'
|
- type: 'memory_use_percent'
|
||||||
- type: 'memory_use'
|
- type: 'memory_use'
|
||||||
- type: 'memory_free'
|
- 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: 'processor_use'
|
||||||
- type: 'process'
|
- type: 'process'
|
||||||
arg: 'octave-cli'
|
arg: 'octave-cli'
|
||||||
|
- type: 'last_boot'
|
||||||
|
- type: 'since_last_boot'
|
||||||
|
|
||||||
Variables:
|
Variables:
|
||||||
|
|
||||||
@ -42,12 +59,12 @@ arg
|
|||||||
*Optional
|
*Optional
|
||||||
Additional details for the type, eg. path, binary name, etc.
|
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.helpers.entity import Entity
|
||||||
from homeassistant.const import STATE_ON, STATE_OFF
|
from homeassistant.const import STATE_ON, STATE_OFF
|
||||||
import psutil
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
'disk_use_percent': ['Disk Use', '%'],
|
'disk_use_percent': ['Disk Use', '%'],
|
||||||
@ -58,6 +75,17 @@ SENSOR_TYPES = {
|
|||||||
'memory_free': ['RAM Free', 'MiB'],
|
'memory_free': ['RAM Free', 'MiB'],
|
||||||
'processor_use': ['CPU Use', '%'],
|
'processor_use': ['CPU Use', '%'],
|
||||||
'process': ['Process', ''],
|
'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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -103,6 +131,7 @@ class SystemMonitorSensor(Entity):
|
|||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
|
# pylint: disable=too-many-branches
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.type == 'disk_use_percent':
|
if self.type == 'disk_use_percent':
|
||||||
self._state = psutil.disk_usage(self.argument).percent
|
self._state = psutil.disk_usage(self.argument).percent
|
||||||
@ -120,6 +149,12 @@ class SystemMonitorSensor(Entity):
|
|||||||
1024**2, 1)
|
1024**2, 1)
|
||||||
elif self.type == 'memory_free':
|
elif self.type == 'memory_free':
|
||||||
self._state = round(psutil.virtual_memory().available / 1024**2, 1)
|
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':
|
elif self.type == 'processor_use':
|
||||||
self._state = round(psutil.cpu_percent(interval=None))
|
self._state = round(psutil.cpu_percent(interval=None))
|
||||||
elif self.type == 'process':
|
elif self.type == 'process':
|
||||||
@ -127,3 +162,24 @@ class SystemMonitorSensor(Entity):
|
|||||||
self._state = STATE_ON
|
self._state = STATE_ON
|
||||||
else:
|
else:
|
||||||
self._state = STATE_OFF
|
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())
|
||||||
|
@ -42,7 +42,7 @@ pydispatcher>=2.0.5
|
|||||||
PyISY>=1.0.2
|
PyISY>=1.0.2
|
||||||
|
|
||||||
# PSutil (sensor.systemmonitor)
|
# PSutil (sensor.systemmonitor)
|
||||||
psutil>=2.2.1
|
psutil>=3.0.0
|
||||||
|
|
||||||
# Pushover bindings (notify.pushover)
|
# Pushover bindings (notify.pushover)
|
||||||
python-pushover>=0.2
|
python-pushover>=0.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user