Advanced IADS: Reconnect from config

Co-Authored-By: RndName <mail@rndname.de>
This commit is contained in:
Raffson 2022-11-20 13:51:18 +01:00
parent b49562f4bc
commit 89c4cc9d79
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99

View File

@ -198,7 +198,10 @@ class IadsNetwork:
# Not participating # Not participating
return return
events.update_iads_node(node) events.update_iads_node(node)
if self.advanced_iads and not self.iads_config: if self.advanced_iads:
if self.iads_config:
self._add_connections_from_config(node)
else:
self._make_advanced_connections_by_range(node) self._make_advanced_connections_by_range(node)
def node_for_group(self, group: IadsGroundGroup) -> IadsNetworkNode: def node_for_group(self, group: IadsGroundGroup) -> IadsNetworkNode:
@ -259,17 +262,17 @@ class IadsNetwork:
def initialize_network_from_config(self) -> None: def initialize_network_from_config(self) -> None:
"""Initialize the IADS Network from a configuration""" """Initialize the IADS Network from a configuration"""
for element_name, connections in self.iads_config.items(): for primary_node in self.iads_config.keys():
warning_msg = ( warning_msg = (
f"IADS: No ground object found for {element_name}." f"IADS: No ground object found for {primary_node}."
f" This can be normal behaviour." f" This can be normal behaviour."
) )
if element_name in self.ground_objects: if primary_node in self.ground_objects:
node = self.node_for_tgo(self.ground_objects[element_name]) node = self.node_for_tgo(self.ground_objects[primary_node])
else: else:
node = None node = None
warning_msg = ( warning_msg = (
f"IADS: No ground object found for connection {element_name}" f"IADS: No ground object found for connection {primary_node}"
) )
if node is None: if node is None:
@ -278,14 +281,18 @@ class IadsNetwork:
# available. Therefore the TGO will not get populated at all # available. Therefore the TGO will not get populated at all
logging.warning(warning_msg) logging.warning(warning_msg)
continue continue
self._add_connections_from_config(node)
# Find all connected ground_objects def _add_connections_from_config(self, node: IadsNetworkNode) -> None:
for node_name in connections: """Add all connections for the given primary node based on the iads_config"""
primary_node = node.group.ground_object.original_name
connections = self.iads_config[primary_node]
for secondary_node in connections:
try: try:
node.add_connection_for_tgo(self.ground_objects[node_name]) node.add_connection_for_tgo(self.ground_objects[secondary_node])
except KeyError: except KeyError:
logging.error( logging.error(
f"IADS: No ground object found for connection {node_name}" f"IADS: No ground object found for connection {secondary_node}"
) )
continue continue