mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Adjust polling rate of Rituals Perfume Genie (#127544)
This commit is contained in:
parent
1b0f731e30
commit
ea8aa6b07d
@ -12,7 +12,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import ACCOUNT_HASH, DOMAIN
|
||||
from .const import ACCOUNT_HASH, DOMAIN, UPDATE_INTERVAL
|
||||
from .coordinator import RitualsDataUpdateCoordinator
|
||||
|
||||
PLATFORMS = [
|
||||
@ -37,9 +37,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
# Migrate old unique_ids to the new format
|
||||
async_migrate_entities_unique_ids(hass, entry, account_devices)
|
||||
|
||||
# The API provided by Rituals is currently rate limited to 30 requests
|
||||
# per hour per IP address. To avoid hitting this limit, we will adjust
|
||||
# the polling interval based on the number of diffusers one has.
|
||||
update_interval = UPDATE_INTERVAL * len(account_devices)
|
||||
|
||||
# Create a coordinator for each diffuser
|
||||
coordinators = {
|
||||
diffuser.hublot: RitualsDataUpdateCoordinator(hass, diffuser)
|
||||
diffuser.hublot: RitualsDataUpdateCoordinator(hass, diffuser, update_interval)
|
||||
for diffuser in account_devices
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ class RitualsPerfumeGenieConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
try:
|
||||
await account.authenticate()
|
||||
except ClientResponseError:
|
||||
_LOGGER.exception("Unexpected response")
|
||||
errors["base"] = "cannot_connect"
|
||||
except AuthenticationException:
|
||||
errors["base"] = "invalid_auth"
|
||||
|
@ -6,4 +6,8 @@ DOMAIN = "rituals_perfume_genie"
|
||||
|
||||
ACCOUNT_HASH = "account_hash"
|
||||
|
||||
UPDATE_INTERVAL = timedelta(minutes=2)
|
||||
# The API provided by Rituals is currently rate limited to 30 requests
|
||||
# per hour per IP address. To avoid hitting this limit, the polling
|
||||
# interval is set to 3 minutes. This also gives a little room for
|
||||
# Home Assistant restarts.
|
||||
UPDATE_INTERVAL = timedelta(minutes=3)
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""The Rituals Perfume Genie data update coordinator."""
|
||||
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from pyrituals import Diffuser
|
||||
@ -7,7 +8,7 @@ from pyrituals import Diffuser
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN, UPDATE_INTERVAL
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -15,14 +16,19 @@ _LOGGER = logging.getLogger(__name__)
|
||||
class RitualsDataUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||
"""Class to manage fetching Rituals Perfume Genie device data from single endpoint."""
|
||||
|
||||
def __init__(self, hass: HomeAssistant, diffuser: Diffuser) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
diffuser: Diffuser,
|
||||
update_interval: timedelta,
|
||||
) -> None:
|
||||
"""Initialize global Rituals Perfume Genie data updater."""
|
||||
self.diffuser = diffuser
|
||||
super().__init__(
|
||||
hass,
|
||||
_LOGGER,
|
||||
name=f"{DOMAIN}-{diffuser.hublot}",
|
||||
update_interval=UPDATE_INTERVAL,
|
||||
update_interval=update_interval,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user