1010
1111from homeassistant .components .button import ButtonEntity , ButtonEntityDescription
1212from homeassistant .const import EntityCategory , Platform
13- from homeassistant .core import HomeAssistant , callback
13+ from homeassistant .core import HomeAssistant
1414from homeassistant .helpers .entity_platform import AddEntitiesCallback
1515
1616from .const import NODES , STICK , UNSUB_NODE_LOADED
@@ -58,7 +58,7 @@ class PlugwiseButtonEntityDescription(
5858 translation_key = "calibrate_light" ,
5959 entity_category = EntityCategory .CONFIG ,
6060 async_button_fn = "scan_calibrate_light" ,
61- node_feature = NodeFeature .MOTION ,
61+ node_feature = NodeFeature .MOTION_CONFIG ,
6262 ),
6363)
6464
@@ -76,14 +76,15 @@ async def async_add_button(node_event: NodeEvent, mac: str) -> None:
7676 return
7777 entities : list [PlugwiseUSBEntity ] = []
7878 if (node_duc := config_entry .runtime_data [NODES ].get (mac )) is not None :
79- _LOGGER .debug ("Add button entities for node %s" , node_duc .node .name )
80- entities .extend (
81- [
82- PlugwiseUSBButtonEntity (node_duc , entity_description )
83- for entity_description in BUTTON_TYPES
84- if entity_description .node_feature in node_duc .node .features
85- ]
86- )
79+ for entity_description in BUTTON_TYPES :
80+ if entity_description .node_feature not in node_duc .node .features :
81+ continue
82+ entities .append (PlugwiseUSBButtonEntity (node_duc , entity_description ))
83+ _LOGGER .debug (
84+ "Add %s button for node %s" ,
85+ entity_description .translation_key ,
86+ node_duc .node .name ,
87+ )
8788 if entities :
8889 async_add_entities (entities )
8990
@@ -102,6 +103,8 @@ async def async_add_button(node_event: NodeEvent, mac: str) -> None:
102103 for mac , node in api_stick .nodes .items ():
103104 if node .is_loaded :
104105 await async_add_button (NodeEvent .LOADED , mac )
106+ else :
107+ _LOGGER .debug ("Adding button(s) for node %s failed, not loaded" , mac )
105108
106109
107110async def async_unload_entry (
@@ -126,13 +129,6 @@ def __init__(
126129 node_duc .node , entity_description .async_button_fn
127130 )
128131
129- @callback
130- def _handle_coordinator_update (self ) -> None :
131- """Handle updated data from the coordinator."""
132-
133132 async def async_press (self ) -> None :
134133 """Button was pressed."""
135134 await self .async_button_fn ()
136-
137- async def async_added_to_hass (self ):
138- """Subscribe for push updates."""
0 commit comments