Skip to content

Commit eb90213

Browse files
committed
fix: faster connection retries
The connection error sometimes happen, so try to recover from it faster and with more retries.
1 parent 66fed0b commit eb90213

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

custom_components/proteus_api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from homeassistant.core import HomeAssistant
1111
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
1212

13-
from .const import DOMAIN
13+
from .const import DOMAIN, UPDATE_INTERVAL
1414
from .proteus_api import ProteusAPI
1515

1616
_LOGGER = logging.getLogger(__name__)
@@ -31,7 +31,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3131
_LOGGER,
3232
name="proteus_api",
3333
update_method=api.get_data,
34-
update_interval=timedelta(seconds=30),
34+
update_interval=timedelta(seconds=UPDATE_INTERVAL),
3535
)
3636

3737
await coordinator.async_config_entry_first_refresh()

custom_components/proteus_api/const.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@
2323
# States
2424
CONTROL_STATES = ["DISABLED", "ENABLED"]
2525
CONTROL_MODES = ["AUTOMATIC", "MANUAL"]
26+
27+
UPDATE_INTERVAL = 30

custom_components/proteus_api/proteus_api.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
API_FLEXIBILITY_ENDPOINT,
2121
API_LOGIN_ENDPOINT,
2222
API_MODE_ENDPOINT,
23+
UPDATE_INTERVAL,
2324
)
2425

2526
_LOGGER = logging.getLogger(__name__)
@@ -79,7 +80,10 @@ async def _get_session(self) -> aiohttp.ClientSession:
7980
async def _get_client(self) -> RetryClient:
8081
session = await self._get_session()
8182
retry_options = ExponentialRetry(
82-
factor=10, exceptions={ConnectionError, ClientConnectionError}
83+
factor=2,
84+
attempts=10,
85+
max_timeout=UPDATE_INTERVAL,
86+
exceptions={ConnectionError, ClientConnectionError},
8387
)
8488
return RetryClient(client_session=session, retry_options=retry_options)
8589

0 commit comments

Comments
 (0)