Skip to content

Commit

Permalink
Merge pull request #9 from tiagofreire-pt/patch-3
Browse files Browse the repository at this point in the history
Define scan configuration parameter for variable time between executions
  • Loading branch information
jchasey authored Jun 4, 2021
2 parents 7853675 + 92f94c3 commit edb713a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions custom_components/ssh/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
vol.Required(CONF_COMMAND): cv.string,
vol.Required(CONF_UNIT_OF_MEASUREMENT): cv.string,
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
vol.Optional(CONF_SCAN, default=MIN_TIME_BETWEEN_UPDATES): cv.string,
})

@asyncio.coroutine
Expand All @@ -61,6 +62,7 @@ def __init__(self, hass, config):
self._command = config.get(CONF_COMMAND)
self._value_template = config.get(CONF_VALUE_TEMPLATE)
self._unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
self._scan = config.get(CONF_SCAN)
self._ssh = None
self._connected = False
self._connect()
Expand Down Expand Up @@ -94,7 +96,12 @@ def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement

@Throttle(MIN_TIME_BETWEEN_UPDATES)
@property
def scan(self):
"""Return the period between executions, if any."""
return self._scan

@Throttle(self._scan)
def update(self):
from pexpect import pxssh, exceptions

Expand Down Expand Up @@ -128,7 +135,7 @@ def update(self):
return None

def _connect(self):
"""Connect to the Unifi AP SSH server."""
"""Connect to the SSH server."""
from pexpect import pxssh, exceptions

self._ssh = pxssh.pxssh()
Expand Down

0 comments on commit edb713a

Please sign in to comment.