@@ -114,6 +114,12 @@ async def get_rule_by_id(api, rule_type, rule_id):
114114 elif rule_type == "wlans" :
115115 wlans = await api .get_wlans ()
116116 return next ((w for w in wlans if w .id == rule_id ), None )
117+ elif rule_type == "vpn_clients" :
118+ clients = await api .get_vpn_clients ()
119+ return next ((c for c in clients if c .id == rule_id ), None )
120+ elif rule_type == "vpn_servers" :
121+ servers = await api .get_vpn_servers ()
122+ return next ((s for s in servers if s .id == rule_id ), None )
117123 return None
118124
119125 # Function to toggle rule based on its type
@@ -132,6 +138,8 @@ async def toggle_rule(api, rule_type, rule_obj):
132138 return await api .queue_api_operation (api .toggle_qos_rule , rule_obj )
133139 elif rule_type == "wlans" :
134140 return await api .queue_api_operation (api .toggle_wlan , rule_obj )
141+ elif rule_type in ["vpn_clients" , "vpn_servers" ]:
142+ return await api .queue_api_operation (api .toggle_vpn_config , rule_obj )
135143 return False
136144
137145 for coordinator in coordinators .values ():
@@ -146,7 +154,7 @@ async def toggle_rule(api, rule_type, rule_obj):
146154 break
147155 else :
148156 # If rule_type is not specified, try all types
149- for type_name in ["firewall_policies" , "traffic_rules" , "port_forwards" , "traffic_routes" , "legacy_firewall_rules" , "qos_rules" , "wlans" ]:
157+ for type_name in ["firewall_policies" , "traffic_rules" , "port_forwards" , "traffic_routes" , "legacy_firewall_rules" , "qos_rules" , "wlans" , "vpn_clients" , "vpn_servers" ]:
150158 try :
151159 rule_obj = await get_rule_by_id (api , type_name , rule_id )
152160 if rule_obj :
@@ -195,22 +203,41 @@ async def async_delete_rule(hass: HomeAssistant, coordinators: Dict, call: Servi
195203 real_id = parts [2 ]
196204 LOGGER .debug ("Extracted ID %s from prefixed ID %s" , real_id , rule_id )
197205 rule_id = real_id
206+
207+ # Helper function to delete rule by type using the API queue
208+ async def delete_rule (api , rule_type , rule_id ):
209+ """Delete a rule by its type."""
210+ if rule_type == "firewall_policies" :
211+ return await api .queue_api_operation (api .remove_firewall_policy , rule_id )
212+ elif rule_type == "traffic_rules" :
213+ return await api .queue_api_operation (api .remove_traffic_rule , rule_id )
214+ elif rule_type == "port_forwards" :
215+ return await api .queue_api_operation (api .remove_port_forward , rule_id )
216+ elif rule_type == "traffic_routes" :
217+ return await api .queue_api_operation (api .remove_traffic_route , rule_id )
218+ elif rule_type == "legacy_firewall_rules" :
219+ return await api .queue_api_operation (api .remove_legacy_firewall_rule , rule_id )
220+ elif rule_type == "qos_rules" :
221+ return await api .queue_api_operation (api .remove_qos_rule , rule_id )
222+ elif rule_type in ["vpn_clients" , "vpn_servers" ]:
223+ return await api .queue_api_operation (api .remove_vpn_config , rule_id )
224+ return False
198225
199226 success = False
200227 for coordinator in coordinators .values ():
201228 api = coordinator .api
202229 try :
203230 # Try to delete rule based on rule_type
204231 if rule_type :
205- if await api . delete_rule (rule_type , rule_id ):
232+ if await delete_rule (api , rule_type , rule_id ):
206233 success = True
207234 LOGGER .info ("Successfully deleted rule %s of type %s" , rule_id , rule_type )
208235 break
209236 else :
210- # Try all rule types
211- for type_name in ["firewall_policies" , "traffic_rules" , "port_forwards" , "traffic_routes" , "legacy_firewall_rules" , "qos_rules" ]:
237+ # Try all rule types that can be deleted
238+ for type_name in ["firewall_policies" , "traffic_rules" , "port_forwards" , "traffic_routes" , "legacy_firewall_rules" , "qos_rules" , "vpn_clients" , "vpn_servers" ]:
212239 try :
213- if await api . delete_rule (type_name , rule_id ):
240+ if await delete_rule (api , type_name , rule_id ):
214241 success = True
215242 LOGGER .info ("Successfully deleted rule %s using type: %s" , rule_id , type_name )
216243 break
@@ -265,6 +292,8 @@ async def toggle_rule_if_needed(api, rule_type, rule_obj, desired_state):
265292 return await api .queue_api_operation (api .toggle_qos_rule , rule_obj )
266293 elif rule_type == "wlans" :
267294 return await api .queue_api_operation (api .toggle_wlan , rule_obj )
295+ elif rule_type in ["vpn_clients" , "vpn_servers" ]:
296+ return await api .queue_api_operation (api .toggle_vpn_config , rule_obj )
268297 return True # Already in desired state
269298
270299 entity_registry = async_get_entity_registry (hass )
0 commit comments