|
21 | 21 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 | from __future__ import annotations |
23 | 23 |
|
24 | | -from typing import Optional |
| 24 | +from typing import List, Optional |
25 | 25 |
|
26 | 26 | from sdbus.sd_bus_internals import SdBus |
27 | 27 |
|
@@ -154,6 +154,24 @@ def __init__(self, bus: Optional[SdBus] = None) -> None: |
154 | 154 | '/org/freedesktop/NetworkManager/Settings', |
155 | 155 | bus) |
156 | 156 |
|
| 157 | + async def get_connections_by_id(self, connection_id: str) -> List[str]: |
| 158 | + """Helper method to get a list of connection profile paths |
| 159 | + which use the given connection identifier. |
| 160 | +
|
| 161 | + :param str connection_id: The connection identifier of the connections, |
| 162 | + e.g. "Ethernet connection 1" |
| 163 | + :return: List of connection profile paths using the given identifier. |
| 164 | + """ |
| 165 | + connection_paths_with_matching_id = [] |
| 166 | + connection_paths: List[str] = await self.connections |
| 167 | + for connection_path in connection_paths: |
| 168 | + settings = NetworkConnectionSettings(connection_path) |
| 169 | + settings_properites = await settings.get_settings() |
| 170 | + # settings_properites["connection"]["id"][1] gives the id value: |
| 171 | + if settings_properites["connection"]["id"][1] == connection_id: |
| 172 | + connection_paths_with_matching_id.append(connection_path) |
| 173 | + return connection_paths_with_matching_id |
| 174 | + |
157 | 175 |
|
158 | 176 | class NetworkConnectionSettings( |
159 | 177 | NetworkManagerSettingsConnectionInterfaceAsync): |
|
0 commit comments