@@ -102,12 +102,18 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
102102 return True
103103
104104
105- async def async_setup_entry (hass , config_entry , async_add_devices ):
106- """Set up the Alarmo entities."""
107-
105+ async def async_setup_entry (hass , config_entry , async_add_devices ):
106+ """Set up the Alarmo entities."""
107+
108108 @callback
109109 def async_add_alarm_entity (config : dict ):
110110 """Add each entity as Alarm Control Panel."""
111+ if not hass .config_entries .async_get_entry (config_entry .entry_id ):
112+ _LOGGER .debug (
113+ "Skipping area registration for unloaded config entry %s" ,
114+ config_entry .entry_id ,
115+ )
116+ return
111117 unique_id = _build_unique_id (hass , config ["area_id" ])
112118 entity_registry = er .async_get (hass )
113119 existing_entity_id = entity_registry .async_get_entity_id (
@@ -146,6 +152,12 @@ def async_add_alarm_entity(config: dict):
146152 @callback
147153 def async_add_alarm_master (config : dict ):
148154 """Add each entity as Alarm Control Panel."""
155+ if not hass .config_entries .async_get_entry (config_entry .entry_id ):
156+ _LOGGER .debug (
157+ "Skipping master registration for unloaded config entry %s" ,
158+ config_entry .entry_id ,
159+ )
160+ return
149161 unique_id = _build_unique_id (hass )
150162 entity_registry = er .async_get (hass )
151163 existing_entity_id = entity_registry .async_get_entity_id (
@@ -1310,9 +1322,11 @@ def async_alarm_state_changed(area_id: str, old_state: str, new_state: str):
13101322 return
13111323 self .async_update_state ()
13121324
1313- async_dispatcher_connect (
1314- self .hass , "alarmo_state_updated" , async_alarm_state_changed
1315- )
1325+ self .async_on_remove (
1326+ async_dispatcher_connect (
1327+ self .hass , "alarmo_state_updated" , async_alarm_state_changed
1328+ )
1329+ )
13161330
13171331 @callback
13181332 def async_handle_event (event : str , area_id : str , args : dict = {}):
@@ -1352,7 +1366,9 @@ def async_handle_event(event: str, area_id: str, args: dict = {}):
13521366 if event == const .EVENT_READY_TO_ARM_MODES_CHANGED :
13531367 self .update_ready_to_arm_modes ()
13541368
1355- async_dispatcher_connect (self .hass , "alarmo_event" , async_handle_event )
1369+ self .async_on_remove (
1370+ async_dispatcher_connect (self .hass , "alarmo_event" , async_handle_event )
1371+ )
13561372
13571373 state = await self .async_get_last_state ()
13581374 if state and state .state :
0 commit comments