Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Add WiFi more reliable #250

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ubo_app/services/030-wifi/pages/create_wireless_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from kivy.lang.builder import Builder
from kivy.properties import BooleanProperty
from sdbus_async.networkmanager import NetworkManagerUnknownConnectionError
from str_to_bool import str_to_bool
from tenacity import retry, retry_if_exception, stop_after_attempt, wait_fixed
from ubo_gui.constants import SUCCESS_COLOR, WARNING_COLOR
from ubo_gui.page import PageWidget
from wifi_manager import add_wireless_connection
Expand Down Expand Up @@ -162,7 +164,7 @@

logger.debug('wifi connection input - creating connection')
try:
await add_wireless_connection(
await add_wireless_connection_with_retry(

Check warning on line 167 in ubo_app/services/030-wifi/pages/create_wireless_connection.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/services/030-wifi/pages/create_wireless_connection.py#L167

Added line #L167 was not covered by tests
ssid=ssid,
password=password,
type=type or WiFiType.NOPASS,
Expand Down Expand Up @@ -198,6 +200,22 @@
)


@retry(
stop=stop_after_attempt(3),
wait=wait_fixed(1),
retry=retry_if_exception(lambda e: isinstance(e,
NetworkManagerUnknownConnectionError)),
)
async def add_wireless_connection_with_retry(
ssid: str,
password: str,
type: WiFiType,
*,
hidden: bool | None = False,
) -> None:
return await add_wireless_connection(ssid, password, type, hidden=hidden)

Check warning on line 216 in ubo_app/services/030-wifi/pages/create_wireless_connection.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/services/030-wifi/pages/create_wireless_connection.py#L216

Added line #L216 was not covered by tests


class CreateWirelessConnectionPage(PageWidget):
creating = BooleanProperty(defaultvalue=False)

Expand Down
51 changes: 30 additions & 21 deletions ubo_app/services/030-wifi/wifi_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,9 @@
from typing import TYPE_CHECKING, Any, TypeVar, cast

from debouncer import DebounceOptions, debounce
from ubo_gui.constants import DANGER_COLOR

from ubo_app.store.main import store
from ubo_app.store.services.ethernet import NetState
from ubo_app.store.services.notifications import (
Chime,
Notification,
NotificationDisplayType,
NotificationsAddAction,
)
from ubo_app.store.services.wifi import ConnectionState, WiFiConnection, WiFiType
from ubo_app.utils.bus_provider import get_system_bus

if TYPE_CHECKING:
from asyncio.tasks import _FutureLike
from collections.abc import Coroutine

from sdbus import dbus_exceptions
from sdbus.utils.inspect import ( # pyright: ignore [reportMissingImports]
inspect_dbus_path,
from sdbus.utils.inspect import (
inspect_dbus_path, # pyright: ignore [reportMissingImports]
)
from sdbus_async.networkmanager import (
AccessPoint,
Expand All @@ -39,11 +22,29 @@
NetworkManager,
NetworkManagerConnectionProperties,
NetworkManagerSettings,
NmDeviceNotAllowedError,
)
from sdbus_async.networkmanager.enums import (
ConnectionState as SdBusConnectionState,
)
from sdbus_async.networkmanager.enums import DeviceType
from ubo_gui.constants import DANGER_COLOR

from ubo_app.logger import logger
from ubo_app.store.main import store
from ubo_app.store.services.ethernet import NetState
from ubo_app.store.services.notifications import (
Chime,
Notification,
NotificationDisplayType,
NotificationsAddAction,
)
from ubo_app.store.services.wifi import ConnectionState, WiFiConnection, WiFiType
from ubo_app.utils.bus_provider import get_system_bus

if TYPE_CHECKING:
from asyncio.tasks import _FutureLike
from collections.abc import Coroutine

RETRIES = 3

Expand Down Expand Up @@ -104,8 +105,17 @@
@debounce(wait=0.5, options=DebounceOptions(trailing=True, time_window=2))
async def request_scan() -> None:
wifi_device = await get_wifi_device()
if wifi_device:
if wifi_device is None:
logger.warning('Cannot scan: WiFi device not found')
return

Check warning on line 110 in ubo_app/services/030-wifi/wifi_manager.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/services/030-wifi/wifi_manager.py#L109-L110

Added lines #L109 - L110 were not covered by tests
try:
await wait_for(wifi_device.request_scan({}))
except NmDeviceNotAllowedError as e:
logger.exception('WiFi scan not allowed', extra={'error': e})
except TimeoutError:
logger.exception('WiFi scan timed out')
except Exception as e:
logger.exception('Unexpected error during WiFi scan', extra={'error': e})

Check warning on line 118 in ubo_app/services/030-wifi/wifi_manager.py

View check run for this annotation

Codecov / codecov/patch

ubo_app/services/030-wifi/wifi_manager.py#L113-L118

Added lines #L113 - L118 were not covered by tests


async def get_access_points() -> list[AccessPoint]:
Expand Down Expand Up @@ -267,7 +277,6 @@
'auth-alg': ('s', 'open'),
'psk': ('s', password),
}
from ubo_app.logger import logger

properties: NetworkManagerConnectionProperties = {
'connection': {
Expand Down
Loading