Skip to content

Commit

Permalink
Do not timeout on subscribe/read operations (#35)
Browse files Browse the repository at this point in the history
* Do not timeout on subscribe/read operations

Sometimes read/subscribe operations take longer (presumably mainly at
startup while searching for the node and establishing CASE sessions).
The stack has its own timeout handling as well, we should rely on those.
  • Loading branch information
agners authored Jun 20, 2022
1 parent d4e7f67 commit edf9137
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions custom_components/matter_experimental/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
from __future__ import annotations

from abc import abstractmethod
import asyncio
from typing import Any, Callable, Coroutine

import async_timeout
from homeassistant.core import callback
from homeassistant.helpers import device_registry, entity

from matter_server.client.exceptions import FailedCommand
from matter_server.client.model.device import MatterDevice

from .const import DOMAIN
Expand Down Expand Up @@ -61,20 +60,20 @@ async def init_matter_device(self) -> None:

try:
# Subscribe to updates.
async with async_timeout.timeout(5):
self._unsubscribe = await self._device.subscribe_updates(
self._device_mapping.subscribe_attributes, self._subscription_update
)
self._unsubscribe = await self._device.subscribe_updates(
self._device_mapping.subscribe_attributes, self._subscription_update
)

# Fetch latest info from the device.
async with async_timeout.timeout(5):
await self._device.update_attributes(
self._device_mapping.subscribe_attributes
)
except asyncio.TimeoutError:
await self._device.update_attributes(
self._device_mapping.subscribe_attributes
)
except FailedCommand as err:
self._device.node.matter.adapter.logger.warning(
"Timeout interacting with %s, marking device as unavailable. Recovery is not implemented yet. Reload config entry when device is available again.",
"Error interacting with node %d (%s): %s. Marking device as unavailable. Recovery is not implemented yet. Reload config entry when device is available again.",
self._device.node.node_id,
self.entity_id,
str(err.error_code),
)
self._attr_available = False

Expand Down

0 comments on commit edf9137

Please sign in to comment.