Document the reconnect-timing change from smartthings-local's fail-fast fix

Answers a review callout on the 0.1.6 upgrade that wasn't actually
addressed, only mentioned in a commit message: a dead reader now raises
SessionClosedError (a ConnectionError) instead of hanging a request out
to its timeout and surfacing as an ambiguous TimeoutError. Mechanically
this was already routed correctly -- SessionClosedError isn't a
TimeoutError, so _defer_reconnect_for's isinstance check already skips
its multi-cycle tolerance for it -- but nothing recorded *why*, and the
callout's whole point was that downstream (i.e. this repo) should hear
about the resulting timing change explicitly, not infer it from the
dependency bump.

Before 0.1.6, a truly dead reader was indistinguishable here from a
slow blockwise transfer: both could only ever surface as a TimeoutError,
so _POLL_TIMEOUT_LIMIT's multi-cycle tolerance (~2 minutes at the
default 30s interval) was the only thing standing between a genuinely
dead session and a reconnect. Now that the library confirms reader
death directly, that failure mode skips the tolerance and reconnects on
the very first occurrence -- intended, and strictly faster recovery,
but a real change in observed timing worth calling out for anyone
correlating reconnect-log cadence with device behavior.

- _poll_once, _defer_reconnect_for, and the _POLL_TIMEOUT_LIMIT comment
  now say so directly, cross-referencing each other.
- README's "Known device behavior" section gets a paragraph so this
  isn't only visible to someone reading the coordinator's source.
- Two new unit tests pin the distinction directly:
  _defer_reconnect_for(SessionClosedError()) is False (no tolerance),
  while SessionTimeoutError keeps the existing _POLL_TIMEOUT_LIMIT
  tolerance -- so a future change can't quietly merge the two paths
  back together.

Full suite (1523 tests), ruff, and ty pass.
This commit is contained in:
Marc Billow committed 2026-08-14 18:15:32 +00:00
1 parent f949ff04c2
commit 74bdc04f56
3 files changed
+58 -2

No files matched your search

+31 -1
View File
@@ -13,7 +13,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceValidationError
from homeassistant.helpers import issue_registry as ir
from smartthings_local.errors import SessionError
from smartthings_local.errors import SessionClosedError, SessionError, SessionTimeoutError
from custom_components.localthings.const import (
CONF_BYPASS_REMOTE_CONTROL,
@@ -532,6 +532,36 @@ async def test_total_poll_failure_downgrades_observe_mode_to_poll(
assert coordinator.last_update_success is True
def test_defer_reconnect_for_reconnects_immediately_on_a_confirmed_dead_session(
hass: HomeAssistant, mock_entry
) -> None:
"""smartthings-local >= 0.1.6 raises SessionClosedError -- a
ConnectionError, not a TimeoutError -- the moment a dead reader thread
is confirmed, instead of the old behavior of letting the request hang
out to its own timeout and surface as an ambiguous TimeoutError.
_defer_reconnect_for must never extend the block-ACK tolerance to a
failure this unambiguous; see its docstring for the full reasoning."""
coordinator = LocalThingsCoordinator(hass, mock_entry)
coordinator._discovered = True
assert coordinator._defer_reconnect_for(SessionClosedError()) is False
def test_defer_reconnect_for_still_tolerates_an_ambiguous_timeout(
hass: HomeAssistant, mock_entry
) -> None:
"""The other half of the same distinction: a plain block-ACK timeout --
still a TimeoutError, including smartthings-local's own
SessionTimeoutError subclass -- keeps its multi-cycle tolerance rather
than being swept into the immediate-reconnect path above."""
coordinator = LocalThingsCoordinator(hass, mock_entry)
coordinator._discovered = True
for _ in range(coordinator._POLL_TIMEOUT_LIMIT - 1):
assert coordinator._defer_reconnect_for(SessionTimeoutError()) is True
assert coordinator._defer_reconnect_for(SessionTimeoutError()) is False
async def test_poll_timeout_skips_reconnect_when_push_is_healthy(
hass: HomeAssistant, mock_entry, mock_coordinator_observe_session
) -> None: