Skip to content

Commit

Permalink
Cleanup commit, plus more data!
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ketchel committed Nov 7, 2024
1 parent 7958b67 commit 5767c3b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
18 changes: 9 additions & 9 deletions wlanpi_core/api/api_v1/endpoints/network_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async def delete_ethernet_vlan(
@router.get("/wlan/interfaces", response_model=network.Interfaces)
async def get_wireless_interfaces(timeout: int = API_DEFAULT_TIMEOUT):
"""
Queries systemd via dbus to get the details of the currently connected network.
Queries wpa_supplicant via dbus to get all interfaces known to the supplicant.
"""

try:
Expand All @@ -233,7 +233,7 @@ async def do_wireless_network_scan(
scan_type: str, interface: str, timeout: int = API_DEFAULT_TIMEOUT
):
"""
Queries systemd via dbus to get a scan of the available networks.
Queries wpa_supplicant via dbus to get a scan of the available networks for an interface.
"""

try:
Expand All @@ -254,7 +254,7 @@ async def add_wireless_network(
timeout: int = API_DEFAULT_TIMEOUT,
):
"""
Queries systemd via dbus to set a single network.
Queries wpa_supplicant via dbus to set a single network.
"""

try:
Expand All @@ -277,7 +277,7 @@ async def get_current_wireless_network_details(
interface: str, timeout: int = API_DEFAULT_TIMEOUT
):
"""
Queries systemd via dbus to get the details of the currently connected network.
Queries wpa_supplicant via dbus to get the details of the currently connected network.
"""

try:
Expand All @@ -300,7 +300,7 @@ async def disconnect_wireless_network(
interface: str, timeout: int = API_DEFAULT_TIMEOUT
):
"""
Queries systemd via dbus to get the details of the currently connected network.
Disconnects the currently connected network for the specified interface.
"""

try:
Expand All @@ -319,7 +319,7 @@ async def disconnect_wireless_network(
)
async def get_all_wireless_networks(interface: str, timeout: int = API_DEFAULT_TIMEOUT):
"""
Queries systemd via dbus to get the details of the currently connected network.
Queries wpa_supplicant via dbus to get all network on an interface.
"""

try:
Expand All @@ -338,7 +338,7 @@ async def get_all_wireless_networks(interface: str, timeout: int = API_DEFAULT_T
)
async def get_current_network(interface: str, timeout: int = API_DEFAULT_TIMEOUT):
"""
Queries systemd via dbus to get the details of the currently connected network.
Queries wpa_supplicant via dbus to get the details of the currently selected network.
"""

try:
Expand All @@ -357,7 +357,7 @@ async def get_current_network(interface: str, timeout: int = API_DEFAULT_TIMEOUT
)
async def get_wireless_network(interface: str, network_id: int):
"""
Queries systemd via dbus to get the details of the currently connected network.
Queries wpa_supplicant via dbus to get the details of a specific network.
"""

try:
Expand Down Expand Up @@ -395,7 +395,7 @@ async def remove_all_wireless_networks(interface: str):
)
async def disconnect_wireless_network(interface: str, network_id: int):
"""
Queries systemd via dbus to get the details of the currently connected network.
Disconnects the specified wireless network.
"""

try:
Expand Down
4 changes: 1 addition & 3 deletions wlanpi_core/services/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from wlanpi_core.models.validation_error import ValidationError
from wlanpi_core.schemas import network
from wlanpi_core.schemas.network.network import SupplicantNetwork
from wlanpi_core.utils.network import (
get_interface_details,
)
from wlanpi_core.utils.network import get_interface_details

"""
These are the functions used to deliver the API
Expand Down
12 changes: 11 additions & 1 deletion wlanpi_core/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,21 @@ def get_interface_details(
iw_list_data = parse_iw_list(run_command(["iw", "list"]).stdout.split("\n"))

return {
get_phy_interface_name(k.split(" ")[1].split("phy")[1]): v
get_phy_interface_name(k.split(" ")[1].split("phy")[1]): {
"phy_name": k.split(" ")[1],
"mac": get_interface_mac(
get_phy_interface_name(k.split(" ")[1].split("phy")[1])
),
"details": v,
}
for k, v in iw_list_data.items()
if "phy" in k
}


def get_interface_mac(interface: str) -> str:
return run_command(["jc", "ifconfig", interface]).output_from_json()[0]["mac_addr"]


if __name__ == "__main__":
print(json.dumps(get_interface_details()))

0 comments on commit 5767c3b

Please sign in to comment.