sghorbal commited on
Commit
00343ac
·
1 Parent(s): c10a804

rework the wifi activation process

Browse files
Files changed (2) hide show
  1. src/api.py +1 -1
  2. src/main.py +14 -8
src/api.py CHANGED
@@ -77,7 +77,7 @@ def enable_wifi():
77
  # Activate the wifi if needed
78
  if wifi_state == WifiState.INACTIVE:
79
  log_info("WiFi is inactive, trying to activate...")
80
- if fbxpy.active_wifi():
81
  log_info("WiFi activated successfully.")
82
  else:
83
  log_error("Failed to activate WiFi.")
 
77
  # Activate the wifi if needed
78
  if wifi_state == WifiState.INACTIVE:
79
  log_info("WiFi is inactive, trying to activate...")
80
+ if fbxpy.activate_wifi():
81
  log_info("WiFi activated successfully.")
82
  else:
83
  log_error("Failed to activate WiFi.")
src/main.py CHANGED
@@ -193,13 +193,19 @@ class Fbxpy():
193
  try:
194
  result = self.connexion_get(method=Endpoint.WIFI_AP)
195
 
196
- state = WifiState.get_by_value(result["result"][0]["status"]["state"])
 
 
 
 
197
 
198
- if state == WifiState.ACTIVE:
199
- if self.get_wifi_planning_state() == WifiPlanningState.TRUE:
200
- return WifiState.ACTIVE_PLANIF
201
- else:
202
- return WifiState.ACTIVE
 
 
203
 
204
  except Exception as e:
205
  log_exception(e)
@@ -238,7 +244,7 @@ class Fbxpy():
238
 
239
  return False
240
 
241
- def active_wifi(self) -> bool:
242
  """
243
  Activate the WiFi.
244
  """
@@ -286,7 +292,7 @@ if __name__ == "__main__":
286
  # Activate the wifi if needed
287
  if wifi_state == WifiState.INACTIVE:
288
  log_info("WiFi is inactive, trying to activate...")
289
- if singleton.active_wifi():
290
  log_info("WiFi activated successfully.")
291
  else:
292
  log_error("Failed to activate WiFi.")
 
193
  try:
194
  result = self.connexion_get(method=Endpoint.WIFI_AP)
195
 
196
+ # Loop over the access points
197
+ for ap in result["result"]:
198
+ state = WifiState.get_by_value(ap["status"]["state"])
199
+ print(f'{ap["status"]["state"]}')
200
+ print(f"State: {state}")
201
 
202
+ if state == WifiState.ACTIVE:
203
+ if self.get_wifi_planning_state() == WifiPlanningState.TRUE:
204
+ return WifiState.ACTIVE_PLANIF
205
+ else:
206
+ return WifiState.ACTIVE
207
+ elif state in [WifiState.INACTIVE, WifiState.DISABLED]:
208
+ return WifiState.INACTIVE
209
 
210
  except Exception as e:
211
  log_exception(e)
 
244
 
245
  return False
246
 
247
+ def activate_wifi(self) -> bool:
248
  """
249
  Activate the WiFi.
250
  """
 
292
  # Activate the wifi if needed
293
  if wifi_state == WifiState.INACTIVE:
294
  log_info("WiFi is inactive, trying to activate...")
295
+ if singleton.activate_wifi():
296
  log_info("WiFi activated successfully.")
297
  else:
298
  log_error("Failed to activate WiFi.")