Skip to content

Commit 0179fad

Browse files
committed
Correct subscription to feature updates for only intended node
1 parent f7287bf commit 0179fad

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

plugwise_usb/nodes/helpers/subscription.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dataclasses import dataclass
88
from typing import Any
99

10+
1011
from ...api import NodeFeature
1112

1213

@@ -20,11 +21,12 @@ class NodeFeatureSubscription:
2021

2122
class FeaturePublisher:
2223
"""Base Class to call awaitable of subscription when event happens."""
24+
def __init__(self) -> None:
25+
self._feature_update_subscribers: dict[
26+
Callable[[], None],
27+
NodeFeatureSubscription,
28+
] = {}
2329

24-
_feature_update_subscribers: dict[
25-
Callable[[], None],
26-
NodeFeatureSubscription,
27-
] = {}
2830

2931
def subscribe_to_feature_update(
3032
self,

plugwise_usb/nodes/node.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(
6363
loaded_callback: Callable[[NodeEvent, str], Awaitable[None]],
6464
):
6565
"""Initialize Plugwise base node class."""
66+
super().__init__()
6667
self._loaded_callback = loaded_callback
6768
self._message_subscribe = controller.subscribe_to_messages
6869
self._features: tuple[NodeFeature, ...] = NODE_FEATURES
@@ -415,7 +416,8 @@ async def _available_update_state(
415416
if (
416417
self._last_seen is not None
417418
and timestamp is not None
418-
and self._last_seen < timestamp
419+
and (timestamp - self._last_seen).seconds > 5
420+
419421
):
420422
self._last_seen = timestamp
421423
await self.publish_feature_update_to_subscribers(

tests/test_usb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ async def test_node_relay_and_power(self, monkeypatch: pytest.MonkeyPatch) -> No
838838
assert await stick.nodes["2222222222222222"].load()
839839
self.test_init_relay_state_on = asyncio.Future()
840840
self.test_init_relay_state_off = asyncio.Future()
841-
unsub_inti_relay = stick.nodes["0098765432101234"].subscribe_to_feature_update(
841+
unsub_inti_relay = stick.nodes["2222222222222222"].subscribe_to_feature_update(
842842
node_feature_callback=self.node_init_relay_state,
843843
features=(pw_api.NodeFeature.RELAY_INIT,),
844844
)

0 commit comments

Comments
 (0)