22
33from __future__ import annotations
44
5- from collections .abc import Callable
65from dataclasses import dataclass
76import logging
8- from typing import Any
97
10- from plugwise_usb .api import PUSHING_FEATURES , NodeFeature , NodeInfo
8+ from plugwise_usb .api import NodeFeature , NodeInfo
119
1210from homeassistant .helpers .device_registry import CONNECTION_ZIGBEE , DeviceInfo
1311from homeassistant .helpers .entity import EntityDescription
@@ -40,10 +38,8 @@ def __init__(
4038 super ().__init__ (node_duc , context = entity_description .node_feature )
4139 self .node_duc = node_duc
4240 self .entity_description = entity_description
43- self .unsubscribe_push_events : Callable [[], None ] | None = None
4441 self ._node_info : NodeInfo = node_duc .node .node_info
4542 self ._attr_unique_id = f"{ self ._node_info .mac } -{ entity_description .key } "
46- self ._subscribe_to_feature_fn = node_duc .node .subscribe_to_feature_update
4743 self ._via_device = (DOMAIN , str (node_duc .api_stick .mac_stick ))
4844
4945 @property
@@ -70,34 +66,10 @@ def device_info(self) -> DeviceInfo:
7066 async def async_added_to_hass (self ):
7167 """Subscribe for push updates."""
7268 await super ().async_added_to_hass ()
73- if (
74- self .entity_description .node_feature in PUSHING_FEATURES
75- and self .entity_description .node_feature in self ._node_info .features
76- ):
77- self .unsubscribe_push_events = self ._subscribe_to_feature_fn (
78- self .async_push_event ,
79- self .entity_description .node_feature ,
80- )
81-
82- async def async_push_event (self , feature : NodeFeature , state : Any ) -> None :
83- """Update data on pushed event."""
84- if self .node_duc is None :
85- _LOGGER .warning (
86- "Unable to push event=%s, state=%s, mac=%s" ,
87- feature ,
88- state ,
89- self ._node_info .mac ,
90- )
91- else :
92- self .node_duc .async_set_updated_data (
93- {
94- feature : state ,
95- }
96- )
69+ await self .node_duc .subscribe_nodefeature (
70+ self .entity_description .node_feature
71+ )
9772
9873 async def async_will_remove_from_hass (self ):
9974 """Unsubscribe to updates."""
100- if self .unsubscribe_push_events is not None :
101- self .unsubscribe_push_events ()
102- self .unsubscribe_push_events = None
10375 await super ().async_will_remove_from_hass ()
0 commit comments