Repair depends in wifi service
This commit is contained in:
parent
6a4ad48577
commit
e1b027b301
2 changed files with 13 additions and 7 deletions
|
|
@ -286,7 +286,7 @@ def connect_to_wifi(request: WifiConnectRequest, translations: Translations = De
|
||||||
HTTPException: Если подключение не удалось (status_code=400).
|
HTTPException: Если подключение не удалось (status_code=400).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
wifi_service = WifiConnectionService()
|
wifi_service = WifiConnectionService(translations)
|
||||||
success, message = wifi_service.connect(request.ssid, request.password)
|
success, message = wifi_service.connect(request.ssid, request.password)
|
||||||
if not success:
|
if not success:
|
||||||
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
||||||
|
|
@ -313,7 +313,7 @@ def disconnect_from_wifi(request: WifiDisconnectRequest, translations: Translati
|
||||||
HTTPException: Если отключение не удалось (status_code=400).
|
HTTPException: Если отключение не удалось (status_code=400).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
wifi_service = WifiConnectionService()
|
wifi_service = WifiConnectionService(translations)
|
||||||
success, message = wifi_service.disconnect(request.ssid)
|
success, message = wifi_service.disconnect(request.ssid)
|
||||||
if not success:
|
if not success:
|
||||||
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
||||||
|
|
@ -341,7 +341,7 @@ def get_wifi_status(translations: Translations = Depends(get_translations())):
|
||||||
HTTPException: Если проверка статуса не удалась (status_code=400).
|
HTTPException: Если проверка статуса не удалась (status_code=400).
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
wifi_service = WifiConnectionService()
|
wifi_service = WifiConnectionService(translations)
|
||||||
success, message = wifi_service.get_status()
|
success, message = wifi_service.get_status()
|
||||||
if not success:
|
if not success:
|
||||||
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
raise HTTPException(status_code=400, detail=translations.gettext(message))
|
||||||
|
|
@ -349,4 +349,4 @@ def get_wifi_status(translations: Translations = Depends(get_translations())):
|
||||||
except HTTPException as e:
|
except HTTPException as e:
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=translations.gettext("Ошибка проверки статуса Wi-Fi: {error}").format(error=str(e)))
|
raise HTTPException(status_code=500, detail=translations.gettext("Ошибка проверки статуса Wi-Fi: {error}").format(error=str(e)))
|
||||||
|
|
|
||||||
|
|
@ -31,13 +31,19 @@ class WifiConnectionService:
|
||||||
Предоставляет методы для подключения, отключения и проверки статуса Wi-Fi соединений.
|
Предоставляет методы для подключения, отключения и проверки статуса Wi-Fi соединений.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, translations: Translations = Depends(get_translations())):
|
def __init__(self, translations: Optional[Translations] = None):
|
||||||
"""Инициализирует сервис Wi-Fi.
|
"""Инициализирует сервис Wi-Fi.
|
||||||
|
|
||||||
Автоматически определяет доступный Wi-Fi-интерфейс и сохраняет его имя.
|
Автоматически определяет доступный Wi-Fi-интерфейс и сохраняет его имя.
|
||||||
"""
|
"""
|
||||||
self.interface = self._get_wifi_interface()
|
self.interface = self._get_wifi_interface()
|
||||||
self.translations = translations
|
if translations is None:
|
||||||
|
try:
|
||||||
|
self.translations = Translations.load("locales", ["ru"], "messages")
|
||||||
|
except Exception:
|
||||||
|
self.translations = Translations()
|
||||||
|
else:
|
||||||
|
self.translations = translations
|
||||||
|
|
||||||
def _get_wifi_interface(self) -> str:
|
def _get_wifi_interface(self) -> str:
|
||||||
"""Автоматически определяет Wi-Fi-интерфейс.
|
"""Автоматически определяет Wi-Fi-интерфейс.
|
||||||
|
|
@ -177,4 +183,4 @@ class WifiConnectionService:
|
||||||
return False, self.translations.gettext("Не подключено к Wi-Fi")
|
return False, self.translations.gettext("Не подключено к Wi-Fi")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error checking status: {str(e)}")
|
logger.error(f"Error checking status: {str(e)}")
|
||||||
return False, self.translations.gettext("Ошибка проверки статуса: {error}").format(error=str(e))
|
return False, self.translations.gettext("Ошибка проверки статуса: {error}").format(error=str(e))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue