Skip to content

Commit 75c194c

Browse files
authored
Timeout on add, service descriptions (#9)
* Timeout on add, service descriptions * Isort
1 parent 25c94fa commit 75c194c

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

custom_components/matter_experimental/adapter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def setup_node(self, node: MatterNode) -> None:
172172
self.logger.debug(
173173
"Creating %s entity for %s (%s)",
174174
platform,
175-
type(device),
175+
device.device_type.__name__,
176176
hex(device.device_type.device_type),
177177
)
178178
entities.append(device_mapping.entity_cls(device, device_mapping))

custom_components/matter_experimental/entity.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
"""Matter entity base class."""
22
from __future__ import annotations
33

4+
import asyncio
45
from typing import Any, Callable, Coroutine
56

7+
import async_timeout
68
from homeassistant.core import callback
79
from homeassistant.helpers import entity
810

@@ -51,13 +53,25 @@ async def async_added_to_hass(self) -> None:
5153
self._update_from_device()
5254
return
5355

54-
# Subscribe to updates.
55-
self._unsubscribe = await self._device.subscribe_updates(
56-
self._device_mapping.subscribe_attributes, self._subscription_update
57-
)
56+
try:
57+
# Subscribe to updates.
58+
async with async_timeout.timeout(5):
59+
self._unsubscribe = await self._device.subscribe_updates(
60+
self._device_mapping.subscribe_attributes, self._subscription_update
61+
)
62+
63+
# Fetch latest info from the device.
64+
async with async_timeout.timeout(5):
65+
await self._device.update_attributes(
66+
self._device_mapping.subscribe_attributes
67+
)
68+
except asyncio.TimeoutError:
69+
self._device.node.matter.adapter.logger.warning(
70+
"Timeout interacting with %s, marking device as unavailable. Recovery is not implemented yet. Reload config entry when device is available again.",
71+
self.entity_id,
72+
)
73+
self._attr_available = False
5874

59-
# Fetch latest info from the device.
60-
await self._device.update_attributes(self._device_mapping.subscribe_attributes)
6175
self._update_from_device()
6276

6377
async def async_will_remove_from_hass(self) -> None:

custom_components/matter_experimental/services.yaml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
commission:
22
name: Commission device
33
description: >
4-
Commission a new device
4+
Add a new device to your Matter network.
55
fields:
66
code:
77
name: Pairing code
@@ -11,7 +11,7 @@ commission:
1111
set_wifi:
1212
name: Set Wi-Fi credentials
1313
description: >
14-
This is needed to set-up new Wi-Fi devices.
14+
The Wi-Fi credentials will be sent as part of comissioning to a Matter device so it can connect to the Wi-Fi network.
1515
fields:
1616
network_name:
1717
name: Network name
@@ -27,7 +27,9 @@ set_wifi:
2727
set_thread:
2828
name: Set Thread network operational dataset
2929
description: >
30-
Required to set-up new Thread devices. Use "ot-ctl dataset active -x" on the OTBR.
30+
The Thread keys will be used as part of comissioning to let a Matter device join the Thread network.
31+
32+
Get keys by running `ot-ctl dataset active -x` on the Open Thread Border Router.
3133
fields:
3234
thread_operation_dataset:
3335
name: Thread Operational Dataset
@@ -37,7 +39,7 @@ set_thread:
3739
open_commissioning_window:
3840
name: Open Commissioning Window
3941
description: >
40-
Open Commissioning Window of a Matter device for 60s.
42+
Allow adding one of your devices to another Matter network by opening the commissioning window for this Matter device for 60 seconds.
4143
fields:
4244
device_id:
4345
name: Device

0 commit comments

Comments
 (0)