Skip to content

Commit 92f94c3

Browse files
Define scan configuration parameter for variable time between executions
YAML configuration: ``` sensor: - platform: ssh host: !secret proxmox_host name: 'NUC CPU Temp' username: !secret proxmox_user password: !secret proxmox_pass command: "sensors | grep 'Package id 0:' | cut -c17-20" value_template: >- {%- set line = value.split("\r\n") -%} {{ line[1] }} unit_of_measurement: "ºC" # Time between executions, in seconds scan: '900' ```
1 parent df82126 commit 92f94c3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

custom_components/ssh/sensor.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
vol.Required(CONF_COMMAND): cv.string,
4040
vol.Required(CONF_UNIT_OF_MEASUREMENT): cv.string,
4141
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
42+
vol.Optional(CONF_SCAN, default=MIN_TIME_BETWEEN_UPDATES): cv.string,
4243
})
4344

4445
@asyncio.coroutine
@@ -61,6 +62,7 @@ def __init__(self, hass, config):
6162
self._command = config.get(CONF_COMMAND)
6263
self._value_template = config.get(CONF_VALUE_TEMPLATE)
6364
self._unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
65+
self._scan = config.get(CONF_SCAN)
6466
self._ssh = None
6567
self._connected = False
6668
self._connect()
@@ -94,7 +96,12 @@ def unit_of_measurement(self):
9496
"""Return the unit of measurement of this entity, if any."""
9597
return self._unit_of_measurement
9698

97-
@Throttle(MIN_TIME_BETWEEN_UPDATES)
99+
@property
100+
def scan(self):
101+
"""Return the period between executions, if any."""
102+
return self._scan
103+
104+
@Throttle(self._scan)
98105
def update(self):
99106
from pexpect import pxssh, exceptions
100107

@@ -128,7 +135,7 @@ def update(self):
128135
return None
129136

130137
def _connect(self):
131-
"""Connect to the Unifi AP SSH server."""
138+
"""Connect to the SSH server."""
132139
from pexpect import pxssh, exceptions
133140

134141
self._ssh = pxssh.pxssh()

0 commit comments

Comments
 (0)