Skip to content

Commit

Permalink
Use SCAN_INTERVAL instead of Throttle decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
mweinelt committed Jun 11, 2024
1 parent 5595098 commit 8476cdc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ Contributions welcome!

Tested against Home Asisstant 2024.5.5.

## Todos

- Migrate to `DataUpdateCoordinator` (https://developers.home-assistant.io/docs/integration_fetching_data/)

## Example usage

```yaml
Expand Down
6 changes: 3 additions & 3 deletions custom_components/prometheus_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
)
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import Throttle

_LOGGER: Final = logging.getLogger(__name__)

# Match the default scrape_interval in Prometheus
SCAN_INTERVAL: Final = timedelta(seconds=15)

DEFAULT_URL: Final = "http://localhost:9090"
CONF_QUERIES: Final = "queries"
CONF_EXPR: Final = "expr"
CONF_STATE_CLASS: Final = "state_class"
MIN_TIME_BETWEEN_UPDATES: Final = timedelta(seconds=60)

_QUERY_SCHEMA: Final = vol.Schema(
{
Expand Down Expand Up @@ -153,7 +154,6 @@ def __init__(
self._attr_state_class = state_class
self._attr_unique_id = unique_id

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self) -> None:
"""Update state by executing query."""
result = await self._prometheus.query(self._expression)
Expand Down

0 comments on commit 8476cdc

Please sign in to comment.