Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrape scan interval #81763

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions homeassistant/components/scrape/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
CONF_NAME,
CONF_PASSWORD,
CONF_RESOURCE,
CONF_SCAN_INTERVAL,
CONF_UNIQUE_ID,
CONF_UNIT_OF_MEASUREMENT,
CONF_USERNAME,
Expand All @@ -43,7 +44,7 @@

_LOGGER = logging.getLogger(__name__)

SCAN_INTERVAL = timedelta(minutes=10)
DEFAULT_SCAN_INTERVAL = timedelta(minutes=10)

CONF_ATTR = "attribute"
CONF_SELECT = "select"
Expand Down Expand Up @@ -111,7 +112,8 @@ async def async_setup_platform(

rest = RestData(hass, method, resource, auth, headers, None, payload, verify_ssl)

coordinator = ScrapeCoordinator(hass, rest, SCAN_INTERVAL)
scan_interval: timedelta = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
coordinator = ScrapeCoordinator(hass, rest, scan_interval)
await coordinator.async_refresh()
if coordinator.data is None:
raise PlatformNotReady
Expand Down
4 changes: 2 additions & 2 deletions tests/components/scrape/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from unittest.mock import patch

from homeassistant.components.scrape.sensor import SCAN_INTERVAL
from homeassistant.components.scrape.sensor import DEFAULT_SCAN_INTERVAL
from homeassistant.components.sensor import (
CONF_STATE_CLASS,
SensorDeviceClass,
Expand Down Expand Up @@ -189,7 +189,7 @@ async def test_scrape_sensor_no_data_refresh(hass: HomeAssistant) -> None:
assert state.state == "Current Version: 2021.12.10"

mocker.payload = "test_scrape_sensor_no_data"
async_fire_time_changed(hass, datetime.utcnow() + SCAN_INTERVAL)
async_fire_time_changed(hass, datetime.utcnow() + DEFAULT_SCAN_INTERVAL)
await hass.async_block_till_done()

state = hass.states.get("sensor.ha_version")
Expand Down