mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Add scan_interval support for NUT integration (#31167)
* Added scan_interval support * Changed to config[key] for required keys and optional keys with default value * Removed usage of Throttle
This commit is contained in:
parent
e18bea0215
commit
57820be92a
@ -24,7 +24,6 @@ from homeassistant.const import (
|
|||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.util import Throttle
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -35,7 +34,7 @@ DEFAULT_PORT = 3493
|
|||||||
KEY_STATUS = "ups.status"
|
KEY_STATUS = "ups.status"
|
||||||
KEY_STATUS_DISPLAY = "ups.status.display"
|
KEY_STATUS_DISPLAY = "ups.status.display"
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=60)
|
SCAN_INTERVAL = timedelta(seconds=60)
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
"ups.status.display": ["Status", "", "mdi:information-outline"],
|
"ups.status.display": ["Status", "", "mdi:information-outline"],
|
||||||
@ -166,9 +165,10 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
"""Set up the NUT sensors."""
|
"""Set up the NUT sensors."""
|
||||||
name = config.get(CONF_NAME)
|
name = config[CONF_NAME]
|
||||||
host = config.get(CONF_HOST)
|
host = config[CONF_HOST]
|
||||||
port = config.get(CONF_PORT)
|
port = config[CONF_PORT]
|
||||||
|
|
||||||
alias = config.get(CONF_ALIAS)
|
alias = config.get(CONF_ALIAS)
|
||||||
username = config.get(CONF_USERNAME)
|
username = config.get(CONF_USERNAME)
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
@ -325,7 +325,6 @@ class PyNUTData:
|
|||||||
_LOGGER.debug("Error getting NUT vars for host %s: %s", self._host, err)
|
_LOGGER.debug("Error getting NUT vars for host %s: %s", self._host, err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
"""Fetch the latest status from NUT."""
|
"""Fetch the latest status from NUT."""
|
||||||
self._status = self._get_status()
|
self._status = self._get_status()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user