Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions core/frontend/src/components/wifi/WifiManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@
flat
class="text-body-1 text-center"
>
No wifi networks available :( <br>
Rescanning...
<template v-if="wifi_status?.state === 'unavailable'">
No wifi adapter
</template>
<template v-else>
No wifi networks available :( <br>
Rescanning...
</template>
</v-card-text>
</div>
<div v-else>
Expand Down
9 changes: 9 additions & 0 deletions core/frontend/src/components/wifi/WifiUpdater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export default Vue.extend({
timeout: 10000,
})
.then((response) => {
if (response.data.state === 'unavailable') {
wifi.setNetworkStatus(response.data)
wifi.setCurrentNetwork(null)
wifi.setAvailableNetworks([])
this.fetch_network_status_task.setDelay(30000)
return
}

this.fetch_network_status_task.setDelay(5000)
wifi.setNetworkStatus(response.data)

if (response.data.wpa_state !== 'COMPLETED') {
Expand Down
1 change: 1 addition & 0 deletions core/frontend/src/types/wifi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface WifiStatus {
p2p_device_address: string
address: string
uuid: string
state?: string
}

export interface WPANetwork {
Expand Down
21 changes: 19 additions & 2 deletions core/services/wifi/wifi_handlers/wpa_supplicant/WifiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def hotspot(self) -> HotspotManager:

async def get_wifi_available(self) -> List[ScannedWifiNetwork]:
"""Get a dict from the wifi signals available"""
if self.wpa_path is None:
return []

async def perform_new_scan() -> None:
try:
Expand Down Expand Up @@ -231,6 +233,8 @@ async def perform_new_scan() -> None:

async def get_saved_wifi_network(self) -> List[SavedWifiNetwork]:
"""Get a list of saved wifi networks"""
if self.wpa_path is None:
return []
try:
data = await self.wpa.send_command_list_networks()
networks_list = WifiManager.__dict_from_table(data)
Expand Down Expand Up @@ -331,6 +335,8 @@ async def connect_to_network(self, network_id: int, timeout: float = 20.0) -> No

async def status(self) -> WifiStatus:
"""Check wpa_supplicant status"""
if self.wpa_path is None:
return WifiStatus(state="unavailable")
try:
data = await self.wpa.send_command_status()
return WifiStatus(**WifiManager.__dict_from_list(data))
Expand Down Expand Up @@ -473,6 +479,9 @@ async def set_hotspot_credentials(self, credentials: WifiCredentials) -> None:
self._settings_manager.settings.hotspot_password = credentials.password
self._settings_manager.save()

if self.wpa_path is None:
return

self.hotspot.set_credentials(credentials)

if self.hotspot.is_running():
Expand All @@ -481,6 +490,9 @@ async def set_hotspot_credentials(self, credentials: WifiCredentials) -> None:
await self.enable_hotspot(save_settings=False)

def hotspot_credentials(self) -> WifiCredentials:
if self.wpa_path is None:
settings = self._settings_manager.settings
return WifiCredentials(ssid=settings.hotspot_ssid or "", password=settings.hotspot_password or "")
credentials: WifiCredentials = self.hotspot.credentials
return credentials

Expand Down Expand Up @@ -566,14 +578,19 @@ def is_socket(file_path: str) -> bool:
try:
await self.connect(("127.0.0.1", 6664))
except Exception as udp_connection_error:
logger.error(f"Could not connect with internet socket: {udp_connection_error}. Exiting.")
raise udp_connection_error
logger.error(f"Could not connect with internet socket: {udp_connection_error}.")
self.wpa_path = None
return
loop = asyncio.get_event_loop()
loop.create_task(self.auto_reconnect(60))
loop.create_task(self.start_hotspot_watchdog())

async def supports_hotspot(self) -> bool:
if self.wpa_path is None:
return False
return self.hotspot.supports_hotspot

async def hotspot_is_running(self) -> bool:
if self.wpa_path is None:
return False
return self.hotspot.is_running()