Throttle ebusd sensors instead of the whole component (#40610)

This commit is contained in:
Daniel Kucera 2020-09-26 09:11:32 +02:00 committed by GitHub
parent 9cd8f66e14
commit 6ddc6a44a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View File

@ -1,5 +1,4 @@
"""Support for Ebusd daemon for communication with eBUS heating systems.""" """Support for Ebusd daemon for communication with eBUS heating systems."""
from datetime import timedelta
import logging import logging
import socket import socket
@ -14,7 +13,6 @@ from homeassistant.const import (
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.discovery import load_platform
from homeassistant.util import Throttle
from .const import DOMAIN, SENSOR_TYPES from .const import DOMAIN, SENSOR_TYPES
@ -26,8 +24,6 @@ CONF_CIRCUIT = "circuit"
CACHE_TTL = 900 CACHE_TTL = 900
SERVICE_EBUSD_WRITE = "ebusd_write" SERVICE_EBUSD_WRITE = "ebusd_write"
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=15)
def verify_ebusd_config(config): def verify_ebusd_config(config):
"""Verify eBusd config.""" """Verify eBusd config."""
@ -59,6 +55,7 @@ CONFIG_SCHEMA = vol.Schema(
def setup(hass, config): def setup(hass, config):
"""Set up the eBusd component.""" """Set up the eBusd component."""
_LOGGER.debug("Integration setup started")
conf = config[DOMAIN] conf = config[DOMAIN]
name = conf[CONF_NAME] name = conf[CONF_NAME]
circuit = conf[CONF_CIRCUIT] circuit = conf[CONF_CIRCUIT]
@ -66,7 +63,6 @@ def setup(hass, config):
server_address = (conf.get(CONF_HOST), conf.get(CONF_PORT)) server_address = (conf.get(CONF_HOST), conf.get(CONF_PORT))
try: try:
_LOGGER.debug("Ebusd integration setup started")
ebusdpy.init(server_address) ebusdpy.init(server_address)
hass.data[DOMAIN] = EbusdData(server_address, circuit) hass.data[DOMAIN] = EbusdData(server_address, circuit)
@ -95,7 +91,6 @@ class EbusdData:
self._address = address self._address = address
self.value = {} self.value = {}
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self, name, stype): def update(self, name, stype):
"""Call the Ebusd API to update the data.""" """Call the Ebusd API to update the data."""
try: try:

View File

@ -3,6 +3,7 @@ import datetime
import logging import logging
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from .const import DOMAIN from .const import DOMAIN
@ -13,6 +14,7 @@ TIME_FRAME2_BEGIN = "time_frame2_begin"
TIME_FRAME2_END = "time_frame2_end" TIME_FRAME2_END = "time_frame2_end"
TIME_FRAME3_BEGIN = "time_frame3_begin" TIME_FRAME3_BEGIN = "time_frame3_begin"
TIME_FRAME3_END = "time_frame3_end" TIME_FRAME3_END = "time_frame3_end"
MIN_TIME_BETWEEN_UPDATES = datetime.timedelta(seconds=15)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -85,6 +87,7 @@ class EbusdSensor(Entity):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return self._unit_of_measurement return self._unit_of_measurement
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
"""Fetch new state data for the sensor.""" """Fetch new state data for the sensor."""
try: try: