mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Increase update timeouts used in Shelly integration (#42937)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
46412ef0c6
commit
8b998365a4
@ -23,7 +23,14 @@ from homeassistant.helpers import (
|
|||||||
update_coordinator,
|
update_coordinator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import DATA_CONFIG_ENTRY, DOMAIN
|
from .const import (
|
||||||
|
DATA_CONFIG_ENTRY,
|
||||||
|
DOMAIN,
|
||||||
|
POLLING_TIMEOUT_MULTIPLIER,
|
||||||
|
SETUP_ENTRY_TIMEOUT_SEC,
|
||||||
|
SLEEP_PERIOD_MULTIPLIER,
|
||||||
|
UPDATE_PERIOD_MULTIPLIER,
|
||||||
|
)
|
||||||
|
|
||||||
PLATFORMS = ["binary_sensor", "cover", "light", "sensor", "switch"]
|
PLATFORMS = ["binary_sensor", "cover", "light", "sensor", "switch"]
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -66,7 +73,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
coap_context = await get_coap_context(hass)
|
coap_context = await get_coap_context(hass)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(5):
|
async with async_timeout.timeout(SETUP_ENTRY_TIMEOUT_SEC):
|
||||||
device = await aioshelly.Device.create(
|
device = await aioshelly.Device.create(
|
||||||
aiohttp_client.async_get_clientsession(hass),
|
aiohttp_client.async_get_clientsession(hass),
|
||||||
coap_context,
|
coap_context,
|
||||||
@ -100,9 +107,13 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
if sleep_mode["unit"] == "h":
|
if sleep_mode["unit"] == "h":
|
||||||
sleep_period *= 60 # hours to minutes
|
sleep_period *= 60 # hours to minutes
|
||||||
|
|
||||||
update_interval = 1.2 * sleep_period * 60 # minutes to seconds
|
update_interval = (
|
||||||
|
SLEEP_PERIOD_MULTIPLIER * sleep_period * 60
|
||||||
|
) # minutes to seconds
|
||||||
else:
|
else:
|
||||||
update_interval = 2 * device.settings["coiot"]["update_period"]
|
update_interval = (
|
||||||
|
UPDATE_PERIOD_MULTIPLIER * device.settings["coiot"]["update_period"]
|
||||||
|
)
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
@ -118,8 +129,12 @@ class ShellyDeviceWrapper(update_coordinator.DataUpdateCoordinator):
|
|||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self):
|
||||||
"""Fetch data."""
|
"""Fetch data."""
|
||||||
|
_LOGGER.debug("Polling Shelly Device - %s", self.name)
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(5):
|
async with async_timeout.timeout(
|
||||||
|
POLLING_TIMEOUT_MULTIPLIER
|
||||||
|
* self.device.settings["coiot"]["update_period"]
|
||||||
|
):
|
||||||
return await self.device.update()
|
return await self.device.update()
|
||||||
except OSError as err:
|
except OSError as err:
|
||||||
raise update_coordinator.UpdateFailed("Error fetching data") from err
|
raise update_coordinator.UpdateFailed("Error fetching data") from err
|
||||||
|
@ -2,3 +2,15 @@
|
|||||||
|
|
||||||
DATA_CONFIG_ENTRY = "config_entry"
|
DATA_CONFIG_ENTRY = "config_entry"
|
||||||
DOMAIN = "shelly"
|
DOMAIN = "shelly"
|
||||||
|
|
||||||
|
# Used to calculate the timeout in "_async_update_data" used for polling data from devices.
|
||||||
|
POLLING_TIMEOUT_MULTIPLIER = 1.2
|
||||||
|
|
||||||
|
# Timeout used for initial entry setup in "async_setup_entry".
|
||||||
|
SETUP_ENTRY_TIMEOUT_SEC = 10
|
||||||
|
|
||||||
|
# Multiplier used to calculate the "update_interval" for sleeping devices.
|
||||||
|
SLEEP_PERIOD_MULTIPLIER = 1.2
|
||||||
|
|
||||||
|
# Multiplier used to calculate the "update_interval" for non-sleeping devices.
|
||||||
|
UPDATE_PERIOD_MULTIPLIER = 2.2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user